Last active
June 26, 2026 09:10
-
-
Save GulgDev/7b113b5e971682a6512d96c9c0fdf6da to your computer and use it in GitHub Desktop.
33-byte JS signal implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Usage | |
| const foo = signal(); | |
| // subscribe (callback must return a nullish value) | |
| foo(() => console.log("subscriber #1")); | |
| foo(() => console.log("subscriber #2")); | |
| // fire and reset | |
| foo(); // subscriber #1, subscriber #2 | |
| foo(); // nothing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const signal = F=>(f,G=F)=>F=f?_=>f(G?.()):F?.(); // 33 bytes |
const signal = F=>(f,G=F)=>F=typeof f === 'function'?_=>f(G?.()):F?.();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Brilliant!