Skip to content

Instantly share code, notes, and snippets.

@GulgDev
Last active June 29, 2026 10:51
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?.(); 

@RobertAKARobin

Copy link
Copy Markdown

It's impressive that it's so concise, but you might consider rewriting it with readable variable names and comments so people can better understand the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment