You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After researching this topic, it seems that using the 'new' keyword can cause false positives with instanceof and encourage other incorrect practices. Because mini-signals is not actively used in the wild, maybe it would better to switch to a factory implementation (as mentioned by @Hypercubed in #1).
I've gone back and forth on this a few times (not just for mini-signals) but here are my current thoughts.
As I pointed out in my apologetic comments here, developers are used to the new keyword. They will use it even if they don't have to. Like the semicolon, it's usually safe to put it in, often unsafe to leave out.
One thing I like about signals is that they are, by design, made for composition. Objects contain signals. These higher-order objects can may be classes, or factories, or stamps. This is an implied "has a" relationship. Most the arguments the ES6 class boil down to issues with inheritance. Inheritance is an "is a" relationship. I can't really see a need to inherit from a signal either through classical inheritance nor prototypical (remember classes in JS are just sugar for prototypes). Can we come up with a specific use case where a signal is inherited? How would a factory be better in that case?
Related, since signals are rarely inherited how can instanceof ever lie? instanceof is useful if it can be relied upon. What is the alternative to instanceof for a Signal or a SignalBinding?
The ES6 class syntax is compact and clean. I may actually prefer the Constructor, Constructor.prototype = syntax but that is no different (behavior wise) from an ES6 class.
It is a breaking change, would mean a bump to v2.0.0. Not a good reason to not do it, but perhaps a reason to delay.
After researching this topic, it seems that using the 'new' keyword can cause false positives with
instanceof
and encourage other incorrect practices. Because mini-signals is not actively used in the wild, maybe it would better to switch to a factory implementation (as mentioned by @Hypercubed in #1).Proposals for DSL:
The text was updated successfully, but these errors were encountered: