Sha256: 9c3fe921ce1c205c62ce1cca97e1eb9335f3ddf066626a36c9a44bd59bd7a2db

Contents?: true

Size: 941 Bytes

Versions: 91

Compression:

Stored size: 941 Bytes

Contents

// 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;
}

Version data entries

91 entries across 89 versions & 22 rubygems

Version Path
clapton-0.0.6 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.5 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.4 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.3 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.2 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.1 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
optimacms-0.1.61 spec/dummy/node_modules/asynckit/lib/state.js
waves_lib-0.1.0 js/node_modules/asynckit/lib/state.js
reed_sdk-1.0.1 node_modules/asynckit/lib/state.js
reed_sdk-1.0.0 node_modules/asynckit/lib/state.js
disco_app-0.18.0 test/dummy/node_modules/asynckit/lib/state.js
disco_app-0.18.2 test/dummy/node_modules/asynckit/lib/state.js
appmap-0.72.2 ./node_modules/asynckit/lib/state.js
appmap-0.72.1 ./node_modules/asynckit/lib/state.js
appmap-0.72.0 ./node_modules/asynckit/lib/state.js
appmap-0.71.0 ./node_modules/asynckit/lib/state.js
appmap-0.70.2 ./node_modules/asynckit/lib/state.js
appmap-0.70.1 ./node_modules/asynckit/lib/state.js
appmap-0.70.0 ./node_modules/asynckit/lib/state.js
appmap-0.69.0 ./node_modules/asynckit/lib/state.js