baseWrapperValue.js 873 B

1234567891011121314151617181920212223242526272829
  1. var LazyWrapper = require('./LazyWrapper'),
  2. arrayPush = require('./arrayPush');
  3. /**
  4. * The base implementation of `wrapperValue` which returns the result of
  5. * performing a sequence of actions on the unwrapped `value`, where each
  6. * successive action is supplied the return value of the previous.
  7. *
  8. * @private
  9. * @param {*} value The unwrapped value.
  10. * @param {Array} actions Actions to peform to resolve the unwrapped value.
  11. * @returns {*} Returns the resolved value.
  12. */
  13. function baseWrapperValue(value, actions) {
  14. var result = value;
  15. if (result instanceof LazyWrapper) {
  16. result = result.value();
  17. }
  18. var index = -1,
  19. length = actions.length;
  20. while (++index < length) {
  21. var action = actions[index];
  22. result = action.func.apply(action.thisArg, arrayPush([result], action.args));
  23. }
  24. return result;
  25. }
  26. module.exports = baseWrapperValue;