Skip to content

Commit

Permalink
Remove "pending flush" concept from chains
Browse files Browse the repository at this point in the history
  • Loading branch information
mmun committed Feb 8, 2016
1 parent d47271c commit 59fa972
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 59 deletions.
23 changes: 0 additions & 23 deletions packages/ember-metal/lib/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,6 @@ ChainWatchers.prototype = {
}
};

var pendingQueue = [];

// attempts to add the pendingQueue chains again. If some of them end up
// back in the queue and reschedule is true, schedules a timeout to try
// again.
export function flushPendingChains() {
if (pendingQueue.length === 0) {
return;
}

var queue = pendingQueue;
pendingQueue = [];

queue.forEach((q) => q[0].add(q[1]));

warn(
'Watching an undefined global, Ember expects watched globals to be ' +
'setup by the time the run loop is flushed, check for typos',
pendingQueue.length === 0,
{ id: 'ember-metal.chains-flush-pending-chains' }
);
}

function makeChainWatcher(obj) {
return new ChainWatchers(obj);
}
Expand Down
2 changes: 0 additions & 2 deletions packages/ember-metal/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ import {
import {
ChainNode,
finishChains,
flushPendingChains,
removeChainWatcher
} from 'ember-metal/chains';
import {
Expand Down Expand Up @@ -263,7 +262,6 @@ Ember.setProperties = setProperties;
Ember.watchKey = watchKey;
Ember.unwatchKey = unwatchKey;

Ember.flushPendingChains = flushPendingChains;
Ember.removeChainWatcher = removeChainWatcher;
Ember._ChainNode = ChainNode;
Ember.finishChains = finishChains;
Expand Down
5 changes: 1 addition & 4 deletions packages/ember-metal/lib/watching.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/

import {
removeChainWatcher,
flushPendingChains
removeChainWatcher
} from 'ember-metal/chains';
import {
watchKey,
Expand Down Expand Up @@ -58,8 +57,6 @@ export function watcherCount(obj, key) {
return (meta && meta.peekWatching(key)) || 0;
}

watch.flushPending = flushPendingChains;

export function unwatch(obj, _keyPath, m) {
// can't watch length on Array - it is special...
if (_keyPath === 'length' && Array.isArray(obj)) { return; }
Expand Down
31 changes: 1 addition & 30 deletions packages/ember-metal/tests/watching/watch_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

var willCount, didCount,
willKeys, didKeys,
originalLookup, lookup, Global;
originalLookup, lookup;

QUnit.module('watch', {
setup() {
Expand Down Expand Up @@ -170,35 +170,6 @@ testBoth('watching an object value then unwatching should restore old value', fu
equal(get(get(get(foo, 'bar'), 'baz'), 'biff'), 'BIFF', 'biff should exist');
});

testBoth('watching a global object that does not yet exist should queue', function(get, set) {
lookup['Global'] = Global = null;

var obj = {};
addListeners(obj, 'Global.foo');

watch(obj, 'Global.foo'); // only works on global chained props

equal(willCount, 0, 'should not have fired yet');
equal(didCount, 0, 'should not have fired yet');

lookup['Global'] = Global = { foo: 'bar' };
addListeners(Global, 'foo');

watch.flushPending(); // this will also be invoked automatically on ready

equal(willCount, 0, 'should not have fired yet');
equal(didCount, 0, 'should not have fired yet');

set(Global, 'foo', 'baz');

// should fire twice because this is a chained property (once on key, once
// on path)
equal(willCount, 2, 'should be watching');
equal(didCount, 2, 'should be watching');

lookup['Global'] = Global = null; // reset
});

QUnit.test('when watching another object, destroy should remove chain watchers from the other object', function() {
var objA = {};
var objB = { foo: 'bar' };
Expand Down

0 comments on commit 59fa972

Please sign in to comment.