Skip to content

Lint Component Lifecycle Events - #298

Closed
RobbieTheWagner wants to merge 10 commits into
emberjs:masterfrom
RobbieTheWagner:deprecate-component-lifecycle-events
Closed

RobbieTheWagner wants to merge 10 commits into
emberjs:masterfrom
RobbieTheWagner:deprecate-component-lifecycle-events

Conversation

@RobbieTheWagner

@RobbieTheWagner RobbieTheWagner commented Jan 19, 2018 •

Copy link
Copy Markdown
Member


After:
```js
didRender() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs super

@RobbieTheWagner RobbieTheWagner changed the title WIP - Deprecate Component Lifecycle Events Deprecate Component Lifecycle Events Jan 19, 2018
@locks locks added Needs Champion T-framework RFCs that impact the ember.js library labels Jan 19, 2018

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should change these to permalinks at a tag, so they won't be dead in the future!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! Updating now.

@cibernox

Copy link
Copy Markdown
Contributor

I'm all for removing those events. Specially thinking on the upcoming ES6 class syntax, defining a function and calling super will be much more streamlined with regular javascript.

@Gaurav0

Gaurav0 commented Jan 30, 2018

Copy link
Copy Markdown
Contributor

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

@Panman82

Copy link
Copy Markdown

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)

@rwjblue rwjblue self-assigned this Feb 2, 2018
@locks locks self-assigned this Feb 4, 2018
@rogatty

rogatty commented Feb 4, 2018

Copy link
Copy Markdown

What about the case where you need an observer to fire as part of the initialization process? Ember guides recommend to use on('init', observer(...)). Is there a way to achieve this effect without the lifecycle events?

@RobbieTheWagner

Copy link
Copy Markdown
Member Author

@rogatty can you not just put your observer code in a plain function and call that function inside init?

@chadhietala

chadhietala commented Feb 4, 2018 •

Copy link
Copy Markdown
Contributor

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.

@rogatty

rogatty commented Feb 4, 2018

Copy link
Copy Markdown

@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.

@josemarluedke

Copy link
Copy Markdown
Contributor

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.

@rwjblue

rwjblue commented Feb 4, 2018

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

  • willRender
  • willInsertElement
  • didInsertElement
  • didRender
  • didUpdateAttrs
  • didReceiveAttrs
  • willUpdate
  • willRender
  • didUpdate
  • didRender

@rwjblue

rwjblue commented Feb 4, 2018

Copy link
Copy Markdown
Member

@Gaurav0:

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

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 _supering. I think this is an anti-pattern. It makes reviewing/understanding what the mixin does much more complicated (because now any method could be didReceiveAttrs). Instead, mixins should be clear about their API's and what methods they expect to be called (either having the user invoke their custom named method from the components own hook method, or implementing the hook method and _supering).

@Gaurav0

Gaurav0 commented Feb 5, 2018

Copy link
Copy Markdown
Contributor

@rwjblue @locks Should we update APIs, Guides, Docs etc. to indicate that _super should always be called in each of these lifecycle hooks just as we do for init?

@RobbieTheWagner

Copy link
Copy Markdown
Member Author

@rwjblue @locks Should we update APIs, Guides, Docs etc. to indicate that _super should always be called in each of these lifecycle hooks just as we do for init?

@Gaurav0 I say yes.

@RobbieTheWagner

Copy link
Copy Markdown
Member Author

@rwjblue I added the list of events you provided 👍

@RobbieTheWagner

Copy link
Copy Markdown
Member Author

What else do we need here?

@rwjblue

rwjblue commented Apr 20, 2018

Copy link
Copy Markdown
Member

Soooo, when I brought this up at a recent Ember.js Core Team call there were a few folks that had concerns. I'd love to have them comment here so we can discuss the concerns together...

@wycats / @dgeb - Would y'all mind sharing the concerns you brought up?

@RobbieTheWagner

Copy link
Copy Markdown
Member Author

@rwjblue @wycats @dgeb I would love to have an open discussion about your concerns, if you wouldn't mind voicing them here please 😃

@dgeb

dgeb commented Jun 22, 2018

Copy link
Copy Markdown
Member

@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.

@RobbieTheWagner

Copy link
Copy Markdown
Member Author

@dgeb I'm in favor of announcing FCP and seeing if anyone comes out of the woodwork in objection to it.

@rwjblue what do you need from me here to help this along?

@ef4

ef4 commented Aug 13, 2018

Copy link
Copy Markdown
Contributor

@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.

@mike-north

Copy link
Copy Markdown
Contributor

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)

@tomdale

tomdale commented Aug 17, 2018

Copy link
Copy Markdown
Member

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.

@RobbieTheWagner

Copy link
Copy Markdown
Member Author

@tomdale Thanks for the update! How long do we wait on FCP before merging?

@RobbieTheWagner

Copy link
Copy Markdown
Member Author

Any updates on when we might want to merge this?

@machty

machty commented Oct 1, 2018 •

Copy link
Copy Markdown
Contributor

I had some confusions that I discussed with @rwwagner90; here are a few points of clarification:

  • on('init') is included as one of the lifecycle hooks to be deprecated for Components, even though it's a general Ember Object lifecycle hook
  • that said, we are not (for this RFC) deprecating .on('init') for regular (non-Component) Ember Objects
  • .on('click') and other non-lifecycle Component hooks (that still use the .on() API) will not be deprecated as part of this RFC

@tomdale

tomdale commented Oct 19, 2018

Copy link
Copy Markdown
Member

At the core team meeting today, @wycats raised some concerns about whether it's worth deprecating on('init') and making people refactor existing mixins, which impacts downstream consumers, rather than just asking people to move to non-mixin patterns. We have asked him to comment here with his thoughts, but since there are some open concerns, we are not ready to merge or close this RFC yet.

@RobbieTheWagner

Copy link
Copy Markdown
Member Author

@tomdale thanks for the update! If init is the only hook there is concern around, we could exclude init from this.

@tomdale

tomdale commented Dec 22, 2018

Copy link
Copy Markdown
Member

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.

@RobbieTheWagner

Copy link
Copy Markdown
Member Author

I discussed this with @tomdale and will be updating this RFC to suggest using lint to enforce this.

@RobbieTheWagner RobbieTheWagner changed the title Deprecate Component Lifecycle Events Lint Component Lifecycle Events Jan 11, 2019
@RobbieTheWagner

Copy link
Copy Markdown
Member Author

@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.

@RobbieTheWagner

Copy link
Copy Markdown
Member Author

Should we close this?

rwjblue commented Aug 16, 2019

Copy link
Copy Markdown
Member

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 Ember.Component calls then in some future time asking them to refactor them to @glimmer/component seems not great.

What do you think?

@RobbieTheWagner

Copy link
Copy Markdown
Member Author

@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?

@locks

locks commented Aug 16, 2019

Copy link
Copy Markdown
Contributor

@rwwagner90 as the author you are free to withdrawn the proposal at any time 😁

@RobbieTheWagner
RobbieTheWagner deleted the deprecate-component-lifecycle-events branch August 16, 2019 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-deprecation T-framework RFCs that impact the ember.js library

Projects

None yet

Development

Successfully merging this pull request may close these issues.