Beta 7 with some repo names changed.
This commit is contained in:
1 parent
0f7b40cca7
commit
963c19493a
3408 files changed
+462217
-15516
No files matched your search
+71
@@ -0,0 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
var callable, byObserver;
|
||||
|
||||
callable = function (fn) {
|
||||
if (typeof fn !== 'function') throw new TypeError(fn + " is not a function");
|
||||
return fn;
|
||||
};
|
||||
|
||||
byObserver = function (Observer) {
|
||||
var node = document.createTextNode(''), queue, currentQueue, i = 0;
|
||||
new Observer(function () {
|
||||
var callback;
|
||||
if (!queue) {
|
||||
if (!currentQueue) return;
|
||||
queue = currentQueue;
|
||||
} else if (currentQueue) {
|
||||
queue = currentQueue.concat(queue);
|
||||
}
|
||||
currentQueue = queue;
|
||||
queue = null;
|
||||
if (typeof currentQueue === 'function') {
|
||||
callback = currentQueue;
|
||||
currentQueue = null;
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
node.data = (i = ++i % 2); // Invoke other batch, to handle leftover callbacks in case of crash
|
||||
while (currentQueue) {
|
||||
callback = currentQueue.shift();
|
||||
if (!currentQueue.length) currentQueue = null;
|
||||
callback();
|
||||
}
|
||||
}).observe(node, { characterData: true });
|
||||
return function (fn) {
|
||||
callable(fn);
|
||||
if (queue) {
|
||||
if (typeof queue === 'function') queue = [queue, fn];
|
||||
else queue.push(fn);
|
||||
return;
|
||||
}
|
||||
queue = fn;
|
||||
node.data = (i = ++i % 2);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = (function () {
|
||||
// Node.js
|
||||
if ((typeof process === 'object') && process && (typeof process.nextTick === 'function')) {
|
||||
return process.nextTick;
|
||||
}
|
||||
|
||||
// MutationObserver
|
||||
if ((typeof document === 'object') && document) {
|
||||
if (typeof MutationObserver === 'function') return byObserver(MutationObserver);
|
||||
if (typeof WebKitMutationObserver === 'function') return byObserver(WebKitMutationObserver);
|
||||
}
|
||||
|
||||
// W3C Draft
|
||||
// http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/setImmediate/Overview.html
|
||||
if (typeof setImmediate === 'function') {
|
||||
return function (cb) { setImmediate(callable(cb)); };
|
||||
}
|
||||
|
||||
// Wide available standard
|
||||
if ((typeof setTimeout === 'function') || (typeof setTimeout === 'object')) {
|
||||
return function (cb) { setTimeout(callable(cb), 0); };
|
||||
}
|
||||
|
||||
return null;
|
||||
}());
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "next-tick",
|
||||
"version": "1.0.0",
|
||||
"description": "Environment agnostic nextTick polyfill",
|
||||
"author": "Mariusz Nowak <medyk@medikoo.com> (http://www.medikoo.com/)",
|
||||
"keywords": [
|
||||
"nexttick",
|
||||
"setImmediate",
|
||||
"setTimeout",
|
||||
"async"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/medikoo/next-tick.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tad": "^0.2.4",
|
||||
"xlint": "^0.2.2",
|
||||
"xlint-jslint-medikoo": "^0.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "node node_modules/xlint/bin/xlint --linter=node_modules/xlint-jslint-medikoo/index.js --no-cache --no-stream",
|
||||
"lint-console": "node node_modules/xlint/bin/xlint --linter=node_modules/xlint-jslint-medikoo/index.js --watch",
|
||||
"test": "node node_modules/tad/bin/tad"
|
||||
},
|
||||
"license": "MIT"
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz"
|
||||
,"_integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw="
|
||||
,"_from": "next-tick@~1.0.0"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (t, a, d) {
|
||||
var invoked;
|
||||
|
||||
a(t(function () {
|
||||
a(arguments.length, 0, "Arguments");
|
||||
invoked = true;
|
||||
}), undefined, "Return");
|
||||
a(invoked, undefined, "Is not run immediately");
|
||||
setTimeout(function () {
|
||||
a(invoked, true, "Run in next tick");
|
||||
invoked = [];
|
||||
t(function () { invoked.push(0); });
|
||||
t(function () { invoked.push(1); });
|
||||
t(function () { invoked.push(2); });
|
||||
setTimeout(function () {
|
||||
a.deep(invoked, [0, 1, 2], "Serial");
|
||||
d();
|
||||
}, 10);
|
||||
}, 10);
|
||||
};
|
||||
Reference in new issue
Block a user