-
Notifications
You must be signed in to change notification settings - Fork 75
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
added postInitialize #176
added postInitialize #176
Conversation
I'm still trying to work out what's going on here, but it looks like this PR also includes the changes from #175, so we'll want to wait for a decision on that before we merge this, or redo this PR without those changes. |
Yes, sorry, I continued working from my previous branch... Shall I revert this into 2 different PR's? Waiting for a decision on the first PR is also fine for me. |
Hi @latentflip, If you need more information, I'd love to talk about it. This is my first real contribution... So I'm just getting acquainted using Pull Request on Github. |
I think you should create a new branch and add just the changes relevant for |
Hi @latentflip and @pgilad. I created a new branch to be able to replace the previous commits. I also updated the readme-file so it is more clear why I would like to have this functionality added to ampersand. Feel free to ask more information. Thanks |
Hey I'd actually like to raise the debate on whether view lifecycles should be done via callback functions or events. Events are great in the form that any module can subscribe/unsubscribe to/from them. Also they don't force you to use a specific function that is coupled to the view instance. For example you can assign a helper function to handle the lifecycle event (say analytics tracking). Most if not all IMO events are preferable. Consider these 2 examples: var UsingFunctions = State.extend({
initialize() {
console.log('init');
},
postInitialize() {
console.log('realized');
}
});
var UsingEvents = State.extend({
initialize() {
console.log('init');
this.listenTo(this, 'post:initialize', this.postInitialize);
},
postInitialize() {
console.log('realized');
}
}); In the first example using functions - it seems like the In the 2nd example using events - it requires an extra step, but it's far more explicit. I know why the I vote for using events as lifecycle hooks. |
Actually I did some testing, and the problem with events, at least with the current implementation of So either we create an alternative trigger method (i.e |
Thanks for your research and testing. You're right that using events is a more explicit way, but the bubbling-problem you describe indeed makes this impossible. |
Now you can use a "postInitialize"-function which will be triggered just AFTER all "initialize"-functions from parent -states and -collections have been triggerd.
This is necessary when you need to access some (non-binding) properties from a parent-State-object which needs to be altered first in it's own initialize function.