use requestAnimationFrame

This commit is contained in:
nightwing 2012-11-04 16:25:36 +04:00
commit 6dddfe8edd
2 changed files with 17 additions and 10 deletions

View file

@ -3,7 +3,7 @@
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
@ -14,7 +14,7 @@
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -287,7 +287,7 @@ if (window.postMessage && !useragent.isOldIE) {
var postMessageId = 1;
exports.nextTick = function(callback, win) {
win = win || window;
var messageName = "zero-timeout-message-" + postMessageId;
var messageName = "zero-timeout-message-" + postMessageId;
exports.addListener(win, "message", function listener(e) {
if (e.data == messageName) {
exports.stopPropagation(e);
@ -298,11 +298,18 @@ if (window.postMessage && !useragent.isOldIE) {
win.postMessage(messageName, "*");
};
}
else {
exports.nextTick = function(callback, win) {
win = win || window;
window.setTimeout(callback, 0);
};
}
exports.nextFrame = window.requestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame;
if (exports.nextFrame)
exports.nextFrame = exports.nextFrame.bind(window);
else
exports.nextFrame = function(callback) {
setTimeout(callback, 17);
};
});

View file

@ -68,7 +68,7 @@ var RenderLoop = function(onRender, win) {
if (!this.pending) {
this.pending = true;
var _self = this;
event.nextTick(function() {
event.nextFrame(function() {
_self.pending = false;
var changes;
while (changes = _self.changes) {