123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- module.exports = (function() {
- var __MODS__ = {};
- var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
- var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
- var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
- var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
- __DEFINE__(1662612701689, function(require, module, exports) {
- module.exports =
- {
- parallel : require('./parallel.js'),
- serial : require('./serial.js'),
- serialOrdered : require('./serialOrdered.js')
- };
- }, function(modId) {var map = {"./parallel.js":1662612701690,"./serial.js":1662612701697,"./serialOrdered.js":1662612701698}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1662612701690, function(require, module, exports) {
- var iterate = require('./lib/iterate.js')
- , initState = require('./lib/state.js')
- , terminator = require('./lib/terminator.js')
- ;
- // Public API
- module.exports = parallel;
- /**
- * Runs iterator over provided array elements in parallel
- *
- * @param {array|object} list - array or object (named list) to iterate over
- * @param {function} iterator - iterator to run
- * @param {function} callback - invoked when all elements processed
- * @returns {function} - jobs terminator
- */
- function parallel(list, iterator, callback)
- {
- var state = initState(list);
- while (state.index < (state['keyedList'] || list).length)
- {
- iterate(list, iterator, state, function(error, result)
- {
- if (error)
- {
- callback(error, result);
- return;
- }
- // looks like it's the last one
- if (Object.keys(state.jobs).length === 0)
- {
- callback(null, state.results);
- return;
- }
- });
- state.index++;
- }
- return terminator.bind(state, callback);
- }
- }, function(modId) { var map = {"./lib/iterate.js":1662612701691,"./lib/state.js":1662612701695,"./lib/terminator.js":1662612701696}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1662612701691, function(require, module, exports) {
- var async = require('./async.js')
- , abort = require('./abort.js')
- ;
- // API
- module.exports = iterate;
- /**
- * Iterates over each job object
- *
- * @param {array|object} list - array or object (named list) to iterate over
- * @param {function} iterator - iterator to run
- * @param {object} state - current job status
- * @param {function} callback - invoked when all elements processed
- */
- function iterate(list, iterator, state, callback)
- {
- // store current index
- var key = state['keyedList'] ? state['keyedList'][state.index] : state.index;
- state.jobs[key] = runJob(iterator, key, list[key], function(error, output)
- {
- // don't repeat yourself
- // skip secondary callbacks
- if (!(key in state.jobs))
- {
- return;
- }
- // clean up jobs
- delete state.jobs[key];
- if (error)
- {
- // don't process rest of the results
- // stop still active jobs
- // and reset the list
- abort(state);
- }
- else
- {
- state.results[key] = output;
- }
- // return salvaged results
- callback(error, state.results);
- });
- }
- /**
- * Runs iterator over provided job element
- *
- * @param {function} iterator - iterator to invoke
- * @param {string|number} key - key/index of the element in the list of jobs
- * @param {mixed} item - job description
- * @param {function} callback - invoked after iterator is done with the job
- * @returns {function|mixed} - job abort function or something else
- */
- function runJob(iterator, key, item, callback)
- {
- var aborter;
- // allow shortcut if iterator expects only two arguments
- if (iterator.length == 2)
- {
- aborter = iterator(item, async(callback));
- }
- // otherwise go with full three arguments
- else
- {
- aborter = iterator(item, key, async(callback));
- }
- return aborter;
- }
- }, function(modId) { var map = {"./async.js":1662612701692,"./abort.js":1662612701694}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1662612701692, function(require, module, exports) {
- var defer = require('./defer.js');
- // API
- module.exports = async;
- /**
- * Runs provided callback asynchronously
- * even if callback itself is not
- *
- * @param {function} callback - callback to invoke
- * @returns {function} - augmented callback
- */
- function async(callback)
- {
- var isAsync = false;
- // check if async happened
- defer(function() { isAsync = true; });
- return function async_callback(err, result)
- {
- if (isAsync)
- {
- callback(err, result);
- }
- else
- {
- defer(function nextTick_callback()
- {
- callback(err, result);
- });
- }
- };
- }
- }, function(modId) { var map = {"./defer.js":1662612701693}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1662612701693, function(require, module, exports) {
- module.exports = defer;
- /**
- * Runs provided function on next iteration of the event loop
- *
- * @param {function} fn - function to run
- */
- function defer(fn)
- {
- var nextTick = typeof setImmediate == 'function'
- ? setImmediate
- : (
- typeof process == 'object' && typeof process.nextTick == 'function'
- ? process.nextTick
- : null
- );
- if (nextTick)
- {
- nextTick(fn);
- }
- else
- {
- setTimeout(fn, 0);
- }
- }
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1662612701694, function(require, module, exports) {
- // API
- module.exports = abort;
- /**
- * Aborts leftover active jobs
- *
- * @param {object} state - current state object
- */
- function abort(state)
- {
- Object.keys(state.jobs).forEach(clean.bind(state));
- // reset leftover jobs
- state.jobs = {};
- }
- /**
- * Cleans up leftover job by invoking abort function for the provided job id
- *
- * @this state
- * @param {string|number} key - job id to abort
- */
- function clean(key)
- {
- if (typeof this.jobs[key] == 'function')
- {
- this.jobs[key]();
- }
- }
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1662612701695, function(require, module, exports) {
- // API
- module.exports = state;
- /**
- * Creates initial state object
- * for iteration over list
- *
- * @param {array|object} list - list to iterate over
- * @param {function|null} sortMethod - function to use for keys sort,
- * or `null` to keep them as is
- * @returns {object} - initial state object
- */
- function state(list, sortMethod)
- {
- var isNamedList = !Array.isArray(list)
- , initState =
- {
- index : 0,
- keyedList: isNamedList || sortMethod ? Object.keys(list) : null,
- jobs : {},
- results : isNamedList ? {} : [],
- size : isNamedList ? Object.keys(list).length : list.length
- }
- ;
- if (sortMethod)
- {
- // sort array keys based on it's values
- // sort object's keys just on own merit
- initState.keyedList.sort(isNamedList ? sortMethod : function(a, b)
- {
- return sortMethod(list[a], list[b]);
- });
- }
- return initState;
- }
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1662612701696, function(require, module, exports) {
- var abort = require('./abort.js')
- , async = require('./async.js')
- ;
- // API
- module.exports = terminator;
- /**
- * Terminates jobs in the attached state context
- *
- * @this AsyncKitState#
- * @param {function} callback - final callback to invoke after termination
- */
- function terminator(callback)
- {
- if (!Object.keys(this.jobs).length)
- {
- return;
- }
- // fast forward iteration index
- this.index = this.size;
- // abort jobs
- abort(this);
- // send back results we have so far
- async(callback)(null, this.results);
- }
- }, function(modId) { var map = {"./abort.js":1662612701694,"./async.js":1662612701692}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1662612701697, function(require, module, exports) {
- var serialOrdered = require('./serialOrdered.js');
- // Public API
- module.exports = serial;
- /**
- * Runs iterator over provided array elements in series
- *
- * @param {array|object} list - array or object (named list) to iterate over
- * @param {function} iterator - iterator to run
- * @param {function} callback - invoked when all elements processed
- * @returns {function} - jobs terminator
- */
- function serial(list, iterator, callback)
- {
- return serialOrdered(list, iterator, null, callback);
- }
- }, function(modId) { var map = {"./serialOrdered.js":1662612701698}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1662612701698, function(require, module, exports) {
- var iterate = require('./lib/iterate.js')
- , initState = require('./lib/state.js')
- , terminator = require('./lib/terminator.js')
- ;
- // Public API
- module.exports = serialOrdered;
- // sorting helpers
- module.exports.ascending = ascending;
- module.exports.descending = descending;
- /**
- * Runs iterator over provided sorted array elements in series
- *
- * @param {array|object} list - array or object (named list) to iterate over
- * @param {function} iterator - iterator to run
- * @param {function} sortMethod - custom sort function
- * @param {function} callback - invoked when all elements processed
- * @returns {function} - jobs terminator
- */
- function serialOrdered(list, iterator, sortMethod, callback)
- {
- var state = initState(list, sortMethod);
- iterate(list, iterator, state, function iteratorHandler(error, result)
- {
- if (error)
- {
- callback(error, result);
- return;
- }
- state.index++;
- // are we there yet?
- if (state.index < (state['keyedList'] || list).length)
- {
- iterate(list, iterator, state, iteratorHandler);
- return;
- }
- // done here
- callback(null, state.results);
- });
- return terminator.bind(state, callback);
- }
- /*
- * -- Sort methods
- */
- /**
- * sort helper to sort array elements in ascending order
- *
- * @param {mixed} a - an item to compare
- * @param {mixed} b - an item to compare
- * @returns {number} - comparison result
- */
- function ascending(a, b)
- {
- return a < b ? -1 : a > b ? 1 : 0;
- }
- /**
- * sort helper to sort array elements in descending order
- *
- * @param {mixed} a - an item to compare
- * @param {mixed} b - an item to compare
- * @returns {number} - comparison result
- */
- function descending(a, b)
- {
- return -1 * ascending(a, b);
- }
- }, function(modId) { var map = {"./lib/iterate.js":1662612701691,"./lib/state.js":1662612701695,"./lib/terminator.js":1662612701696}; return __REQUIRE__(map[modId], modId); })
- return __REQUIRE__(1662612701689);
- })()
- //miniprogram-npm-outsideDeps=[]
- //# sourceMappingURL=index.js.map
|