Repository navigation
Lint Component Lifecycle Events - #298
RobbieTheWagner wants to merge 10 commits into
Conversation
|
|
||
| After: | ||
| ```js | ||
| didRender() { |
|
|
||
| Ember does not appear to rely on these events internally, however there are at least a couple of mentions of | ||
| these events in the comments, referring specifically to `on('didInsertElement')` | ||
| [here](https://github.com/emberjs/ember.js/blob/master/packages/ember-metal/lib/run_loop.js#L140) |
There was a problem hiding this comment.
should change these to permalinks at a tag, so they won't be dead in the future!
There was a problem hiding this comment.
Good call! Updating now.
|
I'm all for removing those events. Specially thinking on the upcoming ES6 class syntax, defining a function and calling |
|
The main use I have for lifecycle events is in mixins, where I don't want to override a method the user may want to override without calling _super |
An addon example of that is: alexspeller/ember-cli-active-link-wrapper#10 (comment) |
|
What about the case where you need an observer to fire as part of the initialization process? Ember guides recommend to use |
|
@rogatty can you not just put your observer code in a plain function and call that function inside |
|
I'm +1 for this because it will finally remove the this long standing issue where basically have to call hooks 2 times. In our apps we already leverage ESLint rules via eslint-plugin-ember-best-practices that already check for the presence of evented APIs. This also aligns with the goal of Ember 3.0 by removing APIs that are not obvious and we have to teach. |
|
@rwwagner90 I believe there were some issues with that approach ~3 years ago. After your suggestion, I tried to reproduce them in Ember Twiddle and found nothing. Thanks, we can now get rid of this dinosaur from our old code. |
|
I give this a huge "+1". In our app we have been avoiding this for a long time already. It also removes a confusion for people learning ember, since there is two ways of doing the same thing. |
|
I am also in favor of moving forward on this, these event based hooks are a pretty significant trap... |
|
|
||
| ## Detailed design | ||
|
|
||
| Ember will start logging deprecation messages that state which event you used and which |
There was a problem hiding this comment.
AFAICT the RFC only gives examples of the events we are talking about, but the detailed design section should also include an explicit list of events.
I believe this is the current list of events that are component specific (from the curly component manager):
willRenderwillInsertElementdidInsertElementdidRenderdidUpdateAttrsdidReceiveAttrswillUpdatewillRenderdidUpdatedidRender
I agree that this is the most common use case for these hooks, but I also think that it is one of the main reasons to move forward with this RFC. Often this is done by mixin authors defensively as a way to protect against component authors not properly |
|
@rwjblue I added the list of events you provided 👍 |
|
What else do we need here? |
|
@rwwagner90 @rwjblue I apologize for taking so long to comment on this. I'm actually in favor of moving forward with this RFC, but cautiously. Eliminating these lifecycle events and forcing usage of lifecycle methods will of course eliminate the ability of outside listeners to respond directly to these events. My concern was in verifying that tooling may currently rely on wiring up these listeners for potentially legit purposes such as auditing component lifecycle events throughout an application. Maybe this is the kind of use case we want to support in non-production builds or maybe it's not worthwhile even then. I don't consider this concern to be a major blocker. It may be entirely imagined and no such usages exist in the wild. It just seems worthwhile to do a code search in emberobserver (although that search might be quite noisy). Perhaps it would be sufficient to announce FCP (Final Comment Period) and see if this raises alarms for anyone. |
|
@rwwagner90 I'm putting this on the agenda for the next core meeting. I think FCP is appropriate because that the forcing function to get people out of the woodwork if they really have concerns. |
|
This is a great initiative. One thing that might be tricky to codemod/detect (since connections are defined in hbs) is parent/child components interacting with eahother via these events. It would be helpful for the deprecation guide to provide some nudging toward more sustainable patterns for these kinds of things (i.e. observer-free pattern for: child invokes ember-concurrency task in response to parent attrs changing) |
|
We discussed this at the core team meeting today and agree that this RFC is ready for Final Comment Period. We had a few folks out this week, so we don't have consensus to merge this, but we do think it's appropriate to FCP and give folks a chance to raise any remaining issues before we discuss further. |
|
@tomdale Thanks for the update! How long do we wait on FCP before merging? |
|
Any updates on when we might want to merge this? |
|
I had some confusions that I discussed with @rwwagner90; here are a few points of clarification:
|
|
At the core team meeting today, @wycats raised some concerns about whether it's worth deprecating |
|
@tomdale thanks for the update! If |
|
We discussed this again at the core team meeting. We agree that people should move away from this but we also are leery of a full-blown deprecation creating additional churn, when the real end-game is that people eventually refactor away from mixins and ideally towards Glimmer components. We discussed that perhaps this should be a lint rather than a full-blown deprecation, as a way to nudge people towards the right path, but without the heavy-handedness of a deprecation warning. |
|
I discussed this with @tomdale and will be updating this RFC to suggest using lint to enforce this. |
|
@tomdale I adjusted some things to use lint, but there is already a lint rule for this stuff, so do we even want to do anything? I suppose we could have more specific rules, but let me know what we should do here. |
|
Should we close this? |
|
Hmm. Perhaps? I still agree with the overall goal here, but I suspect that doing a change now is probably a bit of a disservice to folks. Making them do extra work to update their What do you think? |
|
@rwjblue I think there is nothing to do anyway, since these lint rules already exist. Are we able to just close or is there a process? |
|
@rwwagner90 as the author you are free to withdrawn the proposal at any time 😁 |
Rendered