-
-
Notifications
You must be signed in to change notification settings - Fork 298
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
Implement new Generator.extend inheritance method #446
Conversation
}; | ||
|
||
/** | ||
* Extend this Class to create a new one inherithing this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use or wrap util.inherits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the end user, the advantage is mostly the syntax sugar.
Internally, util.inherits
simply call object.create
and assign a _super
method to the constructor. It is a very light wrapper, and I prefer defining our own __super__
reference as I found this way more useful. Also, here we can declare both instances and static method which is an advantage over relying simply on the node.js inheritance helper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the bikeshedding. I just don't want us to bloat it with unnecessary code if not needed. It would still be possible to add static properties with util.inherits, right? I guess I don't see the convenience.
Isn't there already a module on npm that does this? It feels very generic. If not, could you do it as a separate module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
util.inherits
really just a small wrapper over assigning a prototype inheritance via object.create
https://github.com/joyent/node/blob/master/lib/util.js#L558-L581 - so there's no static built-in.
There's one similar node module out there that I know of (though it does way more) -> https://github.com/dfilatov/inherit
But this is really core to the way yeoman generators are extended, I really feel this should belong close to them (with direct unit tests) for more stability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is really core to the way yeoman generators are extended, I really feel this should belong close to them (with direct unit tests) for more stability.
Yes, but this is Node, and things should be modular if possible. The generator core is way too big for what it does and we should try to separate out more of it.
When you need to add static methods, can't you just use normal _.extend() for that?
There, I extracted this functionality in its own node module. I removed some unit tests, but I kept the main feature's ones as it is quite important to ensure inheritance works well when we send out releases. |
Implement new Generator.extend inheritance method
Awesome! Thanks @SBoudrias :) |
hahaha no problem |
I'll add some missing test, but this is my WIP.