-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FView.defer loop with max loop process time
- Loading branch information
Showing
4 changed files
with
43 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var DEFER_RUN_THRESHOLD = 2; | ||
|
||
/* | ||
* Rather than just `setTimeout(f, 0)`, let's assume defer'd functions don't | ||
* need to be run "as soon as possible". We can loop through them once per | ||
* frame, and abort the queue if we exceed the given threshold. Inspired by | ||
* famous 0.3. | ||
*/ | ||
|
||
var queue = []; | ||
var timer = typeof performance === 'object' ? performance : Date; | ||
|
||
FView.defer = function(func) { | ||
queue.push(func); | ||
}; | ||
|
||
// avoid garbage collection | ||
var start, i, len, diff; | ||
|
||
var deferRunObj = { | ||
onUpdate: function() { | ||
start = timer.now(); | ||
len = queue.length; | ||
|
||
for (i = 0; i < len && timer.now() - start < DEFER_RUN_THRESHOLD; i++) | ||
queue[i](); | ||
|
||
queue.splice(0, i); | ||
FamousEngine.requestUpdateOnNextTick(deferRunObj); | ||
} | ||
}; | ||
|
||
FView.ready(function() { | ||
FamousEngine.requestUpdate(deferRunObj); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
FView.ready(function() { | ||
var clock = FamousEngine.getClock(); | ||
// log.debug('Overriding Meteor._setImmediate() to use famous clock'); | ||
// log.debug('Overriding Meteor._setImmediate() to use FView.defer'); | ||
|
||
var setImmediate = function (fn) { | ||
clock.setTimeout(fn, 0); | ||
}; | ||
var setImmediate = function (fn) { | ||
FView.defer(fn); | ||
}; | ||
|
||
setImmediate.implementation = 'famous'; | ||
Meteor._setImmediate = setImmediate; | ||
}); | ||
setImmediate.implementation = 'famous'; | ||
Meteor._setImmediate = setImmediate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters