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

[CLEANUP beta] Remove support for reversed args in Ember.Observer #11782

Merged
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
26 changes: 7 additions & 19 deletions packages/ember-metal/lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,32 +800,20 @@ export function aliasMethod(methodName) {
@return func
@private
*/
export function observer(...args) {
var func = args.slice(-1)[0];
var paths;

var addWatchedProperty = function(path) { paths.push(path); };
var _paths = args.slice(0, -1);

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.');
export function observer(...paths) {
var func = paths.pop();
var expandedPaths = [];
var addWatchedProperty = function(path) { expandedPaths.push(path); };

func = args[0];
_paths = args.slice(1);
}

paths = [];

for (var i = 0; i < _paths.length; ++i) {
expandProperties(_paths[i], addWatchedProperty);
for (var i = 0; i < paths.length; ++i) {
expandProperties(paths[i], addWatchedProperty);
}

if (typeof func !== 'function') {
throw new Ember.Error('Ember.observer called without a function');
}

func.__ember_observes__ = paths;
func.__ember_observes__ = expandedPaths;
return func;
}

Expand Down
11 changes: 0 additions & 11 deletions packages/ember-metal/tests/mixin/observer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,3 @@ 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')
});
});