36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
|
"use strict";
|
||
|
var util = require("./util");
|
||
|
var schedule;
|
||
|
var noAsyncScheduler = function() {
|
||
|
throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
|
||
|
};
|
||
|
if (util.isNode && typeof MutationObserver === "undefined") {
|
||
|
var GlobalSetImmediate = global.setImmediate;
|
||
|
var ProcessNextTick = process.nextTick;
|
||
|
schedule = util.isRecentNode
|
||
|
? function(fn) { GlobalSetImmediate.call(global, fn); }
|
||
|
: function(fn) { ProcessNextTick.call(process, fn); };
|
||
|
} else if ((typeof MutationObserver !== "undefined") &&
|
||
|
!(typeof window !== "undefined" &&
|
||
|
window.navigator &&
|
||
|
window.navigator.standalone)) {
|
||
|
schedule = function(fn) {
|
||
|
var div = document.createElement("div");
|
||
|
var observer = new MutationObserver(fn);
|
||
|
observer.observe(div, {attributes: true});
|
||
|
return function() { div.classList.toggle("foo"); };
|
||
|
};
|
||
|
schedule.isStatic = true;
|
||
|
} else if (typeof setImmediate !== "undefined") {
|
||
|
schedule = function (fn) {
|
||
|
setImmediate(fn);
|
||
|
};
|
||
|
} else if (typeof setTimeout !== "undefined") {
|
||
|
schedule = function (fn) {
|
||
|
setTimeout(fn, 0);
|
||
|
};
|
||
|
} else {
|
||
|
schedule = noAsyncScheduler;
|
||
|
}
|
||
|
module.exports = schedule;
|