Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
runEOM
Browse files Browse the repository at this point in the history
We only have one mechanism left that explicitly needs to wait to EOM to run which is responding to assignment to template.model.

This private API will be used by TemplateBinding, and allow the removal of the more complex and expensive ensureScheduled.

R=arv
BUG=

Review URL: https://codereview.appspot.com/48100043
  • Loading branch information
rafaelw committed Jan 6, 2014
1 parent 972b4a8 commit 3abce7a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,41 @@
};
}

var eomTasks = [];
function runEOMTasks() {
if (!eomTasks.length)
return false;

for (var i = 0; i < eomTasks.length; i++) {
eomTasks[i]();
}
eomTasks.length = 0;
return true;
}

var runEOM = hasObserve ? (function(){
var eomObj = { pingPong: true };
var eomRunScheduled = false;

Object.observe(eomObj, function() {
runEOMTasks();
eomRunScheduled = false;
});

return function(fn) {
eomTasks.push(fn);
if (!eomRunScheduled) {
eomRunScheduled = true;
eomObj.pingPong = !eomObj.pingPong;
}
};
})() :
(function() {
return function(fn) {
eomTasks.push(fn);
};
})();

var observedObjectCache = [];

function newObservedObject() {
Expand Down Expand Up @@ -589,6 +624,8 @@

allObservers.push(observer);
}
if (runEOMTasks())
anyChanged = true;
} while (cycles < MAX_DIRTY_CHECK_CYCLES && anyChanged);

if (global.testingExposeCycleCount)
Expand Down Expand Up @@ -1456,6 +1493,7 @@
}

global.Observer = Observer;
global.Observer.runEOM_ = runEOM;
global.Observer.hasObjectObserve = hasObserve;
global.ArrayObserver = ArrayObserver;
global.ArrayObserver.calculateSplices = function(current, previous) {
Expand Down

0 comments on commit 3abce7a

Please sign in to comment.