Skip to content

Instantly share code, notes, and snippets.

@GulgDev
Last active June 26, 2026 09:10
Show Gist options
  • Select an option

  • Save GulgDev/7b113b5e971682a6512d96c9c0fdf6da to your computer and use it in GitHub Desktop.

Select an option

Save GulgDev/7b113b5e971682a6512d96c9c0fdf6da to your computer and use it in GitHub Desktop.
33-byte JS signal implementation
// 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
const signal = F=>(f,G=F)=>F=f?_=>f(G?.()):F?.(); // 33 bytes
@souljorje

Copy link
Copy Markdown

Brilliant!

@pablohpsilva

pablohpsilva commented Jun 24, 2026

Copy link
Copy Markdown
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