Skip to content

Commit

Permalink
removed providing reversed arguments to observer
Browse files Browse the repository at this point in the history
  • Loading branch information
bekzod committed Nov 30, 2017
1 parent c27cd04 commit e383e1d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 32 deletions.
24 changes: 5 additions & 19 deletions packages/ember-metal/lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,17 +757,8 @@ export function aliasMethod(methodName) {
@static
*/
export function observer(...args) {
let _paths, func;
if (typeof args[args.length - 1] !== 'function') {
// revert to old, soft-deprecated argument ordering
deprecate('Passing the dependentKeys after the callback function in observer is deprecated. Ensure the callback function is the last argument.', false, { id: 'ember-metal.observer-argument-order', until: '3.0.0' });

func = args.shift();
_paths = args;
} else {
func = args.pop();
_paths = args;
}
let func = args.pop();
let _paths = args;

assert('observer called without a function', typeof func === 'function');
assert('observer called without valid path', _paths.length > 0 && _paths.every((p)=> typeof p === 'string' && p.length));
Expand Down Expand Up @@ -841,19 +832,14 @@ export function _immediateObserver() {
@private
*/
export function _beforeObserver(...args) {
let func = args[args.length - 1];

let _paths = args.slice(0, -1);
if (typeof func !== 'function') {
// revert to old, soft-deprecated argument ordering
func = args[0];
_paths = args.slice(1);
}
let func = args.pop();
let _paths = args;

assert('_beforeObserver called without a function', typeof func === 'function');

let paths = [];
let addWatchedProperty = path => { paths.push(path); };

for (let i = 0; i < _paths.length; ++i) {
expandProperties(_paths[i], addWatchedProperty);
}
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 overridden 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 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')
});
});
2 changes: 0 additions & 2 deletions packages/ember-metal/tests/observer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ testBoth('observer should assert to invalid input', function(get, set) {
observer(()=>{});
}, 'observer called without valid path');

expectDeprecation('Passing the dependentKeys after the callback function in observer is deprecated. Ensure the callback function is the last argument.');

expectAssertion(()=> {
observer(null);
}, 'observer called without a function');
Expand Down

0 comments on commit e383e1d

Please sign in to comment.