Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory implementation #3

Closed
divmgl opened this issue Oct 5, 2015 · 3 comments
Closed

Factory implementation #3

divmgl opened this issue Oct 5, 2015 · 3 comments

Comments

@divmgl
Copy link

divmgl commented Oct 5, 2015

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:

var miniSignal = require('mini-signals');
var signal = miniSignal();
var miniSignals = require('mini-signals');
var signal = miniSignals.create();
@Hypercubed
Copy link
Owner

Ahhh... Welcome to the esoteric side of JavaScript.

I've gone back and forth on this a few times (not just for mini-signals) but here are my current thoughts.

  1. 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.
  2. 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?
  3. 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?
  4. 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.
  5. 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.

@Hypercubed Hypercubed added this to the v2.0.0 milestone Oct 6, 2015
@Hypercubed
Copy link
Owner

Not for now... maybe later. Closing.

@divmgl
Copy link
Author

divmgl commented Jun 21, 2017

@Hypercubed hello, just wanted to say that this package is fantastic. thanks for all the hard work on this

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

No branches or pull requests

2 participants