-
Notifications
You must be signed in to change notification settings - Fork 130
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
lifecycle events #19
Comments
They'll work in a similar way: var Thing = component({
afterMount() {},
beforeMount() {},
beforeUpdate() {},
afterUpdate() {},
shouldUpdate() {}
}); But they'll also be exposed as events, so instead of using a Thing.use(myPlugin); That might do something like: function myPlugin(Component) {
// Do something on mount without needing to mixin and patch functions
Component.on('mount', function(instance, el, state, props){
});
// Or just add new methods to the prototype to make it available
// to the instance
Component.prototype.doSomething = function(){}
} The big difference is that Components in Deku are just simple constructor functions. So you can extend them, listen to events, and even create instances without needing Deku or stubbing the require functions. |
👏👏👏👏👏👏👏👏👏👏👏👏 I approve of this so much. |
I was wondering if something like this would also be possible: var thing = component()
module.exports = thing;
thing.on('render', function(dom, state, props) {
return dom('button', null, ['click me']);
})
thing.on('mount', function(instance, el, state, props) {
// do other stuff
}) If any form of child element is rendered you could pass it the |
As mentioned in the roadmap (#3), what would the syntax for lifecycle events look like? Is it the goal to achieve event parity with React?
The text was updated successfully, but these errors were encountered: