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

Commit

Permalink
Merge pull request #2384 from Kuzirashi/master
Browse files Browse the repository at this point in the history
Add info about deprecated function as second argument in deprecate/warn/assert
  • Loading branch information
rwjblue committed Oct 5, 2015
2 parents 79a5d9f + 44f4f06 commit 02826d6
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions source/deprecations/v2.x.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,64 @@ In Ember 2.1 the internal `.currentState` property has been moved to `_currentSt

Please keep in mind that `.currentState` / `._currentState` is still private and should not be used/relied upon
outside of Ember internals.

### Deprecations Added in 2.2

#### Function as test in Ember.deprecate, Ember.warn, Ember.assert

##### Deprecated behavior

Calling `Ember.deprecate`, `Ember.warn` or `Ember.assert` with a function as test argument is deprecated.

You can no longer pass arguments of type `function` to these methods. Following calls will trigger deprecations:

```javascript
const message = 'Test message.';
const options = { id: 'test', until: '3.0.0' };

// passing function
Ember.deprecate(message, function() {
return true;
}, options);

const myConstructor = {}.constructor;

// passing constructor (also a function)
Ember.warn(message, myConstructor, options);

// passing function with double arrow syntax
Ember.assert(message, () => true, options);
```

[Demo.](http://ember-twiddle.com/34d36b9121e017d2388f)

##### Refactoring

You have 3 options to refactor second argument from `function` to `boolean`:

1. Use [IIFE](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression).
2. Use `!!Constructor` for constructors.
3. Pass `boolean` directly instead of wrapping it in function.

Example:

``` javascript
// ... message, options ommited for brevity

// passing IIFE (1)
Ember.deprecate(message, (function() {
return true;
})(), options);

const myConstructor = {}.constructor;

// passing !!constructor (2)
Ember.warn(message, !!myConstructor, options);

// passing boolean directly (3)
Ember.assert(message, true, options);
```

[Demo.](http://ember-twiddle.com/ed90d0c7812914f09a3f)

In a future version functions will be treated as truthy values instead of being executed.

0 comments on commit 02826d6

Please sign in to comment.