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

Commit

Permalink
Add deprecation guide for ember-views.lifecycle-hook-arguments #2761
Browse files Browse the repository at this point in the history
  • Loading branch information
jenweber authored and locks committed Jan 6, 2017
1 parent d8cb5b4 commit 57d8b5d
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions source/deprecations/v2.x.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -858,3 +858,105 @@ Index Content
For more informations of how to use `ember-elsewhere`, please visit the official
documentation [here](https://github.com/ef4/ember-elsewhere#ember-elsewhere).
### Deprecations Added in 2.12
#### `Ember.K`
##### until: 3.0.0
##### id: ember-metal.ember-k
Using `Ember.K` is deprecated in favor of defining a function inline. See [RFC 0178](https://github.com/emberjs/rfcs/blob/master/text/0178-deprecate-ember-k.md).
You can use the addon [ember-watson](https://github.com/abuiles/ember-watson#remove-usages-of-emberk) to automate the removal of `Ember.K` from your application.
Example object:
```js
Ember.Object.extend({
someFun: Ember.K
});
```
Command:
```sh
ember watson:remove-ember-k --empty
```
The result will be:
```js
Ember.Object.extend({
someFun() {}
});
```
If for some reason your app depends on the ability to chain `Ember.K` invocations, you can use the flag `--return-this`. It will replace `Ember.K` with a function that returns `this`.
### Deprecations Added in Pending Features
#### Arguments in Component Lifecycle Hooks
##### until: 2.13.0
##### id: ember-views.lifecycle-hook-arguments
Previously, it was possible for component lifecycle hooks `didInitAttrs`, `didReceiveAttrs`, and `didUpdateAttrs` to receive arguments. However, this functionality was part of private API. Using the arguments is harmful to component performance, so they will trigger a deprecation. Alternative approaches for all three hooks are below:
##### `didInitAttrs` arguments
Since this lifecycle hook is [already deprecated](http://emberjs.com/deprecations/v2.x/#toc_ember-component-didinitattrs), we suggest taking this chance to address two deprecations at the same time.
Imagine you have a component that stores a timestamp when it is initialized.
Before:
``` javascript
Ember.Component.extend({
didInitAttrs({ attrs }) {
this.set('initialTimestamp', attrs.timestamp);
}
});
```
After:
``` javascript
Ember.Component.extend({
init() {
this._super(...arguments);

this.set('initialTimestamp', this.get('timestamp'));
}
});
```
##### `didReceiveAttrs` and `didUpdateAttrs` arguments
This example for `didReceiveAttrs` below also applies to `didUpdateAttrs`, a similar hook that only runs on re-renders. Let's say you want to animate a thermometer widget showing the change between today's high and low temperatures.
Before:
``` javascript
Ember.Component.extend({
didReceiveAttrs({ oldAttrs, newAttrs }) {
if (oldAttrs.temp !== newAttrs.temp) {
this.thermometer.move({ from: oldAttrs.temp, to: newAttrs.temp });
}
}
});
```
After:
``` javascript
Ember.Component.extend({
didReceiveAttrs() {
let highTemp = this.get('_highTemp');
let lowTemp = this.get('_lowTemp');

if (highTemp !== lowTemp) {
this.thermometer.move({ from: highTemp, to: lowTemp });
}
}
});
```

0 comments on commit 57d8b5d

Please sign in to comment.