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

Add info about deprecated function as second argument in deprecate/warn/assert #2384

Merged
merged 1 commit into from
Oct 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.