From fcb7a502794f19544f2d4b77c96eebb70830591d Mon Sep 17 00:00:00 2001 From: Rafael Weinstein Date: Mon, 6 Jan 2014 09:50:16 -0800 Subject: [PATCH] remove ensureScheduled from TemplateBinding R=arv BUG= Review URL: https://codereview.appspot.com/48110043 --- src/TemplateBinding.js | 81 +++--------------------------------------- tests/tests.js | 2 +- 2 files changed, 6 insertions(+), 77 deletions(-) diff --git a/src/TemplateBinding.js b/src/TemplateBinding.js index 3e67b3a..d54c75c 100644 --- a/src/TemplateBinding.js +++ b/src/TemplateBinding.js @@ -161,80 +161,6 @@ return hasTemplateElement && el.tagName == 'TEMPLATE'; } - var ensureScheduled = function() { - // We need to ping-pong between two Runners in order for the tests to - // simulate proper end-of-microtask behavior for Object.observe. Without - // this, we'll continue delivering to a single observer without allowing - // other observers in the same microtask to make progress. - - function Runner(nextRunner) { - this.nextRunner = nextRunner; - this.value = false; - this.lastValue = this.value; - this.scheduled = []; - this.scheduledIds = []; - this.running = false; - this.observer = new PathObserver(this, 'value'); - this.observer.open(this.run, this); - } - - Runner.prototype = { - schedule: function(async, id) { - if (this.scheduledIds[id]) - return; - - if (this.running) - return this.nextRunner.schedule(async, id); - - this.scheduledIds[id] = true; - this.scheduled.push(async); - - if (this.lastValue !== this.value) - return; - - this.value = !this.value; - }, - - run: function() { - this.running = true; - - for (var i = 0; i < this.scheduled.length; i++) { - var async = this.scheduled[i]; - var id = async[idExpando]; - this.scheduledIds[id] = false; - - if (typeof async === 'function') - async(); - else - async.resolve(); - } - - this.scheduled = []; - this.scheduledIds = []; - this.lastValue = this.value; - - this.running = false; - } - } - - var runner = new Runner(new Runner()); - - var nextId = 1; - var idExpando = '__scheduledId__'; - - function ensureScheduled(async) { - var id = async[idExpando]; - if (!async[idExpando]) { - id = nextId++; - async[idExpando] = id; - } - - runner.schedule(async, id); - } - - return ensureScheduled; - }(); - // FIXME: Observe templates being added/removed from documents // FIXME: Expose imperative API to decorate and observe templates in // "disconnected tress" (e.g. ShadowRoot) @@ -451,13 +377,17 @@ function ensureSetModelScheduled(template) { if (!template.setModelFn_) { template.setModelFn_ = function() { + template.setModelFnScheduled_ = false; processBindings(template, getBindings(template, template.prepareBindingFn_), template.model_); }; } - ensureScheduled(template.setModelFn_); + if (!template.setModelFnScheduled_) { + template.setModelFnScheduled_ = true; + Observer.runEOM_(template.setModelFn_); + } } mixin(HTMLTemplateElement.prototype, { @@ -899,7 +829,6 @@ this.updateIteratedValue(); }, - // Called as a result ensureScheduled (above). updateIteratedValue: function() { if (this.deps.hasIf) { var ifValue = this.deps.ifValue; diff --git a/tests/tests.js b/tests/tests.js index f9b99a5..c45a8a0 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -30,7 +30,7 @@ function doTeardown() { document.body.removeChild(testDiv); unbindAll(testDiv); Platform.performMicrotaskCheckpoint(); - assert.strictEqual(2, Observer._allObserversCount); + assert.strictEqual(0, Observer._allObserversCount); } function then(fn) {