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.26 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/asynckit/lib/state.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/asynckit/lib/state.js