Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] Deprecate reverse argument ordering in Ember.observer #11778

Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/ember-metal/lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ export function observer(...args) {

if (typeof func !== 'function') {
// revert to old, soft-deprecated argument ordering
Ember.deprecate('Passing the dependentKeys after the callback function in Ember.observer is deprecated. Ensure the callback function is the last argument.');

func = args[0];
_paths = args.slice(1);
Expand Down
12 changes: 11 additions & 1 deletion packages/ember-metal/tests/mixin/observer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ testBoth('global observer helper takes multiple params', function(get, set) {
equal(get(obj, 'count'), 2, 'should invoke observer after change');
});


testBoth('replacing observer should remove old observer', function(get, set) {
var MyMixin = Mixin.create({

Expand Down Expand Up @@ -210,3 +209,14 @@ testBoth('observing chain with overriden property', function(get, set) {
set(obj3, 'baz', 'BEAR');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});

testBoth('providing the arguments in reverse order is deprecated', function(get, set) {
expectDeprecation(/Passing the dependentKeys after the callback function in Ember\.observer is deprecated. Ensure the callback function is the last argument/);

Mixin.create({
count: 0,
foo: observer(function() {
set(this, 'count', get(this, 'count') + 1);
}, 'bar.baz')
});
});