express-yui
Version:
Express extension for YUI Applications
29 lines (28 loc) • 859 B
JavaScript
module.exports = function patchClientLazyUse(Y) {
var use = Y.use,
pending = [],
callbacks = [];
function flush() {
var p = pending,
c = callbacks;
if (p.length) {
pending = []; callbacks = []; // resetting
p.push(function () {
var i;
for (i = 0; i < c.length; i += 1) {
c[i].apply(this, arguments);
}
});
use.apply(Y, p);
}
}
Y.use = function () {
pending = pending.concat(Array.prototype.slice.call(arguments, 0));
// The last argument supplied to use can be a load complete callback
if (Y.Lang.isFunction(pending[pending.length - 1])) {
callbacks.push(pending.pop());
}
setTimeout(flush, 0);
return Y;
};
};