From 051ec8a24d7ff5e3cd55b8c61bbf35882c0136f5 Mon Sep 17 00:00:00 2001 From: cliren Date: Mon, 2 Mar 2015 12:37:30 -0800 Subject: [PATCH] cleanup --- demo/async-loader.js | 1153 ------------------------------------------ demo/loader.js | 93 ---- demo/require.html | 25 - demo/script.html | 30 -- demo/test.html | 34 -- 5 files changed, 1335 deletions(-) delete mode 100644 demo/async-loader.js delete mode 100644 demo/loader.js delete mode 100644 demo/require.html delete mode 100644 demo/script.html delete mode 100644 demo/test.html diff --git a/demo/async-loader.js b/demo/async-loader.js deleted file mode 100644 index 189c658..0000000 --- a/demo/async-loader.js +++ /dev/null @@ -1,1153 +0,0 @@ -(function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); - else if(typeof define === 'function' && define.amd) - define(factory); - else if(typeof exports === 'object') - exports["AsyncLoader"] = factory(); - else - root["AsyncLoader"] = factory(); -})(this, function() { -return /******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; -/******/ -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.loaded = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ function(module, exports, __webpack_require__) { - - "use strict"; - - var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; - - var has = __webpack_require__(2).has; - - var loadScript = _interopRequire(__webpack_require__(1)); - - var AsyncLoader = { - load: function load(path) { - return loadScript(path); - } - }; - - module.exports = AsyncLoader; - -/***/ }, -/* 1 */ -/***/ function(module, exports, __webpack_require__) { - - "use strict"; - - var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; - - module.exports = loadScript; - - var $script = _interopRequire(__webpack_require__(4)); - - var Q = _interopRequire(__webpack_require__(3)); - - function loadScript(path) { - - var successDefer = Q.defer(); - - var fn = function fn() { - successDefer.resolve("ok"); - }; - - $script.get(path, fn); - return successDefer; - } - -/***/ }, -/* 2 */ -/***/ function(module, exports, __webpack_require__) { - - /** Used for native method references. */ - var objectProto = Object.prototype; - - /** Used to check objects for own properties. */ - var hasOwnProperty = objectProto.hasOwnProperty; - - /** - * Checks if `key` exists as a direct property of `object` instead of an - * inherited property. - * - * @static - * @memberOf _ - * @category Object - * @param {Object} object The object to inspect. - * @param {string} key The key to check. - * @returns {boolean} Returns `true` if `key` is a direct property, else `false`. - * @example - * - * _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); - * // => true - */ - function has(object, key) { - return object ? hasOwnProperty.call(object, key) : false; - } - - module.exports = has; - - -/***/ }, -/* 3 */ -/***/ function(module, exports, __webpack_require__) { - - /* WEBPACK VAR INJECTION */(function(process) { - /** - * An object representing a "promise" for a future value - * - * @param {?function(T, ?)=} onSuccess a function to handle successful - * resolution of this promise - * @param {?function(!Error, ?)=} onFail a function to handle failed - * resolution of this promise - * @constructor - * @template T - */ - function Promise(onSuccess, onFail) { - this.promise = this - this._isPromise = true - this._successFn = onSuccess - this._failFn = onFail - this._scope = this - this._boundArgs = null - this._hasContext = false - this._nextContext = undefined - this._currentContext = undefined - } - - /** - * @param {function()} callback - */ - function nextTick (callback) { - callback() - } - - if (typeof process !== 'undefined') { - nextTick = process.nextTick - } - - /** - * All callback execution should go through this function. While the - * implementation below is simple, it can be replaced with more sophisticated - * implementations that enforce QoS on the event loop. - * - * @param {Promise} defer - * @param {Function} callback - * @param {Object|undefined} scope - * @param {Array} args - */ - function nextTickCallback (defer, callback, scope, args) { - try { - defer.resolve(callback.apply(scope, args)) - } catch (thrown) { - defer.reject(thrown) - } - } - - /** - * Used for accessing the nextTick function from outside the kew module. - * - * @return {Function} - */ - function getNextTickFunction () { - return nextTick - } - - /** - * Used for overriding the nextTick function from outside the kew module so that - * the user can plug and play lower level schedulers - * @param {!Function} fn - */ - function setNextTickFunction (fn) { - nextTick = fn - } - - /** - * Keep track of the number of promises that are rejected along side - * the number of rejected promises we call _failFn on so we can look - * for leaked rejections. - * @constructor - */ - function PromiseStats() { - /** @type {number} */ - this.errorsEmitted = 0 - - /** @type {number} */ - this.errorsHandled = 0 - } - - var stats = new PromiseStats() - - Promise.prototype._handleError = function () { - if (!this._errorHandled) { - stats.errorsHandled++ - this._errorHandled = true - } - } - - /** - * Specify that the current promise should have a specified context - * @param {*} context context - * @private - */ - Promise.prototype._useContext = function (context) { - this._nextContext = this._currentContext = context - this._hasContext = true - return this - } - - Promise.prototype.clearContext = function () { - this._hasContext = false - this._nextContext = undefined - return this - } - - /** - * Set the context for all promise handlers to follow - * - * NOTE(dpup): This should be considered deprecated. It does not do what most - * people would expect. The context will be passed as a second argument to all - * subsequent callbacks. - * - * @param {*} context An arbitrary context - */ - Promise.prototype.setContext = function (context) { - this._nextContext = context - this._hasContext = true - return this - } - - /** - * Get the context for a promise - * @return {*} the context set by setContext - */ - Promise.prototype.getContext = function () { - return this._nextContext - } - - /** - * Resolve this promise with a specified value - * - * @param {*=} data - */ - Promise.prototype.resolve = function (data) { - if (this._error || this._hasData) throw new Error("Unable to resolve or reject the same promise twice") - - var i - if (data && isPromise(data)) { - this._child = data - if (this._promises) { - for (i = 0; i < this._promises.length; i += 1) { - data._chainPromise(this._promises[i]) - } - delete this._promises - } - - if (this._onComplete) { - for (i = 0; i < this._onComplete.length; i+= 1) { - data.fin(this._onComplete[i]) - } - delete this._onComplete - } - } else if (data && isPromiseLike(data)) { - data.then( - function(data) { this.resolve(data) }.bind(this), - function(err) { this.reject(err) }.bind(this) - ) - } else { - this._hasData = true - this._data = data - - if (this._onComplete) { - for (i = 0; i < this._onComplete.length; i++) { - this._onComplete[i]() - } - } - - if (this._promises) { - for (i = 0; i < this._promises.length; i += 1) { - this._promises[i]._useContext(this._nextContext) - this._promises[i]._withInput(data) - } - delete this._promises - } - } - } - - /** - * Reject this promise with an error - * - * @param {!Error} e - */ - Promise.prototype.reject = function (e) { - if (this._error || this._hasData) throw new Error("Unable to resolve or reject the same promise twice") - - var i - this._error = e - stats.errorsEmitted++ - - if (this._ended) { - this._handleError() - process.nextTick(function onPromiseThrow() { - throw e - }) - } - - if (this._onComplete) { - for (i = 0; i < this._onComplete.length; i++) { - this._onComplete[i]() - } - } - - if (this._promises) { - this._handleError() - for (i = 0; i < this._promises.length; i += 1) { - this._promises[i]._useContext(this._nextContext) - this._promises[i]._withError(e) - } - delete this._promises - } - } - - /** - * Provide a callback to be called whenever this promise successfully - * resolves. Allows for an optional second callback to handle the failure - * case. - * - * @param {?function(this:void, T, ?): RESULT|undefined} onSuccess - * @param {?function(this:void, !Error, ?): RESULT=} onFail - * @return {!Promise.} returns a new promise with the output of the onSuccess or - * onFail handler - * @template RESULT - */ - Promise.prototype.then = function (onSuccess, onFail) { - var promise = new Promise(onSuccess, onFail) - if (this._nextContext) promise._useContext(this._nextContext) - - if (this._child) this._child._chainPromise(promise) - else this._chainPromise(promise) - - return promise - } - - /** - * Provide a callback to be called whenever this promise successfully - * resolves. The callback will be executed in the context of the provided scope. - * - * @param {function(this:SCOPE, ...): RESULT} onSuccess - * @param {SCOPE} scope Object whose context callback will be executed in. - * @param {...*} var_args Additional arguments to be passed to the promise callback. - * @return {!Promise.} returns a new promise with the output of the onSuccess - * @template SCOPE, RESULT - */ - Promise.prototype.thenBound = function (onSuccess, scope, var_args) { - var promise = new Promise(onSuccess) - if (this._nextContext) promise._useContext(this._nextContext) - - promise._scope = scope - if (arguments.length > 2) { - promise._boundArgs = Array.prototype.slice.call(arguments, 2) - } - - // Chaining must happen after setting args and scope since it may fire callback. - if (this._child) this._child._chainPromise(promise) - else this._chainPromise(promise) - - return promise - } - - /** - * Provide a callback to be called whenever this promise is rejected - * - * @param {function(this:void, !Error, ?)} onFail - * @return {!Promise.} returns a new promise with the output of the onFail handler - */ - Promise.prototype.fail = function (onFail) { - return this.then(null, onFail) - } - - /** - * Provide a callback to be called whenever this promise is rejected. - * The callback will be executed in the context of the provided scope. - * - * @param {function(this:SCOPE, ...)} onFail - * @param {SCOPE} scope Object whose context callback will be executed in. - * @param {...?} var_args - * @return {!Promise.} returns a new promise with the output of the onSuccess - * @template SCOPE - */ - Promise.prototype.failBound = function (onFail, scope, var_args) { - var promise = new Promise(null, onFail) - if (this._nextContext) promise._useContext(this._nextContext) - - promise._scope = scope - if (arguments.length > 2) { - promise._boundArgs = Array.prototype.slice.call(arguments, 2) - } - - // Chaining must happen after setting args and scope since it may fire callback. - if (this._child) this._child._chainPromise(promise) - else this._chainPromise(promise) - - return promise - } - - /** - * Provide a callback to be called whenever this promise is either resolved - * or rejected. - * - * @param {function()} onComplete - * @return {!Promise.} returns the current promise - */ - Promise.prototype.fin = function (onComplete) { - if (this._hasData || this._error) { - onComplete() - return this - } - - if (this._child) { - this._child.fin(onComplete) - } else { - if (!this._onComplete) this._onComplete = [onComplete] - else this._onComplete.push(onComplete) - } - - return this - } - - /** - * Mark this promise as "ended". If the promise is rejected, this will throw an - * error in whatever scope it happens to be in - * - * @return {!Promise.} returns the current promise - * @deprecated Prefer done(), because it's consistent with Q. - */ - Promise.prototype.end = function () { - this._end() - return this - } - - - /** - * Mark this promise as "ended". - * @private - */ - Promise.prototype._end = function () { - if (this._error) { - this._handleError() - throw this._error - } - this._ended = true - return this - } - - /** - * Close the promise. Any errors after this completes will be thrown to the global handler. - * - * @param {?function(this:void, T, ?)=} onSuccess a function to handle successful - * resolution of this promise - * @param {?function(this:void, !Error, ?)=} onFailure a function to handle failed - * resolution of this promise - * @return {void} - */ - Promise.prototype.done = function (onSuccess, onFailure) { - var self = this - if (onSuccess || onFailure) { - self = self.then(onSuccess, onFailure) - } - self._end() - } - - /** - * Return a new promise that behaves the same as the current promise except - * that it will be rejected if the current promise does not get fulfilled - * after a certain amount of time. - * - * @param {number} timeoutMs The timeout threshold in msec - * @param {string=} timeoutMsg error message - * @return {!Promise.} a new promise with timeout - */ - Promise.prototype.timeout = function (timeoutMs, timeoutMsg) { - var deferred = new Promise() - var isTimeout = false - - var timeout = setTimeout(function() { - deferred.reject(new Error(timeoutMsg || 'Promise timeout after ' + timeoutMs + ' ms.')) - isTimeout = true - }, timeoutMs) - - this.then(function (data) { - if (!isTimeout) { - clearTimeout(timeout) - deferred.resolve(data) - } - }, - function (err) { - if (!isTimeout) { - clearTimeout(timeout) - deferred.reject(err) - } - }) - - return deferred.promise - } - - /** - * Attempt to resolve this promise with the specified input - * - * @param {*} data the input - */ - Promise.prototype._withInput = function (data) { - if (this._successFn) { - this._nextTick(this._successFn, [data, this._currentContext]) - } else { - this.resolve(data) - } - - // context is no longer needed - delete this._currentContext - } - - /** - * Attempt to reject this promise with the specified error - * - * @param {!Error} e - * @private - */ - Promise.prototype._withError = function (e) { - if (this._failFn) { - this._nextTick(this._failFn, [e, this._currentContext]) - } else { - this.reject(e) - } - - // context is no longer needed - delete this._currentContext - } - - /** - * Calls a function in the correct scope, and includes bound arguments. - * @param {Function} fn - * @param {Array} args - * @private - */ - Promise.prototype._nextTick = function (fn, args) { - if (this._boundArgs) { - args = this._boundArgs.concat(args) - } - nextTick(nextTickCallback.bind(null, this, fn, this._scope, args)) - } - - /** - * Chain a promise to the current promise - * - * @param {!Promise} promise the promise to chain - * @private - */ - Promise.prototype._chainPromise = function (promise) { - var i - if (this._hasContext) promise._useContext(this._nextContext) - - if (this._child) { - this._child._chainPromise(promise) - } else if (this._hasData) { - promise._withInput(this._data) - } else if (this._error) { - // We can't rely on _withError() because it's called on the chained promises - // and we need to use the source's _errorHandled state - this._handleError() - promise._withError(this._error) - } else if (!this._promises) { - this._promises = [promise] - } else { - this._promises.push(promise) - } - } - - /** - * Utility function used for creating a node-style resolver - * for deferreds - * - * @param {!Promise} deferred a promise that looks like a deferred - * @param {Error=} err an optional error - * @param {*=} data optional data - */ - function resolver(deferred, err, data) { - if (err) deferred.reject(err) - else deferred.resolve(data) - } - - /** - * Creates a node-style resolver for a deferred by wrapping - * resolver() - * - * @return {function(?Error, *)} node-style callback - */ - Promise.prototype.makeNodeResolver = function () { - return resolver.bind(null, this) - } - - /** - * Return true iff the given object is a promise of this library. - * - * Because kew's API is slightly different than other promise libraries, - * it's important that we have a test for its promise type. If you want - * to test for a more general A+ promise, you should do a cap test for - * the features you want. - * - * @param {*} obj The object to test - * @return {boolean} Whether the object is a promise - */ - function isPromise(obj) { - return !!obj._isPromise - } - - /** - * Return true iff the given object is a promise-like object, e.g. appears to - * implement Promises/A+ specification - * - * @param {*} obj The object to test - * @return {boolean} Whether the object is a promise-like object - */ - function isPromiseLike(obj) { - return (typeof obj === 'object' || typeof obj === 'function') && - typeof obj.then === 'function' - } - - /** - * Static function which creates and resolves a promise immediately - * - * @param {T} data data to resolve the promise with - * @return {!Promise.} - * @template T - */ - function resolve(data) { - var promise = new Promise() - promise.resolve(data) - return promise - } - - /** - * Static function which creates and rejects a promise immediately - * - * @param {!Error} e error to reject the promise with - * @return {!Promise} - */ - function reject(e) { - var promise = new Promise() - promise.reject(e) - return promise - } - - /** - * Replace an element in an array with a new value. Used by .all() to - * call from .then() - * - * @param {!Array} arr - * @param {number} idx - * @param {*} val - * @return {*} the val that's being injected into the array - */ - function replaceEl(arr, idx, val) { - arr[idx] = val - return val - } - - /** - * Replace an element in an array as it is resolved with its value. - * Used by .allSettled(). - * - * @param {!Array} arr - * @param {number} idx - * @param {*} value The value from a resolved promise. - * @return {*} the data that's being passed in - */ - function replaceElFulfilled(arr, idx, value) { - arr[idx] = { - state: 'fulfilled', - value: value - } - return value - } - - /** - * Replace an element in an array as it is rejected with the reason. - * Used by .allSettled(). - * - * @param {!Array} arr - * @param {number} idx - * @param {*} reason The reason why the original promise is rejected - * @return {*} the data that's being passed in - */ - function replaceElRejected(arr, idx, reason) { - arr[idx] = { - state: 'rejected', - reason: reason - } - return reason - } - - /** - * Takes in an array of promises or literals and returns a promise which returns - * an array of values when all have resolved. If any fail, the promise fails. - * - * @param {!Array.} promises - * @return {!Promise.} - */ - function all(promises) { - if (arguments.length != 1 || !Array.isArray(promises)) { - promises = Array.prototype.slice.call(arguments, 0) - } - if (!promises.length) return resolve([]) - - var outputs = [] - var finished = false - var promise = new Promise() - var counter = promises.length - - for (var i = 0; i < promises.length; i += 1) { - if (!promises[i] || !isPromiseLike(promises[i])) { - outputs[i] = promises[i] - counter -= 1 - } else { - promises[i].then(replaceEl.bind(null, outputs, i)) - .then(function decrementAllCounter() { - counter-- - if (!finished && counter === 0) { - finished = true - promise.resolve(outputs) - } - }, function onAllError(e) { - if (!finished) { - finished = true - promise.reject(e) - } - }) - } - } - - if (counter === 0 && !finished) { - finished = true - promise.resolve(outputs) - } - - return promise - } - - /** - * Takes in an array of promises or values and returns a promise that is - * fulfilled with an array of state objects when all have resolved or - * rejected. If a promise is resolved, its corresponding state object is - * {state: 'fulfilled', value: Object}; whereas if a promise is rejected, its - * corresponding state object is {state: 'rejected', reason: Object}. - * - * @param {!Array} promises or values - * @return {!Promise.} Promise fulfilled with state objects for each input - */ - function allSettled(promises) { - if (!Array.isArray(promises)) { - throw Error('The input to "allSettled()" should be an array of Promise or values') - } - if (!promises.length) return resolve([]) - - var outputs = [] - var promise = new Promise() - var counter = promises.length - - for (var i = 0; i < promises.length; i += 1) { - if (!promises[i] || !isPromiseLike(promises[i])) { - replaceElFulfilled(outputs, i, promises[i]) - if ((--counter) === 0) promise.resolve(outputs) - } else { - promises[i] - .then(replaceElFulfilled.bind(null, outputs, i), replaceElRejected.bind(null, outputs, i)) - .then(function () { - if ((--counter) === 0) promise.resolve(outputs) - }) - } - } - - return promise - } - - /** - * Create a new Promise which looks like a deferred - * - * @return {!Promise} - */ - function defer() { - return new Promise() - } - - /** - * Return a promise which will wait a specified number of ms to resolve - * - * @param {*} delayMsOrVal A delay (in ms) if this takes one argument, or ther - * return value if it takes two. - * @param {number=} opt_delayMs - * @return {!Promise} - */ - function delay(delayMsOrVal, opt_delayMs) { - var returnVal = undefined - var delayMs = delayMsOrVal - if (typeof opt_delayMs != 'undefined') { - delayMs = opt_delayMs - returnVal = delayMsOrVal - } - - if (typeof delayMs != 'number') { - throw new Error('Bad delay value ' + delayMs) - } - - var defer = new Promise() - setTimeout(function onDelay() { - defer.resolve(returnVal) - }, delayMs) - return defer - } - - /** - * Returns a promise that has the same result as `this`, but fulfilled - * after at least ms milliseconds - * @param {number} ms - */ - Promise.prototype.delay = function (ms) { - return this.then(function (val) { - return delay(val, ms) - }) - } - - /** - * Return a promise which will evaluate the function fn in a future turn with - * the provided args - * - * @param {function(...)} fn - * @param {...*} var_args a variable number of arguments - * @return {!Promise} - */ - function fcall(fn, var_args) { - var rootArgs = Array.prototype.slice.call(arguments, 1) - var defer = new Promise() - nextTick(nextTickCallback.bind(null, defer, fn, undefined, rootArgs)) - return defer - } - - - /** - * Returns a promise that will be invoked with the result of a node style - * callback. All args to fn should be given except for the final callback arg - * - * @param {function(...)} fn - * @param {...*} var_args a variable number of arguments - * @return {!Promise} - */ - function nfcall(fn, var_args) { - // Insert an undefined argument for scope and let bindPromise() do the work. - var args = Array.prototype.slice.call(arguments, 0) - args.splice(1, 0, undefined) - return bindPromise.apply(undefined, args)() - } - - - /** - * Binds a function to a scope with an optional number of curried arguments. Attaches - * a node style callback as the last argument and returns a promise - * - * @param {function(...)} fn - * @param {Object} scope - * @param {...*} var_args a variable number of arguments - * @return {function(...)}: !Promise} - */ - function bindPromise(fn, scope, var_args) { - var rootArgs = Array.prototype.slice.call(arguments, 2) - return function onBoundPromise(var_args) { - var defer = new Promise() - try { - fn.apply(scope, rootArgs.concat(Array.prototype.slice.call(arguments, 0), defer.makeNodeResolver())) - } catch (e) { - defer.reject(e) - } - return defer - } - } - - module.exports = { - all: all - , bindPromise: bindPromise - , defer: defer - , delay: delay - , fcall: fcall - , isPromise: isPromise - , isPromiseLike: isPromiseLike - , nfcall: nfcall - , resolve: resolve - , reject: reject - , stats: stats - , allSettled: allSettled - , Promise: Promise - , getNextTickFunction: getNextTickFunction - , setNextTickFunction: setNextTickFunction - } - - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5))) - -/***/ }, -/* 4 */ -/***/ function(module, exports, __webpack_require__) { - - var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! - * $script.js JS loader & dependency manager - * https://github.com/ded/script.js - * (c) Dustin Diaz 2014 | License MIT - */ - - (function (name, definition) { - if (typeof module != 'undefined' && module.exports) module.exports = definition() - else if (true) !(__WEBPACK_AMD_DEFINE_FACTORY__ = (definition), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) - else this[name] = definition() - })('$script', function () { - var doc = document - , head = doc.getElementsByTagName('head')[0] - , s = 'string' - , f = false - , push = 'push' - , readyState = 'readyState' - , onreadystatechange = 'onreadystatechange' - , list = {} - , ids = {} - , delay = {} - , scripts = {} - , scriptpath - , urlArgs - - function every(ar, fn) { - for (var i = 0, j = ar.length; i < j; ++i) if (!fn(ar[i])) return f - return 1 - } - function each(ar, fn) { - every(ar, function (el) { - return !fn(el) - }) - } - - function $script(paths, idOrDone, optDone) { - paths = paths[push] ? paths : [paths] - var idOrDoneIsDone = idOrDone && idOrDone.call - , done = idOrDoneIsDone ? idOrDone : optDone - , id = idOrDoneIsDone ? paths.join('') : idOrDone - , queue = paths.length - function loopFn(item) { - return item.call ? item() : list[item] - } - function callback() { - if (!--queue) { - list[id] = 1 - done && done() - for (var dset in delay) { - every(dset.split('|'), loopFn) && !each(delay[dset], loopFn) && (delay[dset] = []) - } - } - } - setTimeout(function () { - each(paths, function loading(path, force) { - if (path === null) return callback() - path = !force && path.indexOf('.js') === -1 && !/^https?:\/\//.test(path) && scriptpath ? scriptpath + path + '.js' : path - if (scripts[path]) { - if (id) ids[id] = 1 - return (scripts[path] == 2) ? callback() : setTimeout(function () { loading(path, true) }, 0) - } - - scripts[path] = 1 - if (id) ids[id] = 1 - create(path, callback) - }) - }, 0) - return $script - } - - function create(path, fn) { - var el = doc.createElement('script'), loaded - el.onload = el.onerror = el[onreadystatechange] = function () { - if ((el[readyState] && !(/^c|loade/.test(el[readyState]))) || loaded) return; - el.onload = el[onreadystatechange] = null - loaded = 1 - scripts[path] = 2 - fn() - } - el.async = 1 - el.src = urlArgs ? path + (path.indexOf('?') === -1 ? '?' : '&') + urlArgs : path; - head.insertBefore(el, head.lastChild) - } - - $script.get = create - - $script.order = function (scripts, id, done) { - (function callback(s) { - s = scripts.shift() - !scripts.length ? $script(s, id, done) : $script(s, callback) - }()) - } - - $script.path = function (p) { - scriptpath = p - } - $script.urlArgs = function (str) { - urlArgs = str; - } - $script.ready = function (deps, ready, req) { - deps = deps[push] ? deps : [deps] - var missing = []; - !each(deps, function (dep) { - list[dep] || missing[push](dep); - }) && every(deps, function (dep) {return list[dep]}) ? - ready() : !function (key) { - delay[key] = delay[key] || [] - delay[key][push](ready) - req && req(missing) - }(deps.join('|')) - return $script - } - - $script.done = function (idOrDone) { - $script([null], idOrDone) - } - - return $script - }); - - -/***/ }, -/* 5 */ -/***/ function(module, exports, __webpack_require__) { - - // shim for using process in browser - - var process = module.exports = {}; - - process.nextTick = (function () { - var canSetImmediate = typeof window !== 'undefined' - && window.setImmediate; - var canMutationObserver = typeof window !== 'undefined' - && window.MutationObserver; - var canPost = typeof window !== 'undefined' - && window.postMessage && window.addEventListener - ; - - if (canSetImmediate) { - return function (f) { return window.setImmediate(f) }; - } - - var queue = []; - - if (canMutationObserver) { - var hiddenDiv = document.createElement("div"); - var observer = new MutationObserver(function () { - var queueList = queue.slice(); - queue.length = 0; - queueList.forEach(function (fn) { - fn(); - }); - }); - - observer.observe(hiddenDiv, { attributes: true }); - - return function nextTick(fn) { - if (!queue.length) { - hiddenDiv.setAttribute('yes', 'no'); - } - queue.push(fn); - }; - } - - if (canPost) { - window.addEventListener('message', function (ev) { - var source = ev.source; - if ((source === window || source === null) && ev.data === 'process-tick') { - ev.stopPropagation(); - if (queue.length > 0) { - var fn = queue.shift(); - fn(); - } - } - }, true); - - return function nextTick(fn) { - queue.push(fn); - window.postMessage('process-tick', '*'); - }; - } - - return function nextTick(fn) { - setTimeout(fn, 0); - }; - })(); - - process.title = 'browser'; - process.browser = true; - process.env = {}; - process.argv = []; - - function noop() {} - - process.on = noop; - process.addListener = noop; - process.once = noop; - process.off = noop; - process.removeListener = noop; - process.removeAllListeners = noop; - process.emit = noop; - - process.binding = function (name) { - throw new Error('process.binding is not supported'); - }; - - // TODO(shtylman) - process.cwd = function () { return '/' }; - process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); - }; - - -/***/ } -/******/ ]) -}); diff --git a/demo/loader.js b/demo/loader.js deleted file mode 100644 index 442090a..0000000 --- a/demo/loader.js +++ /dev/null @@ -1,93 +0,0 @@ -/** - * @author apendua / apendua@gmail.com - */ - -// module request - -var ModuleRequest = function (name) { this.name = name; this.listeners = [] }; - -ModuleRequest.prototype.verify = function () { - if (this.handler && _.isFunction(this.handler.verify)) - return this.handler.verify(); -}; - -ModuleRequest.prototype.loaded = function (module) { - if (this.handler && _.isFunction(this.handler.loaded)) - return this.handler.loaded(module); -}; - -// module loader - -ModuleLoader = { _requests: {} }; - -ModuleLoader.define = function (name, handler) { - if (_.has(ModuleLoader._requests, name)) - throw new Error('module ' + name + ' is already defined'); - var request = ModuleLoader._getRequest(name); - request.handler = handler || {}; - // check if someone is waiting for this module - if (request.listeners.length > 0) - ModuleLoader.load(name); -}; - -ModuleLoader.ready = function (name, action) { - if (!_.isFunction(action)) - throw new Error('ModuleLoader.ready: the second argument must be a function'); - var request = ModuleLoader._getRequest(name); - if (!request.module) { - var listener = {stopped: false, action: action}; - // register listener - request.listeners.push(listener); - // tell that we want to load the module - ModuleLoader.load(name); - // handle to discard the listener - return {stop: function (){listener.stopped=true;}}; - } - action.call(undefined, request.module); - return {stop: function (){}}; -}; - -ModuleLoader.load = function (name) { - var request = ModuleLoader._getRequest(name); - // maybe the module is defined locally? - if (!request.module) - request.module = request.verify(); - if (request.module || request.lock || !request.handler) - // either the module has already been loaded, - // or it's being loaded right now - // or it has not been defined yet - return; - // prevent mutiple ajax calls - request.lock = true; - //TODO: handle progress event - $.ajax({ - url : request.handler.source, - type : 'GET', - dataType : 'script' - }).done(function (message) { - //TODO: can we use this message somehow (?) - // verify if the module has been loaded properlly - request.module = request.verify(); - if (request.module) { - request.loaded(request.module); - while (request.listeners.length > 0) { - listener = request.listeners.shift(); - if (!listener.stopped) - listener.action.call(undefined, request.module); - } - } else { - console.log('ERROR: module ', request.name, ' failed to load...'); - } - }).fail(function (jqXHR, textStatus) { - console.log('ERROR: unable to load source code from ', request.handler.source); - }); -}; - -// private routines - -ModuleLoader._getRequest = function (name) { - var requests = ModuleLoader._requests; - if (_.has(requests, name)) - return requests[name]; - return requests[name] = new ModuleRequest(name); -}; \ No newline at end of file diff --git a/demo/require.html b/demo/require.html deleted file mode 100644 index b740863..0000000 --- a/demo/require.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - Require Test - - - - - - - - -
- -
- - - \ No newline at end of file diff --git a/demo/script.html b/demo/script.html deleted file mode 100644 index a1fad7b..0000000 --- a/demo/script.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - Loader Test - - - - - - - - - -
- -
- - - \ No newline at end of file diff --git a/demo/test.html b/demo/test.html deleted file mode 100644 index 73db617..0000000 --- a/demo/test.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - Loader Test - - - - - - - - - -
- -
- - - \ No newline at end of file