r/javascript • u/GulgPlayer • Jun 21 '26
33-byte JS signal implementation
https://gist.github.com/GulgDev/7b113b5e971682a6512d96c9c0fdf6daRecently I've developed a code-golfed signal implementation with the following features/constraints:
- subscribes functions returning nullish values.
- fires all pending subscribers and resets.
- requires no arguments to be passed to the factory and either null/undefined or a function to the signal. (as noted by u/azhder)
As it turns out, you can go as short as 33 bytes using function compositon, nullish coalescing and default parameters:
F=>(f,G=F)=>F=f?_=>f(G?.()):F?.()
102
Upvotes
View all comments
Show parent comment
2
u/azhder Jun 22 '26
Did you ask an LLM to unwrap it for you? Because I did. After the first response I got, something in the lines of: it is chaining closures. It left me scratching my head for a bit, but once I saw it expanded, like in your code, I was "yup, right, there it is".