From 59fa9721c2278d2d23d4d4417b00ff726e60167d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mu=C3=B1oz?= Date: Mon, 8 Feb 2016 03:27:35 -0500 Subject: [PATCH] Remove "pending flush" concept from chains --- packages/ember-metal/lib/chains.js | 23 -------------- packages/ember-metal/lib/index.js | 2 -- packages/ember-metal/lib/watching.js | 5 +-- .../ember-metal/tests/watching/watch_test.js | 31 +------------------ 4 files changed, 2 insertions(+), 59 deletions(-) diff --git a/packages/ember-metal/lib/chains.js b/packages/ember-metal/lib/chains.js index c438578e448..395e63b4424 100644 --- a/packages/ember-metal/lib/chains.js +++ b/packages/ember-metal/lib/chains.js @@ -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); } diff --git a/packages/ember-metal/lib/index.js b/packages/ember-metal/lib/index.js index fd79788a41d..00ac4b4cf3d 100644 --- a/packages/ember-metal/lib/index.js +++ b/packages/ember-metal/lib/index.js @@ -90,7 +90,6 @@ import { import { ChainNode, finishChains, - flushPendingChains, removeChainWatcher } from 'ember-metal/chains'; import { @@ -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; diff --git a/packages/ember-metal/lib/watching.js b/packages/ember-metal/lib/watching.js index 2d0cc45c691..990744ff430 100644 --- a/packages/ember-metal/lib/watching.js +++ b/packages/ember-metal/lib/watching.js @@ -3,8 +3,7 @@ */ import { - removeChainWatcher, - flushPendingChains + removeChainWatcher } from 'ember-metal/chains'; import { watchKey, @@ -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; } diff --git a/packages/ember-metal/tests/watching/watch_test.js b/packages/ember-metal/tests/watching/watch_test.js index 23adba90c49..5486fdd5817 100644 --- a/packages/ember-metal/tests/watching/watch_test.js +++ b/packages/ember-metal/tests/watching/watch_test.js @@ -13,7 +13,7 @@ import { var willCount, didCount, willKeys, didKeys, - originalLookup, lookup, Global; + originalLookup, lookup; QUnit.module('watch', { setup() { @@ -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' };