UNPKG

bdn-pocket

Version:

pocket tools for managing redux and redux-saga

1,727 lines (1,485 loc) 92.7 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (factory((global['bdn-pocket'] = {}))); }(this, (function (exports) { 'use strict'; var array = Array.isArray; var _function = function isFunction(arg) { return typeof arg === 'function'; }; var object = function isObject(arg) { var type = typeof arg; return Boolean(arg) && (type === 'object' || type === 'function'); }; var stamp = function isStamp(arg) { return _function(arg) && _function(arg.compose); }; // More proper implementation would be // isDescriptor(obj) || isStamp(obj) // but there is no sense since stamp is function and function is object. var composable = object; var assign = Object.assign; var plainObject = function isPlainObject(value) { return Boolean(value) && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype; }; var object$2 = function isObject(arg) { var type = typeof arg; return Boolean(arg) && (type === 'object' || type === 'function'); }; var array$2 = Array.isArray; /** * The 'src' argument plays the command role. * The returned values is always of the same type as the 'src'. * @param dst The object to merge into * @param src The object to merge from * @returns {*} */ function mergeOne(dst, src) { if (src === undefined) return dst; // According to specification arrays must be concatenated. // Also, the '.concat' creates a new array instance. Overrides the 'dst'. if (array$2(src)) return (array$2(dst) ? dst : []).concat(src); // Now deal with non plain 'src' object. 'src' overrides 'dst' // Note that functions are also assigned! We do not deep merge functions. if (!plainObject(src)) return src; // See if 'dst' is allowed to be mutated. // If not - it's overridden with a new plain object. var returnValue = object$2(dst) ? dst : {}; var keys = Object.keys(src); for (var i = 0; i < keys.length; i += 1) { var key = keys[i]; var srcValue = src[key]; // Do not merge properties with the 'undefined' value. if (srcValue !== undefined) { var dstValue = returnValue[key]; // Recursive calls to mergeOne() must allow only plain objects or arrays in dst var newDst = plainObject(dstValue) || array$2(srcValue) ? dstValue : {}; // deep merge each property. Recursion! returnValue[key] = mergeOne(newDst, srcValue); } } return returnValue; } var merge = function (dst) { for (var i = 1; i < arguments.length; i++) { dst = mergeOne(dst, arguments[i]); } return dst; }; var slice = Array.prototype.slice; /** * Creates new factory instance. * @returns {Function} The new factory function. */ function createFactory() { return function Stamp(options) { var descriptor = Stamp.compose || {}; // Next line was optimized for most JS VMs. Please, be careful here! var obj = Object.create(descriptor.methods || null); merge(obj, descriptor.deepProperties); assign(obj, descriptor.properties); Object.defineProperties(obj, descriptor.propertyDescriptors || {}); if (!descriptor.initializers || descriptor.initializers.length === 0) return obj; if (options === undefined) options = {}; var inits = descriptor.initializers; var length = inits.length; for (var i = 0; i < length; i += 1) { var initializer = inits[i]; if (_function(initializer)) { var returnedValue = initializer.call(obj, options, {instance: obj, stamp: Stamp, args: slice.apply(arguments)}); obj = returnedValue === undefined ? obj : returnedValue; } } return obj; }; } /** * Returns a new stamp given a descriptor and a compose function implementation. * @param {Descriptor} [descriptor={}] The information about the object the stamp will be creating. * @param {Compose} composeFunction The "compose" function implementation. * @returns {Stamp} */ function createStamp(descriptor, composeFunction) { var Stamp = createFactory(); if (descriptor.staticDeepProperties) { merge(Stamp, descriptor.staticDeepProperties); } if (descriptor.staticProperties) { assign(Stamp, descriptor.staticProperties); } if (descriptor.staticPropertyDescriptors) { Object.defineProperties(Stamp, descriptor.staticPropertyDescriptors); } var composeImplementation = _function(Stamp.compose) ? Stamp.compose : composeFunction; Stamp.compose = function _compose() { 'use strict'; // to make sure `this` is not pointing to `global` or `window` return composeImplementation.apply(this, arguments); }; assign(Stamp.compose, descriptor); return Stamp; } function concatAssignFunctions(dstObject, srcArray, propName) { if (!array(srcArray)) return; var length = srcArray.length; var dstArray = dstObject[propName] || []; dstObject[propName] = dstArray; for (var i = 0; i < length; i += 1) { var fn = srcArray[i]; if (_function(fn) && dstArray.indexOf(fn) < 0) { dstArray.push(fn); } } } function combineProperties(dstObject, srcObject, propName, action) { if (!object(srcObject[propName])) return; if (!object(dstObject[propName])) dstObject[propName] = {}; action(dstObject[propName], srcObject[propName]); } function deepMergeAssign(dstObject, srcObject, propName) { combineProperties(dstObject, srcObject, propName, merge); } function mergeAssign(dstObject, srcObject, propName) { combineProperties(dstObject, srcObject, propName, assign); } /** * Mutates the dstDescriptor by merging the srcComposable data into it. * @param {Descriptor} dstDescriptor The descriptor object to merge into. * @param {Composable} [srcComposable] The composable * (either descriptor or stamp) to merge data form. */ function mergeComposable(dstDescriptor, srcComposable) { var srcDescriptor = (srcComposable && srcComposable.compose) || srcComposable; mergeAssign(dstDescriptor, srcDescriptor, 'methods'); mergeAssign(dstDescriptor, srcDescriptor, 'properties'); deepMergeAssign(dstDescriptor, srcDescriptor, 'deepProperties'); mergeAssign(dstDescriptor, srcDescriptor, 'propertyDescriptors'); mergeAssign(dstDescriptor, srcDescriptor, 'staticProperties'); deepMergeAssign(dstDescriptor, srcDescriptor, 'staticDeepProperties'); mergeAssign(dstDescriptor, srcDescriptor, 'staticPropertyDescriptors'); mergeAssign(dstDescriptor, srcDescriptor, 'configuration'); deepMergeAssign(dstDescriptor, srcDescriptor, 'deepConfiguration'); concatAssignFunctions(dstDescriptor, srcDescriptor.initializers, 'initializers'); concatAssignFunctions(dstDescriptor, srcDescriptor.composers, 'composers'); } /** * Given the list of composables (stamp descriptors and stamps) returns * a new stamp (composable factory function). * @typedef {Function} Compose * @param {...(Composable)} [arguments] The list of composables. * @returns {Stamp} A new stamp (aka composable factory function) */ var compose = function compose() { 'use strict'; // to make sure `this` is not pointing to `global` or `window` var descriptor = {}; var composables = []; if (composable(this)) { mergeComposable(descriptor, this); composables.push(this); } for (var i = 0; i < arguments.length; i++) { var arg = arguments[i]; if (composable(arg)) { mergeComposable(descriptor, arg); composables.push(arg); } } var stamp$$1 = createStamp(descriptor, compose); var composers = descriptor.composers; if (array(composers) && composers.length > 0) { for (var j = 0; j < composers.length; j += 1) { var composer = composers[j]; var returnedValue = composer({stamp: stamp$$1, composables: composables}); stamp$$1 = stamp(returnedValue) ? returnedValue : stamp$$1; } } return stamp$$1; }; /** * The Stamp Descriptor * @typedef {Function|Object} Descriptor * @returns {Stamp} A new stamp based on this Stamp * @property {Object} [methods] Methods or other data used as object instances' prototype * @property {Array<Function>} [initializers] List of initializers called for each object instance * @property {Array<Function>} [composers] List of callbacks called each time a composition happens * @property {Object} [properties] Shallow assigned properties of object instances * @property {Object} [deepProperties] Deeply merged properties of object instances * @property {Object} [staticProperties] Shallow assigned properties of Stamps * @property {Object} [staticDeepProperties] Deeply merged properties of Stamps * @property {Object} [configuration] Shallow assigned properties of Stamp arbitrary metadata * @property {Object} [deepConfiguration] Deeply merged properties of Stamp arbitrary metadata * @property {Object} [propertyDescriptors] ES5 Property Descriptors applied to object instances * @property {Object} [staticPropertyDescriptors] ES5 Property Descriptors applied to Stamps */ /** * The Stamp factory function * @typedef {Function} Stamp * @returns {*} Instantiated object * @property {Descriptor} compose - The Stamp descriptor and composition function */ /** * A composable object - stamp or descriptor * @typedef {Stamp|Descriptor} Composable */ function createShortcut(propName) { return function (arg) { 'use strict'; var param = {}; param[propName] = arg; return this && this.compose ? this.compose(param) : compose(param); }; } var properties = createShortcut('properties'); var staticProperties = createShortcut('staticProperties'); var configuration = createShortcut('configuration'); var deepProperties = createShortcut('deepProperties'); var staticDeepProperties = createShortcut('staticDeepProperties'); var deepConfiguration = createShortcut('deepConfiguration'); var initializers = createShortcut('initializers'); var shortcut = compose({ staticProperties: { methods: createShortcut('methods'), props: properties, properties: properties, statics: staticProperties, staticProperties: staticProperties, conf: configuration, configuration: configuration, deepProps: deepProperties, deepProperties: deepProperties, deepStatics: staticDeepProperties, staticDeepProperties: staticDeepProperties, deepConf: deepConfiguration, deepConfiguration: deepConfiguration, init: initializers, initializers: initializers, composers: createShortcut('composers'), propertyDescriptors: createShortcut('propertyDescriptors'), staticPropertyDescriptors: createShortcut('staticPropertyDescriptors') } }); var _function$2 = function isFunction(arg) { return typeof arg === 'function'; }; var stamp$2 = function isStamp(arg) { return _function$2(arg) && _function$2(arg.compose); }; var object$4 = function isObject(arg) { var type = typeof arg; return Boolean(arg) && (type === 'object' || type === 'function'); }; var concat = Array.prototype.concat; function extractFunctions() { var fns = concat.apply([], arguments).filter(_function$2); return fns.length === 0 ? undefined : fns; } function standardiseDescriptor(descr) { if (!object$4(descr)) return descr; var methods = descr.methods; var properties = descr.properties; var props = descr.props; var initializers = descr.initializers; var init = descr.init; var composers = descr.composers; var deepProperties = descr.deepProperties; var deepProps = descr.deepProps; var pd = descr.propertyDescriptors; var staticProperties = descr.staticProperties; var statics = descr.statics; var staticDeepProperties = descr.staticDeepProperties; var deepStatics = descr.deepStatics; var spd = descr.staticPropertyDescriptors; var configuration = descr.configuration; var conf = descr.conf; var deepConfiguration = descr.deepConfiguration; var deepConf = descr.deepConf; var p = object$4(props) || object$4(properties) ? assign({}, props, properties) : undefined; var dp = object$4(deepProps) ? merge({}, deepProps) : undefined; dp = object$4(deepProperties) ? merge(dp, deepProperties) : dp; var sp = object$4(statics) || object$4(staticProperties) ? assign({}, statics, staticProperties) : undefined; var sdp = object$4(deepStatics) ? merge({}, deepStatics) : undefined; sdp = object$4(staticDeepProperties) ? merge(sdp, staticDeepProperties) : sdp; var c = object$4(conf) || object$4(configuration) ? assign({}, conf, configuration) : undefined; var dc = object$4(deepConf) ? merge({}, deepConf) : undefined; dc = object$4(deepConfiguration) ? merge(dc, deepConfiguration) : dc; var ii = extractFunctions(init, initializers); var cc = extractFunctions(composers); var descriptor = {}; if (methods) descriptor.methods = methods; if (p) descriptor.properties = p; if (ii) descriptor.initializers = ii; if (cc) descriptor.composers = cc; if (dp) descriptor.deepProperties = dp; if (sp) descriptor.staticProperties = sp; if (sdp) descriptor.staticDeepProperties = sdp; if (pd) descriptor.propertyDescriptors = pd; if (spd) descriptor.staticPropertyDescriptors = spd; if (c) descriptor.configuration = c; if (dc) descriptor.deepConfiguration = dc; return descriptor; } function stampit() { 'use strict'; // to make sure `this` is not pointing to `global` or `window` var length = arguments.length, args = []; for (var i = 0; i < length; i += 1) { var arg = arguments[i]; args.push(stamp$2(arg) ? arg : standardiseDescriptor(arg)); } return compose.apply(this || baseStampit, args); // jshint ignore:line } var baseStampit = shortcut.compose({ staticProperties: { create: function () { return this.apply(this, arguments); }, compose: stampit // infecting } }); var shortcuts = shortcut.compose.staticProperties; for (var prop in shortcuts) stampit[prop] = shortcuts[prop].bind(baseStampit); stampit.compose = stampit.bind(); var it = stampit; var array$4 = Array.isArray; var object$6 = function isObject(arg) { var type = typeof arg; return Boolean(arg) && (type === 'object' || type === 'function'); }; var string = function isString(arg) { return typeof arg === 'string'; }; function initializer(opts, ref) { var conf = ref.stamp.compose.deepConfiguration; var keysToAssign = conf && conf.ArgOverProp; if (!keysToAssign || !keysToAssign.length) return; for (var i = 0; i < keysToAssign.length; i++) { var key = keysToAssign[i], incomingValue = opts[key]; if (incomingValue !== undefined) { this[key] = incomingValue; } } } function dedupe(array) { var result = []; for (var i = 0; i < array.length; i++) { var item = array[i]; if (result.indexOf(item) < 0) result.push(item); } return result; } var ArgOverProp = compose({ staticProperties: { argOverProp: function () { 'use strict'; var propNames = [], defaultProps; for (var i = 0; i < arguments.length; i++) { var arg = arguments[i]; if (string(arg)) { propNames.push(arg); } else if (array$4(arg)) { propNames = propNames.concat(arg.filter(string)); } else if (object$6(arg)) { defaultProps = assign(defaultProps || {}, arg); propNames = propNames.concat(Object.keys(arg)); } } var Stamp = this && this.compose ? this : ArgOverProp; return Stamp.compose({ deepConfiguration: {ArgOverProp: propNames}, properties: defaultProps // default property values }); } }, initializers: [initializer], composers: [function (opts) { var descriptor = opts.stamp.compose; var initializers = descriptor.initializers; // Always keep our initializer the first initializers.splice(initializers.indexOf(initializer), 1); initializers.unshift(initializer); var conf = descriptor.deepConfiguration; var propNames = conf && conf.ArgOverProp; if (!array$4(propNames)) return; conf.ArgOverProp = dedupe(propNames); }] }); var argOverProp = ArgOverProp; var argOverProp_1 = argOverProp.argOverProp; function constantize(str) { return str.toUpperCase().replace(/\s+/g, '_'); } var ActionType = it(argOverProp_1('prefix', 'transformer')).props({ prefix: 'my-app', transformer: constantize }).methods({ getType: function getType(type) { return this.prefix + '/' + this.transformer(type); } }); var _isPlaceholder = function _isPlaceholder(a) { return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; }; /** * Optimized internal one-arity curry function. * * @private * @category Function * @param {Function} fn The function to curry. * @return {Function} The curried function. */ var _curry1 = function _curry1(fn) { return function f1(a) { if (arguments.length === 0 || _isPlaceholder(a)) { return f1; } else { return fn.apply(this, arguments); } }; }; /** * Checks if the input value is `null` or `undefined`. * * @func * @memberOf R * @since v0.9.0 * @category Type * @sig * -> Boolean * @param {*} x The value to test. * @return {Boolean} `true` if `x` is `undefined` or `null`, otherwise `false`. * @example * * R.isNil(null); //=> true * R.isNil(undefined); //=> true * R.isNil(0); //=> false * R.isNil([]); //=> false */ var isNil = _curry1(function isNil(x) { return x == null; }); /** * Optimized internal two-arity curry function. * * @private * @category Function * @param {Function} fn The function to curry. * @return {Function} The curried function. */ var _curry2 = function _curry2(fn) { return function f2(a, b) { switch (arguments.length) { case 0: return f2; case 1: return _isPlaceholder(a) ? f2 : _curry1(function(_b) { return fn(a, _b); }); default: return _isPlaceholder(a) && _isPlaceholder(b) ? f2 : _isPlaceholder(a) ? _curry1(function(_a) { return fn(_a, b); }) : _isPlaceholder(b) ? _curry1(function(_b) { return fn(a, _b); }) : fn(a, b); } }; }; /** * Returns a function that when supplied an object returns the indicated * property of that object, if it exists. * * @func * @memberOf R * @since v0.1.0 * @category Object * @sig s -> {s: a} -> a | Undefined * @param {String} p The property name * @param {Object} obj The object to query * @return {*} The value at `obj.p`. * @see R.path * @example * * R.prop('x', {x: 100}); //=> 100 * R.prop('x', {}); //=> undefined */ var prop$1 = _curry2(function prop(p, obj) { return obj[p]; }); var _has = function _has(prop, obj) { return Object.prototype.hasOwnProperty.call(obj, prop); }; /** * Returns whether or not an object has an own property with the specified name * * @func * @memberOf R * @since v0.7.0 * @category Object * @sig s -> {s: x} -> Boolean * @param {String} prop The name of the property to check for. * @param {Object} obj The object to query. * @return {Boolean} Whether the property exists. * @example * * var hasName = R.has('name'); * hasName({name: 'alice'}); //=> true * hasName({name: 'bob'}); //=> true * hasName({}); //=> false * * var point = {x: 0, y: 0}; * var pointHas = R.has(R.__, point); * pointHas('x'); //=> true * pointHas('y'); //=> true * pointHas('z'); //=> false */ var has = _curry2(_has); var babelHelpers = {}; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var asyncGenerator = function () { function AwaitValue(value) { this.value = value; } function AsyncGenerator(gen) { var front, back; function send(key, arg) { return new Promise(function (resolve, reject) { var request = { key: key, arg: arg, resolve: resolve, reject: reject, next: null }; if (back) { back = back.next = request; } else { front = back = request; resume(key, arg); } }); } function resume(key, arg) { try { var result = gen[key](arg); var value = result.value; if (value instanceof AwaitValue) { Promise.resolve(value.value).then(function (arg) { resume("next", arg); }, function (arg) { resume("throw", arg); }); } else { settle(result.done ? "return" : "normal", result.value); } } catch (err) { settle("throw", err); } } function settle(type, value) { switch (type) { case "return": front.resolve({ value: value, done: true }); break; case "throw": front.reject(value); break; default: front.resolve({ value: value, done: false }); break; } front = front.next; if (front) { resume(front.key, front.arg); } else { back = null; } } this._invoke = send; if (typeof gen.return !== "function") { this.return = undefined; } } if (typeof Symbol === "function" && Symbol.asyncIterator) { AsyncGenerator.prototype[Symbol.asyncIterator] = function () { return this; }; } AsyncGenerator.prototype.next = function (arg) { return this._invoke("next", arg); }; AsyncGenerator.prototype.throw = function (arg) { return this._invoke("throw", arg); }; AsyncGenerator.prototype.return = function (arg) { return this._invoke("return", arg); }; return { wrap: function (fn) { return function () { return new AsyncGenerator(fn.apply(this, arguments)); }; }, await: function (value) { return new AwaitValue(value); } }; }(); babelHelpers; var Type = it(argOverProp_1('required', 'name', 'allowNull')).props({ required: true, // key required type: null, name: null, allowNull: false // null value allowed }).methods({ isValid: function isValid() { var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var name = arguments[1]; var propName = name || this.name; var hasProp = has(propName, o); var v = prop$1(propName, o); var isEmpty = isNil(v); if (this.required) { if (hasProp === false) { throw new Error('prop \'' + propName + '\' is required but missing'); } } if (isEmpty === true && this.allowNull === false && hasProp === true) { throw new Error('prop \'' + propName + '\' does not allow null value'); } if (isEmpty === false && this.isTypeOk(v) === false) { var typeOfV = this.getType(v); throw new Error('prop \'' + propName + '\' expect type ' + this.type + ' but received ' + typeOfV); } return true; }, /** * override using Stamp functionality * * const newType = Type * .props({ type: 'newType' }) * .methods({ * isTypeOk(v) { * return // make your test here * } * }) * @param {*} v */ isTypeOk: function isTypeOk(v) { if (isNil(this.type) === true) return true; return (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === this.type; }, getType: function getType(v) { var type = typeof v === 'undefined' ? 'undefined' : _typeof(v); if (type === 'object') { return Array.isArray(v) ? 'array' : 'object'; } else { return type; } } }); var number = Type.props({ type: 'number' }); var func = Type.props({ type: 'function' }); var bool = Type.props({ type: 'boolean' }); var string$2 = Type.props({ type: 'string' }); var object$8 = Type.props({ type: 'object' }).methods({ isTypeOk: function isTypeOk(v) { return this.getType(v) === 'object'; // return (typeof v === 'object') && !Array.isArray(v) } }); var array$6 = Type.props({ type: 'array' }).methods({ isTypeOk: function isTypeOk(v) { return this.getType(v) === 'array'; // return Array.isArray(v) } }); var mixed = Type.props({ type: 'mixed' }).methods({ isTypeOk: function isTypeOk() { return true; } }); var Types = { number: number, func: func, object: object$8, // shape: () => null, bool: bool, string: string$2, array: array$6, mixed: mixed }; /** * Optimized internal three-arity curry function. * * @private * @category Function * @param {Function} fn The function to curry. * @return {Function} The curried function. */ var _curry3 = function _curry3(fn) { return function f3(a, b, c) { switch (arguments.length) { case 0: return f3; case 1: return _isPlaceholder(a) ? f3 : _curry2(function(_b, _c) { return fn(a, _b, _c); }); case 2: return _isPlaceholder(a) && _isPlaceholder(b) ? f3 : _isPlaceholder(a) ? _curry2(function(_a, _c) { return fn(_a, b, _c); }) : _isPlaceholder(b) ? _curry2(function(_b, _c) { return fn(a, _b, _c); }) : _curry1(function(_c) { return fn(a, b, _c); }); default: return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function(_a, _b) { return fn(_a, _b, c); }) : _isPlaceholder(a) && _isPlaceholder(c) ? _curry2(function(_a, _c) { return fn(_a, b, _c); }) : _isPlaceholder(b) && _isPlaceholder(c) ? _curry2(function(_b, _c) { return fn(a, _b, _c); }) : _isPlaceholder(a) ? _curry1(function(_a) { return fn(_a, b, c); }) : _isPlaceholder(b) ? _curry1(function(_b) { return fn(a, _b, c); }) : _isPlaceholder(c) ? _curry1(function(_c) { return fn(a, b, _c); }) : fn(a, b, c); } }; }; /** * Tests whether or not an object is an array. * * @private * @param {*} val The object to test. * @return {Boolean} `true` if `val` is an array, `false` otherwise. * @example * * _isArray([]); //=> true * _isArray(null); //=> false * _isArray({}); //=> false */ var _isArray = Array.isArray || function _isArray(val) { return (val != null && val.length >= 0 && Object.prototype.toString.call(val) === '[object Array]'); }; var _isString = function _isString(x) { return Object.prototype.toString.call(x) === '[object String]'; }; /** * Tests whether or not an object is similar to an array. * * @private * @category Type * @category List * @sig * -> Boolean * @param {*} x The object to test. * @return {Boolean} `true` if `x` has a numeric length property and extreme indices defined; `false` otherwise. * @example * * _isArrayLike([]); //=> true * _isArrayLike(true); //=> false * _isArrayLike({}); //=> false * _isArrayLike({length: 10}); //=> false * _isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true */ var _isArrayLike = _curry1(function isArrayLike(x) { if (_isArray(x)) { return true; } if (!x) { return false; } if (typeof x !== 'object') { return false; } if (_isString(x)) { return false; } if (x.nodeType === 1) { return !!x.length; } if (x.length === 0) { return true; } if (x.length > 0) { return x.hasOwnProperty(0) && x.hasOwnProperty(x.length - 1); } return false; }); var _xwrap = (function() { function XWrap(fn) { this.f = fn; } XWrap.prototype['@@transducer/init'] = function() { throw new Error('init not implemented on XWrap'); }; XWrap.prototype['@@transducer/result'] = function(acc) { return acc; }; XWrap.prototype['@@transducer/step'] = function(acc, x) { return this.f(acc, x); }; return function _xwrap(fn) { return new XWrap(fn); }; }()); var _arity = function _arity(n, fn) { /* eslint-disable no-unused-vars */ switch (n) { case 0: return function() { return fn.apply(this, arguments); }; case 1: return function(a0) { return fn.apply(this, arguments); }; case 2: return function(a0, a1) { return fn.apply(this, arguments); }; case 3: return function(a0, a1, a2) { return fn.apply(this, arguments); }; case 4: return function(a0, a1, a2, a3) { return fn.apply(this, arguments); }; case 5: return function(a0, a1, a2, a3, a4) { return fn.apply(this, arguments); }; case 6: return function(a0, a1, a2, a3, a4, a5) { return fn.apply(this, arguments); }; case 7: return function(a0, a1, a2, a3, a4, a5, a6) { return fn.apply(this, arguments); }; case 8: return function(a0, a1, a2, a3, a4, a5, a6, a7) { return fn.apply(this, arguments); }; case 9: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8) { return fn.apply(this, arguments); }; case 10: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { return fn.apply(this, arguments); }; default: throw new Error('First argument to _arity must be a non-negative integer no greater than ten'); } }; /** * Creates a function that is bound to a context. * Note: `R.bind` does not provide the additional argument-binding capabilities of * [Function.prototype.bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind). * * @func * @memberOf R * @since v0.6.0 * @category Function * @category Object * @sig (* -> *) -> {*} -> (* -> *) * @param {Function} fn The function to bind to context * @param {Object} thisObj The context to bind `fn` to * @return {Function} A function that will execute in the context of `thisObj`. * @see R.partial * @example * * var log = R.bind(console.log, console); * R.pipe(R.assoc('a', 2), R.tap(log), R.assoc('a', 3))({a: 1}); //=> {a: 3} * // logs {a: 2} * @symb R.bind(f, o)(a, b) = f.call(o, a, b) */ var bind = _curry2(function bind(fn, thisObj) { return _arity(fn.length, function() { return fn.apply(thisObj, arguments); }); }); var _reduce = (function() { function _arrayReduce(xf, acc, list) { var idx = 0; var len = list.length; while (idx < len) { acc = xf['@@transducer/step'](acc, list[idx]); if (acc && acc['@@transducer/reduced']) { acc = acc['@@transducer/value']; break; } idx += 1; } return xf['@@transducer/result'](acc); } function _iterableReduce(xf, acc, iter) { var step = iter.next(); while (!step.done) { acc = xf['@@transducer/step'](acc, step.value); if (acc && acc['@@transducer/reduced']) { acc = acc['@@transducer/value']; break; } step = iter.next(); } return xf['@@transducer/result'](acc); } function _methodReduce(xf, acc, obj, methodName) { return xf['@@transducer/result'](obj[methodName](bind(xf['@@transducer/step'], xf), acc)); } var symIterator = (typeof Symbol !== 'undefined') ? Symbol.iterator : '@@iterator'; return function _reduce(fn, acc, list) { if (typeof fn === 'function') { fn = _xwrap(fn); } if (_isArrayLike(list)) { return _arrayReduce(fn, acc, list); } if (typeof list['fantasy-land/reduce'] === 'function') { return _methodReduce(fn, acc, list, 'fantasy-land/reduce'); } if (list[symIterator] != null) { return _iterableReduce(fn, acc, list[symIterator]()); } if (typeof list.next === 'function') { return _iterableReduce(fn, acc, list); } if (typeof list.reduce === 'function') { return _methodReduce(fn, acc, list, 'reduce'); } throw new TypeError('reduce: list must be array or iterable'); }; }()); /** * Returns a single item by iterating through the list, successively calling * the iterator function and passing it an accumulator value and the current * value from the array, and then passing the result to the next call. * * The iterator function receives two values: *(acc, value)*. It may use * [`R.reduced`](#reduced) to shortcut the iteration. * * The arguments' order of [`reduceRight`](#reduceRight)'s iterator function * is *(value, acc)*. * * Note: `R.reduce` does not skip deleted or unassigned indices (sparse * arrays), unlike the native `Array.prototype.reduce` method. For more details * on this behavior, see: * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#Description * * Dispatches to the `reduce` method of the third argument, if present. When * doing so, it is up to the user to handle the [`R.reduced`](#reduced) * shortcuting, as this is not implemented by `reduce`. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig ((a, b) -> a) -> a -> [b] -> a * @param {Function} fn The iterator function. Receives two values, the accumulator and the * current element from the array. * @param {*} acc The accumulator value. * @param {Array} list The list to iterate over. * @return {*} The final, accumulated value. * @see R.reduced, R.addIndex, R.reduceRight * @example * * R.reduce(R.subtract, 0, [1, 2, 3, 4]) // => ((((0 - 1) - 2) - 3) - 4) = -10 * - -10 * / \ / \ * - 4 -6 4 * / \ / \ * - 3 ==> -3 3 * / \ / \ * - 2 -1 2 * / \ / \ * 0 1 0 1 * * @symb R.reduce(f, a, [b, c, d]) = f(f(f(a, b), c), d) */ var reduce = _curry3(_reduce); var _isArguments = (function() { var toString = Object.prototype.toString; return toString.call(arguments) === '[object Arguments]' ? function _isArguments(x) { return toString.call(x) === '[object Arguments]'; } : function _isArguments(x) { return _has('callee', x); }; }()); /** * Returns a list containing the names of all the enumerable own properties of * the supplied object. * Note that the order of the output array is not guaranteed to be consistent * across different JS platforms. * * @func * @memberOf R * @since v0.1.0 * @category Object * @sig {k: v} -> [k] * @param {Object} obj The object to extract properties from * @return {Array} An array of the object's own properties. * @see R.keysIn, R.values * @example * * R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c'] */ var keys = (function() { // cover IE < 9 keys issues var hasEnumBug = !({toString: null}).propertyIsEnumerable('toString'); var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString', 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; // Safari bug var hasArgsEnumBug = (function() { 'use strict'; return arguments.propertyIsEnumerable('length'); }()); var contains = function contains(list, item) { var idx = 0; while (idx < list.length) { if (list[idx] === item) { return true; } idx += 1; } return false; }; return typeof Object.keys === 'function' && !hasArgsEnumBug ? _curry1(function keys(obj) { return Object(obj) !== obj ? [] : Object.keys(obj); }) : _curry1(function keys(obj) { if (Object(obj) !== obj) { return []; } var prop, nIdx; var ks = []; var checkArgsLength = hasArgsEnumBug && _isArguments(obj); for (prop in obj) { if (_has(prop, obj) && (!checkArgsLength || prop !== 'length')) { ks[ks.length] = prop; } } if (hasEnumBug) { nIdx = nonEnumerableProps.length - 1; while (nIdx >= 0) { prop = nonEnumerableProps[nIdx]; if (_has(prop, obj) && !contains(ks, prop)) { ks[ks.length] = prop; } nIdx -= 1; } } return ks; }); }()); /** * An Object-specific version of [`map`](#map). The function is applied to three * arguments: *(value, key, obj)*. If only the value is significant, use * [`map`](#map) instead. * * @func * @memberOf R * @since v0.9.0 * @category Object * @sig ((*, String, Object) -> *) -> Object -> Object * @param {Function} fn * @param {Object} obj * @return {Object} * @see R.map * @example * * var values = { x: 1, y: 2, z: 3 }; * var prependKeyAndDouble = (num, key, obj) => key + (num * 2); * * R.mapObjIndexed(prependKeyAndDouble, values); //=> { x: 'x2', y: 'y4', z: 'z6' } */ var mapObjIndexed = _curry2(function mapObjIndexed(fn, obj) { return _reduce(function(acc, key) { acc[key] = fn(obj[key], key, obj); return acc; }, {}, keys(obj)); }); var _function$4 = function isFunction(arg) { return typeof arg === 'function'; }; var stamp$4 = function isStamp(arg) { return _function$4(arg) && _function$4(arg.compose); }; // More proper implementation would be // isDescriptor(obj) || isStamp(obj) // but there is no sense since stamp is function and function is object. var composable$2 = object$6; var descriptor = object$6; var plainObject$2 = function isPlainObject(value) { return Boolean(value) && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype; }; var is = { // Public API isStamp: stamp$4, isComposable: composable$2, isDescriptor: descriptor, // The below are private for @stamp. isFunction: _function$4, isObject: object$6, isPlainObject: plainObject$2, isArray: array$4, isString: string }; function argsToPropTypes(propTypes) { var reducer = function reducer(acc, name) { if (!is.isString(name)) { throw new ReferenceError('expected args prop types to be only string - ' + (typeof name === 'undefined' ? 'undefined' : _typeof(name)) + ' received'); } acc[name] = mixed({ name: name }); return acc; }; return reduce(reducer, {}, propTypes); } function checkObjPropTypes() { var propTypes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var mapper = function mapper(v, key) { if (is.isFunction(v) || is.isFunction(v.isValid)) { return is.isStamp(v) ? v() : v; } throw new ReferenceError('expected ' + key + ' prop type to be a function - ' + (typeof v === 'undefined' ? 'undefined' : _typeof(v)) + ' received'); }; return mapObjIndexed(mapper, propTypes); } var PropTypes = it.deepConf({ propTypeModel: {} }).statics({ propTypes: function propTypes() { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } if (args.length === 0) return; var firstArg = args[0]; var argsToProps = is.isObject(firstArg) ? checkObjPropTypes(firstArg) : argsToPropTypes(args); // deep merge all the pairs to the modelProps object return this.deepConf({ propTypeModel: argsToProps }); }, hasPropTypes: function hasPropTypes() { var propTypeModel = this.compose.deepConfiguration.propTypeModel; return Object.keys(propTypeModel).length > 0; } }).init(function () { var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var _ref = arguments[1]; var stamp = _ref.stamp; var propTypeModel = stamp.compose.deepConfiguration.propTypeModel; Object.keys(propTypeModel).forEach(function (key) { var propType = propTypeModel[key]; propType.isValid(props, key); }); }); var Action = it(PropTypes).conf({ actionType: ActionType() }).statics({ CONST: '', prefix: function prefix(_prefix) { if (!is.isString(_prefix)) { throw new ReferenceError('expected prefix type is string - received ' + (typeof _prefix === 'undefined' ? 'undefined' : _typeof(_prefix))); } return this.conf({ actionType: ActionType({ prefix: _prefix }) }); }, def: function def(name) { if (!is.isString(name)) { throw new ReferenceError('expected name type is string - received ' + (typeof name === 'undefined' ? 'undefined' : _typeof(name))); } var actionType = this.compose.configuration.actionType; return this.statics({ CONST: actionType.getType(name) }); } }).props({ type: '', payload: {} }).init(function (props, _ref) { var stamp = _ref.stamp, instance = _ref.instance; var CONST = stamp.compose.staticProperties.CONST; if (CONST.length === 0) { throw new Error('action has not name definition - use Action.def to init it'); } instance.type = CONST; instance.payload = props; }); var _arrayFromIterator = function _arrayFromIterator(iter) { var list = []; var next; while (!(next = iter.next()).done) { list.push(next.value); } return list; }; var _functionName = function _functionName(f) { // String(x => x) evaluates to "x => x", so the pattern may not match. var match = String(f).match(/^function (\w*)/); return match == null ? '' : match[1]; }; /** * Returns true if its arguments are identical, false otherwise. Values are * identical if they reference the same memory. `NaN` is identical to `NaN`; * `0` and `-0` are not identical. * * @func * @memberOf R * @since v0.15.0 * @category Relation * @sig a -> a -> Boolean * @param {*} a * @param {*} b * @return {Boolean} * @example * * var o = {}; * R.identical(o, o); //=> true * R.identical(1, 1); //=> true * R.identical(1, '1'); //=> false * R.identical([], []); //=> false * R.identical(0, -0); //=> false * R.identical(NaN, NaN); //=> true */ var identical = _curry2(function identical(a, b) { // SameValue algorithm if (a === b) { // Steps 1-5, 7-10 // Steps 6.b-6.e: +0 != -0 return a !== 0 || 1 / a === 1 / b; } else { // Step 6.a: NaN == NaN return a !== a && b !== b; } }); /** * Gives a single-word string description of the (native) type of a value, * returning such answers as 'Object', 'Number', 'Array', or 'Null'. Does not * attempt to distinguish user Object types any further, reporting them all as * 'Object'. * * @func * @memberOf R * @since v0.8.0 * @category Type * @sig (* -> {*}) -> String * @param {*} val The value to test * @return {String} * @example * * R.type({}); //=> "Object" * R.type(1); //=> "Number" * R.type(false); //=> "Boolean" * R.type('s'); //=> "String" * R.type(null); //=> "Null" * R.type([]); //=> "Array" * R.type(/[A-z]/); //=> "RegExp" * R.type(() => {}); //=> "Function" */ var type = _curry1(function type(val) { return val === null ? 'Null' : val === undefined ? 'Undefined' : Object.prototype.toString.call(val).slice(8, -1); }); var _equals = function _equals(a, b, stackA, stackB) { if (identical(a, b)) { return true; } if (type(a) !== type(b)) { return false; } if (a == null || b == null) { return false; } if (typeof a['fantasy-land/equals'] === 'function' || typeof b['fantasy-land/equals'] === 'function') { return typeof a['fantasy-land/equals'] === 'function' && a['fantasy-land/equals'](b) && typeof b['fantasy-land/equals'] === 'function' && b['fantasy-land/equals'](a); } if (typeof a.equals === 'function' || typeof b.equals === 'function') { return typeof a.equals === 'function' && a.equals(b) && typeof b.equals === 'function' && b.equals(a); } switch (type(a)) { case 'Arguments': case 'Array': case 'Object': if (typeof a.constructor === 'function' && _functionName(a.constructor) === 'Promise') { return a === b; } break; case 'Boolean': case 'Number': case 'String': if (!(typeof a === typeof b && identical(a.valueOf(), b.valueOf()))) { return false; } break; case 'Date': if (!identical(a.valueOf(), b.valueOf())) { return false; } break; case 'Error': return a.name === b.name && a.message === b.message; case 'RegExp': if (!(a.source === b.source && a.global === b.global && a.ignoreCase === b.ignoreCase && a.multiline === b.multiline && a.sticky === b.sticky && a.unicode === b.unicode)) { return false; } break; case 'Map': case 'Set': if (!_equals(_arrayFromIterator(a.entries()), _arrayFromIterator(b.entries()), stackA, stackB)) { return false; } break; case 'Int8Array': case 'Uint8Array': case 'Uint8ClampedArray': case 'Int16Array': case 'Uint16Array': case 'Int32Array': case 'Uint32Array': case 'Float32Array': case 'Float64Array': break; case 'ArrayBuffer': break; default: // Values of other types are only equal if identical. return false; } var keysA = keys(a); if (keysA.length !== keys(b).length) { return false; } var idx = stackA.length - 1; while (idx >= 0) { if (stackA[idx] === a) { return stackB[idx] === b; } idx -= 1; } stackA.push(a); stackB.push(b); idx = keysA.length - 1; while (idx >= 0) { var key = keysA[idx]; if (!(_has(key, b) && _equals(b[key], a[key], stackA, stackB))) { return false; } idx -= 1; } stackA.pop(); stackB.pop(); return true; }; /** * Returns `true` if its arguments are equivalent, `false` otherwise. Handles * cyclical data structures. * * Dispatches symmetrically to the `equals` methods of both arguments, if * present. * * @func * @memberOf R * @since v0.15.0 * @category Relation * @sig a -> b -> Boolean * @param {*} a * @param {*} b * @return {Boolean} * @example * * R.equals(1, 1); //=> true * R.equals(1, '1'); //=> false * R.equals([1, 2, 3], [1, 2, 3]); //=> true * * var a = {}; a.v = a; * var b = {}; b.v = b; * R.equals(a, b); //=> true */ var equals = _curry2(function equals(a, b) { return _equals(a, b, [], []); }); /** * Returns `true` if the specified object property is equal, in * [`R.equals`](#equals) terms, to the given value; `false` otherwise. * * @func * @memberOf R * @since v0.1.0 * @category Relation * @sig String -> a -> Object -> Boolean * @param {String} name * @param {*} val * @param {*} obj * @return {Boolean} * @see R.equals, R.propSatisfies * @example * * var abby = {name: 'Abby', age: 7, hair: 'blond'}; * var fred = {name: 'Fred', age: 12, hair: 'brown'}; * var rusty = {name: 'Rusty', age: 10, hair: 'brown'}; * var alois = {name: 'Alois', age: 15, disposition: 'surly'}; * var kids = [abby, fred, rusty, alois]; * var hasBrownHair = R.propEq('hair', 'brown'); * R.filter(hasBrownHair, kids); //=> [fred, rusty] */ var propEq = _curry3(function propEq(name, val, obj) { return equals(val, obj[name]); }); var _isTransformer = function _isTransformer(obj) { return typeof obj['@@transducer/step'] === 'function'; }; /** * Returns a function that dispatches with different strategies based on the * object in list position (last argument). If it is an array, executes [fn]. * Otherwise, if it has a function with one of the given method names, it will * execute that function (functor case). Otherwise, if it is a transformer, * uses transducer [xf] to return a new transformer (transducer case). * Otherwise, it will default to executing [fn]. * * @private * @param {Array} methodNames properties to check for a custom implementation * @param {Function} xf transducer to initialize if object is transformer * @param {Function} fn default ramda implementation * @return {Function} A function that dispatches on object in list position */ var _dispatchable = function _dispatchable(methodNames, xf, fn) { return function() { if (arguments.length === 0) { return fn(); } var args = Array.prototype.slice.call(arguments, 0); var obj = args.pop(); if (!_isArray(obj)) { var idx = 0; while (idx < methodNames.length) { if (typeof obj[methodNames[idx]] === 'function') { return obj[methodNames[idx]].apply(obj, args); } idx += 1; } if (_isTransformer(obj)) { var transducer = xf.apply(null, args); return transducer(obj); } } return fn.apply(this, arguments); }; }; var _reduced = function _reduced(x) { return x && x['@@transducer/reduced'] ? x : { '@@transducer/value': x, '@@transducer/reduced': true }; }; var _xfBase = { init: function() { return this.xf['@@transducer/init'](); }, result: function(result) { return this.xf['@@transducer/result'](result); } }; var _xfind = (function() { function XFind(f, xf) { this.xf = xf; this.f = f; this.found = false; } XFind.prototype['@@transducer/init'] = _xfBase.init; XFind.prototype['@@transducer/result'] = function(result) { if (!this.found) { result = this.xf['@@transducer/step'](result, void 0); } return this.xf['@@transducer/result'](result); }; XFind.prototype['@@transducer/step'] = function(result, input) { if (this.f(input)) { this.found = true; result = _reduced(this.xf['@@transducer/step'](result, input)); } return result; }; return _curry2(function _xfind(f, xf) { return new XFind(f, xf); }); }()); /** * Returns the first element of the list which matches the predicate, or * `undefined` if no element matches. * * Dispatches to the `find` method of the second argument, if present. * * Acts as a transducer if a transformer is given in list position. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig (a -> Boolean) -> [a] -> a | undefined * @param {Function} fn The predicate function used to determine if the element is the * desired one. * @param {Array} list