News for hackers. Stuff that matters.
Re:A proposal to add signals to JavaScript by ivan_gammel on Sunday March 31, 2024 @03:01PM (#39887038)
Did you read the document? They have an example there, which is quite similar to yours, and explain what is the problem.
Re:A proposal to add signals to JavaScript by explaininjs on Sunday March 31, 2024 @03:05PM (#39887060)
No, they don't. In fact, if you search "event" in the proposal you get exactly one result, the prefix of "eventually". This is a serious shortcoming of the proposal that should be addressed.
Re:A proposal to add signals to JavaScript by throwitaway1123 on Sunday March 31, 2024 @03:11PM (#39887118)
I think the comment you're replying to is referring to the pub/sub sections of the proposal. They don't explicitly mention events, but events are a subset of the publish/subscribe pattern.
Re:A proposal to add signals to JavaScript by explaininjs on Sunday March 31, 2024 @03:14PM (#39887138)
But then so are signals.

The only "benefit" signals as proposed here give you is less control over the exact dispatch pattern of the graph, for instance things like debouncing, throttling, batching, etc etc etc. Aka all the things you absolutely must have control over if you want to make something resembling a high performance application.

Re:A proposal to add signals to JavaScript by naasking on Sunday March 31, 2024 @03:25PM (#39887250)
Signals are not a subset of events. Signals combine event subscription with value construction, which promotes a remote declarative model for updates.

> The only "benefit" signals as proposed here give you is less control over the exact dispatch pattern of the graph, for instance things like debouncing, throttling, batching,

Events don't give you any more control over those properties than signals, they just require more boilerplate.

Re:A proposal to add signals to JavaScript by ivan_gammel on Sunday March 31, 2024 @03:12PM (#39887124)
Oh, come on. They do have an example of architecture, not literal example of events. It doesn’t matter what trivial implementation of Observer pattern you choose.
Re:A proposal to add signals to JavaScript by explaininjs on Sunday March 31, 2024 @03:15PM (#39887153)
Except one is already built into the language? And it provides all the upsides of signals with none of the downsides? (Modulo proper use of `using` directives)
Re:A proposal to add signals to JavaScript by ahmedfromtunis on Sunday March 31, 2024 @03:10PM (#39887109)
Can you please point to where in the document such an example was mentioned? I rechecked the document and couldn't find it.
Re:A proposal to add signals to JavaScript by ivan_gammel on Sunday March 31, 2024 @03:17PM (#39887168)
Just look for the example of a design pattern („Example - A VanillaJS Counter“ section), not for a literal implementation of it via events. Conceptually they are the same.