Skip to content
This repository has been archived by the owner on Mar 22, 2019. It is now read-only.

First draft of component hook argument deprecation guide #2765

Closed
wants to merge 0 commits into from
Closed

First draft of component hook argument deprecation guide #2765

wants to merge 0 commits into from

Conversation

jenweber
Copy link
Contributor

@locks here is the PR to address #2761

I mostly used your examples from the RFC. I changed the "map" example to "thermometer" because when I read map, my mind jumps to enumerating through arrays. I don't think about navigational maps. I simplified what happens inside the component hooks. I see why there were more lines in terms of a real-world example but I think keeping it as simple as possible may help the reader to hone in on what's different between the before and after.

I am also wondering what the best heading level is for each hook. They don't stand out well but they also should not be as prominent as the label.

What's the official deprecation name? I made one up.

Thanks for walking me through the process!

@locks
Copy link
Contributor

locks commented Dec 31, 2016

What's the official deprecation name? I made one up.

You can see that Godfrey used ember-views.lifecycle-hook-arguments in https://github.com/emberjs/ember.js/pull/14711/files#diff-7536fca9f7b528326424427194fd9ac2R514, so you got that right :)

Copy link
Contributor

@locks locks left a comment

Choose a reason for hiding this comment

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

Great first draft, some comments that need addressing. On a macro level, I was thinking if maybe we should shift the organization a bit. The difference between didReceiveAttrs and didUpdateAttrs is when they run, so maybe we can coalesce them into the same header? What's important, IMO, is to address the use cases people used the arguments for, as seen in the discussion for emberjs/rfcs#191.

##### until: 2.13.0
##### id: ember-views.lifecycle-hook-arguments

It is possible for component lifecycle hooks `didInitAttrs`, `didReceiveAttrs`, and `didUpdateAttrs` to receive arguments, but this functionality is part of private API, which is subject to change without notice. Those arguments will be removed because their use is harmful to component performance. However, since the arguments were accessible and some apps may be unknowingly depending on private API, this change will follow the formal deprecation process. Alternative approaches for all three hooks are below:
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this documentation will be post-deprecation, I think we should slightly re-word this. Something in the spirit of http://emberjs.com/deprecations/v2.x/#toc_initializer-arity, maybe.


``` javascript
Ember.Component.extend({
didReceiveAttrs({ highTemp, lowTemp }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can't change this, or the destructuring won't work. didReceiveAttrs receives an object with oldAttrs and newAttrs attributes, so:

didReceiveAttrs({ oldAttrs, newAttrs }) {
}

Is equivalent to:

didReceiveAttrs(attrObj) {
  let oldAttrs = attrObj.oldAttrs;
  let newAttrs = attrObj.newAttrs;
}

Did you mean to destructure oldAttrs/newAttrs themselves, like didReceiveAttrs({ newAttrs: { lowTemp, highTemp }}) {?

}
});
```
After:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add an empty line above "After:"?

@locks
Copy link
Contributor

locks commented Jan 3, 2017

@jenweber let me know if you need help resolving the deprecation

@jenweber
Copy link
Contributor Author

jenweber commented Jan 4, 2017

Thanks @locks. Just got back from the holidays and will update the PR tonight.

@jenweber
Copy link
Contributor Author

jenweber commented Jan 5, 2017

@locks let me know if anything else should be changed, or if I should resolve the conflicts too. Thanks!

Copy link
Contributor

@locks locks left a comment

Choose a reason for hiding this comment

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

Sorry for only noticing this now, can you move this text to the ember deprecations file? It's in the ember-data file.
After that we can merge this!

@jenweber
Copy link
Contributor Author

jenweber commented Jan 6, 2017

@locks I think it's in the right place now. But I'm a bit confused by the "files changed" and "commits" associated with the PR (particularly some deletions that I didn't make and don't show up elsewhere), so please look them over and let me know if that looks normal. I haven't really worked on forks of actively developed projects.

@locks locks closed this Jan 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants