obzervable
Advanced tools
Comparing version 0.1.3 to 0.1.4
1407
dist/index.js
@@ -10,21 +10,5 @@ 'use strict'; | ||
var lodash_clonedeep = createCommonjsModule(function (module, exports) { | ||
/** | ||
* lodash (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modularize exports="npm" -o ./` | ||
* Copyright jQuery Foundation and other contributors <https://jquery.org/> | ||
* Released under MIT license <https://lodash.com/license> | ||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | ||
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
*/ | ||
/** Used as the size to enable large array optimizations. */ | ||
var LARGE_ARRAY_SIZE = 200; | ||
/** Used to stand-in for `undefined` hash values. */ | ||
var HASH_UNDEFINED = '__lodash_hash_undefined__'; | ||
/** Used as references for various `Number` constants. */ | ||
var MAX_SAFE_INTEGER = 9007199254740991; | ||
/** `Object#toString` result references. */ | ||
var argsTag = '[object Arguments]', | ||
@@ -57,84 +41,26 @@ arrayTag = '[object Array]', | ||
uint32Tag = '[object Uint32Array]'; | ||
/** | ||
* Used to match `RegExp` | ||
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). | ||
*/ | ||
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; | ||
/** Used to match `RegExp` flags from their coerced string values. */ | ||
var reFlags = /\w*$/; | ||
/** Used to detect host constructors (Safari). */ | ||
var reIsHostCtor = /^\[object .+?Constructor\]$/; | ||
/** Used to detect unsigned integer values. */ | ||
var reIsUint = /^(?:0|[1-9]\d*)$/; | ||
/** Used to identify `toStringTag` values supported by `_.clone`. */ | ||
var cloneableTags = {}; | ||
cloneableTags[argsTag] = cloneableTags[arrayTag] = cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = cloneableTags[boolTag] = cloneableTags[dateTag] = cloneableTags[float32Tag] = cloneableTags[float64Tag] = cloneableTags[int8Tag] = cloneableTags[int16Tag] = cloneableTags[int32Tag] = cloneableTags[mapTag] = cloneableTags[numberTag] = cloneableTags[objectTag] = cloneableTags[regexpTag] = cloneableTags[setTag] = cloneableTags[stringTag] = cloneableTags[symbolTag] = cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true; | ||
cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[weakMapTag] = false; | ||
/** Detect free variable `global` from Node.js. */ | ||
var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; | ||
/** Detect free variable `self`. */ | ||
var freeSelf = typeof self == 'object' && self && self.Object === Object && self; | ||
/** Used as a reference to the global object. */ | ||
var root = freeGlobal || freeSelf || Function('return this')(); | ||
/** Detect free variable `exports`. */ | ||
var freeExports = exports && !exports.nodeType && exports; | ||
/** Detect free variable `module`. */ | ||
var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module; | ||
/** Detect the popular CommonJS extension `module.exports`. */ | ||
var moduleExports = freeModule && freeModule.exports === freeExports; | ||
/** | ||
* Adds the key-value `pair` to `map`. | ||
* | ||
* @private | ||
* @param {Object} map The map to modify. | ||
* @param {Array} pair The key-value pair to add. | ||
* @returns {Object} Returns `map`. | ||
*/ | ||
function addMapEntry(map, pair) { | ||
// Don't return `map.set` because it's not chainable in IE 11. | ||
map.set(pair[0], pair[1]); | ||
return map; | ||
} | ||
/** | ||
* Adds `value` to `set`. | ||
* | ||
* @private | ||
* @param {Object} set The set to modify. | ||
* @param {*} value The value to add. | ||
* @returns {Object} Returns `set`. | ||
*/ | ||
function addSetEntry(set, value) { | ||
// Don't return `set.add` because it's not chainable in IE 11. | ||
set.add(value); | ||
return set; | ||
} | ||
/** | ||
* A specialized version of `_.forEach` for arrays without support for | ||
* iteratee shorthands. | ||
* | ||
* @private | ||
* @param {Array} [array] The array to iterate over. | ||
* @param {Function} iteratee The function invoked per iteration. | ||
* @returns {Array} Returns `array`. | ||
*/ | ||
function arrayEach(array, iteratee) { | ||
var index = -1, | ||
length = array ? array.length : 0; | ||
while (++index < length) { | ||
@@ -145,15 +71,4 @@ if (iteratee(array[index], index, array) === false) { | ||
} | ||
return array; | ||
} | ||
/** | ||
* Appends the elements of `values` to `array`. | ||
* | ||
* @private | ||
* @param {Array} array The array to modify. | ||
* @param {Array} values The values to append. | ||
* @returns {Array} Returns `array`. | ||
*/ | ||
function arrayPush(array, values) { | ||
@@ -163,85 +78,31 @@ var index = -1, | ||
offset = array.length; | ||
while (++index < length) { | ||
array[offset + index] = values[index]; | ||
} | ||
return array; | ||
} | ||
/** | ||
* A specialized version of `_.reduce` for arrays without support for | ||
* iteratee shorthands. | ||
* | ||
* @private | ||
* @param {Array} [array] The array to iterate over. | ||
* @param {Function} iteratee The function invoked per iteration. | ||
* @param {*} [accumulator] The initial value. | ||
* @param {boolean} [initAccum] Specify using the first element of `array` as | ||
* the initial value. | ||
* @returns {*} Returns the accumulated value. | ||
*/ | ||
function arrayReduce(array, iteratee, accumulator, initAccum) { | ||
var index = -1, | ||
length = array ? array.length : 0; | ||
if (initAccum && length) { | ||
accumulator = array[++index]; | ||
} | ||
while (++index < length) { | ||
accumulator = iteratee(accumulator, array[index], index, array); | ||
} | ||
return accumulator; | ||
} | ||
/** | ||
* The base implementation of `_.times` without support for iteratee shorthands | ||
* or max array length checks. | ||
* | ||
* @private | ||
* @param {number} n The number of times to invoke `iteratee`. | ||
* @param {Function} iteratee The function invoked per iteration. | ||
* @returns {Array} Returns the array of results. | ||
*/ | ||
function baseTimes(n, iteratee) { | ||
var index = -1, | ||
result = Array(n); | ||
while (++index < n) { | ||
result[index] = iteratee(index); | ||
} | ||
return result; | ||
} | ||
/** | ||
* Gets the value at `key` of `object`. | ||
* | ||
* @private | ||
* @param {Object} [object] The object to query. | ||
* @param {string} key The key of the property to get. | ||
* @returns {*} Returns the property value. | ||
*/ | ||
function getValue(object, key) { | ||
return object == null ? undefined : object[key]; | ||
} | ||
/** | ||
* Checks if `value` is a host object in IE < 9. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a host object, else `false`. | ||
*/ | ||
function isHostObject(value) { | ||
// Many host objects are `Object` objects that can coerce to strings | ||
// despite having improperly defined `toString` methods. | ||
var result = false; | ||
if (value != null && typeof value.toString != 'function') { | ||
@@ -252,14 +113,4 @@ try { | ||
} | ||
return result; | ||
} | ||
/** | ||
* Converts `map` to its key-value pairs. | ||
* | ||
* @private | ||
* @param {Object} map The map to convert. | ||
* @returns {Array} Returns the key-value pairs. | ||
*/ | ||
function mapToArray(map) { | ||
@@ -273,12 +124,2 @@ var index = -1, | ||
} | ||
/** | ||
* Creates a unary function that invokes `func` with its argument transformed. | ||
* | ||
* @private | ||
* @param {Function} func The function to wrap. | ||
* @param {Function} transform The argument transform. | ||
* @returns {Function} Returns the new function. | ||
*/ | ||
function overArg(func, transform) { | ||
@@ -289,11 +130,2 @@ return function (arg) { | ||
} | ||
/** | ||
* Converts `set` to an array of its values. | ||
* | ||
* @private | ||
* @param {Object} set The set to convert. | ||
* @returns {Array} Returns the values. | ||
*/ | ||
function setToArray(set) { | ||
@@ -307,13 +139,6 @@ var index = -1, | ||
} | ||
/** Used for built-in method references. */ | ||
var arrayProto = Array.prototype, | ||
funcProto = Function.prototype, | ||
objectProto = Object.prototype; | ||
/** Used to detect overreaching core-js shims. */ | ||
var coreJsData = root['__core-js_shared__']; | ||
/** Used to detect methods masquerading as native. */ | ||
var maskSrcKey = function () { | ||
@@ -323,21 +148,6 @@ var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); | ||
}(); | ||
/** Used to resolve the decompiled source of functions. */ | ||
var funcToString = funcProto.toString; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty = objectProto.hasOwnProperty; | ||
/** | ||
* Used to resolve the | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var objectToString = objectProto.toString; | ||
/** Used to detect if a method is native. */ | ||
var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'); | ||
/** Built-in value references. */ | ||
var Buffer = moduleExports ? root.Buffer : undefined, | ||
@@ -350,9 +160,5 @@ Symbol = root.Symbol, | ||
splice = arrayProto.splice; | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeGetSymbols = Object.getOwnPropertySymbols, | ||
nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined, | ||
nativeKeys = overArg(Object.keys, Object); | ||
/* Built-in method references that are verified to be native. */ | ||
var DataView = getNative(root, 'DataView'), | ||
@@ -364,4 +170,2 @@ Map = getNative(root, 'Map'), | ||
nativeCreate = getNative(Object, 'create'); | ||
/** Used to detect maps, sets, and weakmaps. */ | ||
var dataViewCtorString = toSource(DataView), | ||
@@ -372,14 +176,4 @@ mapCtorString = toSource(Map), | ||
weakMapCtorString = toSource(WeakMap); | ||
/** Used to convert symbols to primitives and strings. */ | ||
var symbolProto = Symbol ? Symbol.prototype : undefined, | ||
symbolValueOf = symbolProto ? symbolProto.valueOf : undefined; | ||
/** | ||
* Creates a hash object. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function Hash(entries) { | ||
@@ -389,3 +183,2 @@ var index = -1, | ||
this.clear(); | ||
while (++index < length) { | ||
@@ -396,43 +189,10 @@ var entry = entries[index]; | ||
} | ||
/** | ||
* Removes all key-value entries from the hash. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf Hash | ||
*/ | ||
function hashClear() { | ||
this.__data__ = nativeCreate ? nativeCreate(null) : {}; | ||
} | ||
/** | ||
* Removes `key` and its value from the hash. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf Hash | ||
* @param {Object} hash The hash to modify. | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function hashDelete(key) { | ||
return this.has(key) && delete this.__data__[key]; | ||
} | ||
/** | ||
* Gets the hash value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf Hash | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function hashGet(key) { | ||
var data = this.__data__; | ||
if (nativeCreate) { | ||
@@ -442,16 +202,4 @@ var result = data[key]; | ||
} | ||
return hasOwnProperty.call(data, key) ? data[key] : undefined; | ||
} | ||
/** | ||
* Checks if a hash value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf Hash | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function hashHas(key) { | ||
@@ -461,14 +209,2 @@ var data = this.__data__; | ||
} | ||
/** | ||
* Sets the hash `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf Hash | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the hash instance. | ||
*/ | ||
function hashSet(key, value) { | ||
@@ -478,5 +214,3 @@ var data = this.__data__; | ||
return this; | ||
} // Add methods to `Hash`. | ||
} | ||
Hash.prototype.clear = hashClear; | ||
@@ -487,10 +221,2 @@ Hash.prototype['delete'] = hashDelete; | ||
Hash.prototype.set = hashSet; | ||
/** | ||
* Creates an list cache object. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function ListCache(entries) { | ||
@@ -500,3 +226,2 @@ var index = -1, | ||
this.clear(); | ||
while (++index < length) { | ||
@@ -507,35 +232,12 @@ var entry = entries[index]; | ||
} | ||
/** | ||
* Removes all key-value entries from the list cache. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf ListCache | ||
*/ | ||
function listCacheClear() { | ||
this.__data__ = []; | ||
} | ||
/** | ||
* Removes `key` and its value from the list cache. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf ListCache | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function listCacheDelete(key) { | ||
var data = this.__data__, | ||
index = assocIndexOf(data, key); | ||
if (index < 0) { | ||
return false; | ||
} | ||
var lastIndex = data.length - 1; | ||
if (index == lastIndex) { | ||
@@ -546,16 +248,4 @@ data.pop(); | ||
} | ||
return true; | ||
} | ||
/** | ||
* Gets the list cache value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf ListCache | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function listCacheGet(key) { | ||
@@ -566,32 +256,8 @@ var data = this.__data__, | ||
} | ||
/** | ||
* Checks if a list cache value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf ListCache | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function listCacheHas(key) { | ||
return assocIndexOf(this.__data__, key) > -1; | ||
} | ||
/** | ||
* Sets the list cache `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf ListCache | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the list cache instance. | ||
*/ | ||
function listCacheSet(key, value) { | ||
var data = this.__data__, | ||
index = assocIndexOf(data, key); | ||
if (index < 0) { | ||
@@ -602,7 +268,4 @@ data.push([key, value]); | ||
} | ||
return this; | ||
} // Add methods to `ListCache`. | ||
} | ||
ListCache.prototype.clear = listCacheClear; | ||
@@ -613,10 +276,2 @@ ListCache.prototype['delete'] = listCacheDelete; | ||
ListCache.prototype.set = listCacheSet; | ||
/** | ||
* Creates a map cache object to store key-value pairs. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function MapCache(entries) { | ||
@@ -626,3 +281,2 @@ var index = -1, | ||
this.clear(); | ||
while (++index < length) { | ||
@@ -633,11 +287,2 @@ var entry = entries[index]; | ||
} | ||
/** | ||
* Removes all key-value entries from the map. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf MapCache | ||
*/ | ||
function mapCacheClear() { | ||
@@ -650,62 +295,15 @@ this.__data__ = { | ||
} | ||
/** | ||
* Removes `key` and its value from the map. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf MapCache | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function mapCacheDelete(key) { | ||
return getMapData(this, key)['delete'](key); | ||
} | ||
/** | ||
* Gets the map value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf MapCache | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function mapCacheGet(key) { | ||
return getMapData(this, key).get(key); | ||
} | ||
/** | ||
* Checks if a map value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf MapCache | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function mapCacheHas(key) { | ||
return getMapData(this, key).has(key); | ||
} | ||
/** | ||
* Sets the map `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf MapCache | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the map cache instance. | ||
*/ | ||
function mapCacheSet(key, value) { | ||
getMapData(this, key).set(key, value); | ||
return this; | ||
} // Add methods to `MapCache`. | ||
} | ||
MapCache.prototype.clear = mapCacheClear; | ||
@@ -716,85 +314,21 @@ MapCache.prototype['delete'] = mapCacheDelete; | ||
MapCache.prototype.set = mapCacheSet; | ||
/** | ||
* Creates a stack cache object to store key-value pairs. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function Stack(entries) { | ||
this.__data__ = new ListCache(entries); | ||
} | ||
/** | ||
* Removes all key-value entries from the stack. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf Stack | ||
*/ | ||
function stackClear() { | ||
this.__data__ = new ListCache(); | ||
} | ||
/** | ||
* Removes `key` and its value from the stack. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf Stack | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function stackDelete(key) { | ||
return this.__data__['delete'](key); | ||
} | ||
/** | ||
* Gets the stack value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf Stack | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function stackGet(key) { | ||
return this.__data__.get(key); | ||
} | ||
/** | ||
* Checks if a stack value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf Stack | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function stackHas(key) { | ||
return this.__data__.has(key); | ||
} | ||
/** | ||
* Sets the stack `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf Stack | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the stack cache instance. | ||
*/ | ||
function stackSet(key, value) { | ||
var cache = this.__data__; | ||
if (cache instanceof ListCache) { | ||
var pairs = cache.__data__; | ||
if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) { | ||
@@ -804,11 +338,7 @@ pairs.push([key, value]); | ||
} | ||
cache = this.__data__ = new MapCache(pairs); | ||
} | ||
cache.set(key, value); | ||
return this; | ||
} // Add methods to `Stack`. | ||
} | ||
Stack.prototype.clear = stackClear; | ||
@@ -819,18 +349,6 @@ Stack.prototype['delete'] = stackDelete; | ||
Stack.prototype.set = stackSet; | ||
/** | ||
* Creates an array of the enumerable property names of the array-like `value`. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @param {boolean} inherited Specify returning inherited property names. | ||
* @returns {Array} Returns the array of property names. | ||
*/ | ||
function arrayLikeKeys(value, inherited) { | ||
// Safari 8.1 makes `arguments.callee` enumerable in strict mode. | ||
// Safari 9 makes `arguments.length` enumerable in strict mode. | ||
var result = isArray(value) || isArguments(value) ? baseTimes(value.length, String) : []; | ||
var length = result.length, | ||
skipIndexes = !!length; | ||
for (var key in value) { | ||
@@ -841,20 +359,6 @@ if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && (key == 'length' || isIndex(key, length)))) { | ||
} | ||
return result; | ||
} | ||
/** | ||
* Assigns `value` to `key` of `object` if the existing value is not equivalent | ||
* using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) | ||
* for equality comparisons. | ||
* | ||
* @private | ||
* @param {Object} object The object to modify. | ||
* @param {string} key The key of the property to assign. | ||
* @param {*} value The value to assign. | ||
*/ | ||
function assignValue(object, key, value) { | ||
var objValue = object[key]; | ||
if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || value === undefined && !(key in object)) { | ||
@@ -864,15 +368,4 @@ object[key] = value; | ||
} | ||
/** | ||
* Gets the index at which the `key` is found in `array` of key-value pairs. | ||
* | ||
* @private | ||
* @param {Array} array The array to inspect. | ||
* @param {*} key The key to search for. | ||
* @returns {number} Returns the index of the matched value, else `-1`. | ||
*/ | ||
function assocIndexOf(array, key) { | ||
var length = array.length; | ||
while (length--) { | ||
@@ -883,55 +376,21 @@ if (eq(array[length][0], key)) { | ||
} | ||
return -1; | ||
} | ||
/** | ||
* The base implementation of `_.assign` without support for multiple sources | ||
* or `customizer` functions. | ||
* | ||
* @private | ||
* @param {Object} object The destination object. | ||
* @param {Object} source The source object. | ||
* @returns {Object} Returns `object`. | ||
*/ | ||
function baseAssign(object, source) { | ||
return object && copyObject(source, keys(source), object); | ||
} | ||
/** | ||
* The base implementation of `_.clone` and `_.cloneDeep` which tracks | ||
* traversed objects. | ||
* | ||
* @private | ||
* @param {*} value The value to clone. | ||
* @param {boolean} [isDeep] Specify a deep clone. | ||
* @param {boolean} [isFull] Specify a clone including symbols. | ||
* @param {Function} [customizer] The function to customize cloning. | ||
* @param {string} [key] The key of `value`. | ||
* @param {Object} [object] The parent object of `value`. | ||
* @param {Object} [stack] Tracks traversed objects and their clone counterparts. | ||
* @returns {*} Returns the cloned value. | ||
*/ | ||
function baseClone(value, isDeep, isFull, customizer, key, object, stack) { | ||
var result; | ||
if (customizer) { | ||
result = object ? customizer(value, key, object, stack) : customizer(value); | ||
} | ||
if (result !== undefined) { | ||
return result; | ||
} | ||
if (!isObject(value)) { | ||
return value; | ||
} | ||
var isArr = isArray(value); | ||
if (isArr) { | ||
result = initCloneArray(value); | ||
if (!isDeep) { | ||
@@ -943,7 +402,5 @@ return copyArray(value, result); | ||
isFunc = tag == funcTag || tag == genTag; | ||
if (isBuffer(value)) { | ||
return cloneBuffer(value, isDeep); | ||
} | ||
if (tag == objectTag || tag == argsTag || isFunc && !object) { | ||
@@ -953,5 +410,3 @@ if (isHostObject(value)) { | ||
} | ||
result = initCloneObject(isFunc ? {} : value); | ||
if (!isDeep) { | ||
@@ -964,21 +419,14 @@ return copySymbols(value, baseAssign(result, value)); | ||
} | ||
result = initCloneByTag(value, tag, baseClone, isDeep); | ||
} | ||
} // Check for circular references and return its corresponding clone. | ||
} | ||
stack || (stack = new Stack()); | ||
var stacked = stack.get(value); | ||
if (stacked) { | ||
return stacked; | ||
} | ||
stack.set(value, result); | ||
if (!isArr) { | ||
var props = isFull ? getAllKeys(value) : keys(value); | ||
} | ||
arrayEach(props || value, function (subValue, key) { | ||
@@ -988,5 +436,3 @@ if (props) { | ||
subValue = value[key]; | ||
} // Recursively populate clone (susceptible to call stack limits). | ||
} | ||
assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack)); | ||
@@ -996,28 +442,5 @@ }); | ||
} | ||
/** | ||
* The base implementation of `_.create` without support for assigning | ||
* properties to the created object. | ||
* | ||
* @private | ||
* @param {Object} prototype The object to inherit from. | ||
* @returns {Object} Returns the new object. | ||
*/ | ||
function baseCreate(proto) { | ||
return isObject(proto) ? objectCreate(proto) : {}; | ||
} | ||
/** | ||
* The base implementation of `getAllKeys` and `getAllKeysIn` which uses | ||
* `keysFunc` and `symbolsFunc` to get the enumerable property names and | ||
* symbols of `object`. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @param {Function} keysFunc The function to get the keys of `object`. | ||
* @param {Function} symbolsFunc The function to get the symbols of `object`. | ||
* @returns {Array} Returns the array of property names and symbols. | ||
*/ | ||
function baseGetAllKeys(object, keysFunc, symbolsFunc) { | ||
@@ -1027,24 +450,5 @@ var result = keysFunc(object); | ||
} | ||
/** | ||
* The base implementation of `getTag`. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {string} Returns the `toStringTag`. | ||
*/ | ||
function baseGetTag(value) { | ||
return objectToString.call(value); | ||
} | ||
/** | ||
* The base implementation of `_.isNative` without bad shim checks. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a native function, | ||
* else `false`. | ||
*/ | ||
function baseIsNative(value) { | ||
@@ -1054,15 +458,5 @@ if (!isObject(value) || isMasked(value)) { | ||
} | ||
var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor; | ||
return pattern.test(toSource(value)); | ||
} | ||
/** | ||
* The base implementation of `_.keys` which doesn't treat sparse arrays as dense. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @returns {Array} Returns the array of property names. | ||
*/ | ||
function baseKeys(object) { | ||
@@ -1072,5 +466,3 @@ if (!isPrototype(object)) { | ||
} | ||
var result = []; | ||
for (var key in Object(object)) { | ||
@@ -1081,15 +473,4 @@ if (hasOwnProperty.call(object, key) && key != 'constructor') { | ||
} | ||
return result; | ||
} | ||
/** | ||
* Creates a clone of `buffer`. | ||
* | ||
* @private | ||
* @param {Buffer} buffer The buffer to clone. | ||
* @param {boolean} [isDeep] Specify a deep clone. | ||
* @returns {Buffer} Returns the cloned buffer. | ||
*/ | ||
function cloneBuffer(buffer, isDeep) { | ||
@@ -1099,3 +480,2 @@ if (isDeep) { | ||
} | ||
var result = new buffer.constructor(buffer.length); | ||
@@ -1105,11 +485,2 @@ buffer.copy(result); | ||
} | ||
/** | ||
* Creates a clone of `arrayBuffer`. | ||
* | ||
* @private | ||
* @param {ArrayBuffer} arrayBuffer The array buffer to clone. | ||
* @returns {ArrayBuffer} Returns the cloned array buffer. | ||
*/ | ||
function cloneArrayBuffer(arrayBuffer) { | ||
@@ -1120,12 +491,2 @@ var result = new arrayBuffer.constructor(arrayBuffer.byteLength); | ||
} | ||
/** | ||
* Creates a clone of `dataView`. | ||
* | ||
* @private | ||
* @param {Object} dataView The data view to clone. | ||
* @param {boolean} [isDeep] Specify a deep clone. | ||
* @returns {Object} Returns the cloned data view. | ||
*/ | ||
function cloneDataView(dataView, isDeep) { | ||
@@ -1135,13 +496,2 @@ var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer; | ||
} | ||
/** | ||
* Creates a clone of `map`. | ||
* | ||
* @private | ||
* @param {Object} map The map to clone. | ||
* @param {Function} cloneFunc The function to clone values. | ||
* @param {boolean} [isDeep] Specify a deep clone. | ||
* @returns {Object} Returns the cloned map. | ||
*/ | ||
function cloneMap(map, isDeep, cloneFunc) { | ||
@@ -1151,11 +501,2 @@ var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map); | ||
} | ||
/** | ||
* Creates a clone of `regexp`. | ||
* | ||
* @private | ||
* @param {Object} regexp The regexp to clone. | ||
* @returns {Object} Returns the cloned regexp. | ||
*/ | ||
function cloneRegExp(regexp) { | ||
@@ -1166,13 +507,2 @@ var result = new regexp.constructor(regexp.source, reFlags.exec(regexp)); | ||
} | ||
/** | ||
* Creates a clone of `set`. | ||
* | ||
* @private | ||
* @param {Object} set The set to clone. | ||
* @param {Function} cloneFunc The function to clone values. | ||
* @param {boolean} [isDeep] Specify a deep clone. | ||
* @returns {Object} Returns the cloned set. | ||
*/ | ||
function cloneSet(set, isDeep, cloneFunc) { | ||
@@ -1182,24 +512,5 @@ var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set); | ||
} | ||
/** | ||
* Creates a clone of the `symbol` object. | ||
* | ||
* @private | ||
* @param {Object} symbol The symbol object to clone. | ||
* @returns {Object} Returns the cloned symbol object. | ||
*/ | ||
function cloneSymbol(symbol) { | ||
return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {}; | ||
} | ||
/** | ||
* Creates a clone of `typedArray`. | ||
* | ||
* @private | ||
* @param {Object} typedArray The typed array to clone. | ||
* @param {boolean} [isDeep] Specify a deep clone. | ||
* @returns {Object} Returns the cloned typed array. | ||
*/ | ||
function cloneTypedArray(typedArray, isDeep) { | ||
@@ -1209,12 +520,2 @@ var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer; | ||
} | ||
/** | ||
* Copies the values of `source` to `array`. | ||
* | ||
* @private | ||
* @param {Array} source The array to copy values from. | ||
* @param {Array} [array=[]] The array to copy values to. | ||
* @returns {Array} Returns `array`. | ||
*/ | ||
function copyArray(source, array) { | ||
@@ -1224,21 +525,7 @@ var index = -1, | ||
array || (array = Array(length)); | ||
while (++index < length) { | ||
array[index] = source[index]; | ||
} | ||
return array; | ||
} | ||
/** | ||
* Copies properties of `source` to `object`. | ||
* | ||
* @private | ||
* @param {Object} source The object to copy properties from. | ||
* @param {Array} props The property identifiers to copy. | ||
* @param {Object} [object={}] The object to copy properties to. | ||
* @param {Function} [customizer] The function to customize copied values. | ||
* @returns {Object} Returns `object`. | ||
*/ | ||
function copyObject(source, props, object, customizer) { | ||
@@ -1248,3 +535,2 @@ object || (object = {}); | ||
length = props.length; | ||
while (++index < length) { | ||
@@ -1255,40 +541,10 @@ var key = props[index]; | ||
} | ||
return object; | ||
} | ||
/** | ||
* Copies own symbol properties of `source` to `object`. | ||
* | ||
* @private | ||
* @param {Object} source The object to copy symbols from. | ||
* @param {Object} [object={}] The object to copy symbols to. | ||
* @returns {Object} Returns `object`. | ||
*/ | ||
function copySymbols(source, object) { | ||
return copyObject(source, getSymbols(source), object); | ||
} | ||
/** | ||
* Creates an array of own enumerable property names and symbols of `object`. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @returns {Array} Returns the array of property names and symbols. | ||
*/ | ||
function getAllKeys(object) { | ||
return baseGetAllKeys(object, keys, getSymbols); | ||
} | ||
/** | ||
* Gets the data for `map`. | ||
* | ||
* @private | ||
* @param {Object} map The map to query. | ||
* @param {string} key The reference key. | ||
* @returns {*} Returns the map data. | ||
*/ | ||
function getMapData(map, key) { | ||
@@ -1298,12 +554,2 @@ var data = map.__data__; | ||
} | ||
/** | ||
* Gets the native function at `key` of `object`. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @param {string} key The key of the method to get. | ||
* @returns {*} Returns the function if it's native, else `undefined`. | ||
*/ | ||
function getNative(object, key) { | ||
@@ -1313,23 +559,4 @@ var value = getValue(object, key); | ||
} | ||
/** | ||
* Creates an array of the own enumerable symbol properties of `object`. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @returns {Array} Returns the array of symbols. | ||
*/ | ||
var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray; | ||
/** | ||
* Gets the `toStringTag` of `value`. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {string} Returns the `toStringTag`. | ||
*/ | ||
var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11, | ||
// for data views in Edge < 14, and promises in Node.js. | ||
var getTag = baseGetTag; | ||
if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map && getTag(new Map()) != mapTag || Promise && getTag(Promise.resolve()) != promiseTag || Set && getTag(new Set()) != setTag || WeakMap && getTag(new WeakMap()) != weakMapTag) { | ||
@@ -1340,3 +567,2 @@ getTag = function (value) { | ||
ctorString = Ctor ? toSource(Ctor) : undefined; | ||
if (ctorString) { | ||
@@ -1346,12 +572,8 @@ switch (ctorString) { | ||
return dataViewTag; | ||
case mapCtorString: | ||
return mapTag; | ||
case promiseCtorString: | ||
return promiseTag; | ||
case setCtorString: | ||
return setTag; | ||
case weakMapCtorString: | ||
@@ -1361,19 +583,8 @@ return weakMapTag; | ||
} | ||
return result; | ||
}; | ||
} | ||
/** | ||
* Initializes an array clone. | ||
* | ||
* @private | ||
* @param {Array} array The array to clone. | ||
* @returns {Array} Returns the initialized clone. | ||
*/ | ||
function initCloneArray(array) { | ||
var length = array.length, | ||
result = array.constructor(length); // Add properties assigned by `RegExp#exec`. | ||
result = array.constructor(length); | ||
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) { | ||
@@ -1383,46 +594,17 @@ result.index = array.index; | ||
} | ||
return result; | ||
} | ||
/** | ||
* Initializes an object clone. | ||
* | ||
* @private | ||
* @param {Object} object The object to clone. | ||
* @returns {Object} Returns the initialized clone. | ||
*/ | ||
function initCloneObject(object) { | ||
return typeof object.constructor == 'function' && !isPrototype(object) ? baseCreate(getPrototype(object)) : {}; | ||
} | ||
/** | ||
* Initializes an object clone based on its `toStringTag`. | ||
* | ||
* **Note:** This function only supports cloning values with tags of | ||
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. | ||
* | ||
* @private | ||
* @param {Object} object The object to clone. | ||
* @param {string} tag The `toStringTag` of the object to clone. | ||
* @param {Function} cloneFunc The function to clone values. | ||
* @param {boolean} [isDeep] Specify a deep clone. | ||
* @returns {Object} Returns the initialized clone. | ||
*/ | ||
function initCloneByTag(object, tag, cloneFunc, isDeep) { | ||
var Ctor = object.constructor; | ||
switch (tag) { | ||
case arrayBufferTag: | ||
return cloneArrayBuffer(object); | ||
case boolTag: | ||
case dateTag: | ||
return new Ctor(+object); | ||
case dataViewTag: | ||
return cloneDataView(object, isDeep); | ||
case float32Tag: | ||
@@ -1438,16 +620,11 @@ case float64Tag: | ||
return cloneTypedArray(object, isDeep); | ||
case mapTag: | ||
return cloneMap(object, isDeep, cloneFunc); | ||
case numberTag: | ||
case stringTag: | ||
return new Ctor(object); | ||
case regexpTag: | ||
return cloneRegExp(object); | ||
case setTag: | ||
return cloneSet(object, isDeep, cloneFunc); | ||
case symbolTag: | ||
@@ -1457,12 +634,2 @@ return cloneSymbol(object); | ||
} | ||
/** | ||
* Checks if `value` is a valid array-like index. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. | ||
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`. | ||
*/ | ||
function isIndex(value, length) { | ||
@@ -1472,11 +639,2 @@ length = length == null ? MAX_SAFE_INTEGER : length; | ||
} | ||
/** | ||
* Checks if `value` is suitable for use as unique object key. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is suitable, else `false`. | ||
*/ | ||
function isKeyable(value) { | ||
@@ -1486,23 +644,5 @@ var type = typeof value; | ||
} | ||
/** | ||
* Checks if `func` has its source masked. | ||
* | ||
* @private | ||
* @param {Function} func The function to check. | ||
* @returns {boolean} Returns `true` if `func` is masked, else `false`. | ||
*/ | ||
function isMasked(func) { | ||
return !!maskSrcKey && maskSrcKey in func; | ||
} | ||
/** | ||
* Checks if `value` is likely a prototype object. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`. | ||
*/ | ||
function isPrototype(value) { | ||
@@ -1513,11 +653,2 @@ var Ctor = value && value.constructor, | ||
} | ||
/** | ||
* Converts `func` to its source code. | ||
* | ||
* @private | ||
* @param {Function} func The function to process. | ||
* @returns {string} Returns the source code. | ||
*/ | ||
function toSource(func) { | ||
@@ -1528,3 +659,2 @@ if (func != null) { | ||
} catch (e) {} | ||
try { | ||
@@ -1534,276 +664,28 @@ return func + ''; | ||
} | ||
return ''; | ||
} | ||
/** | ||
* This method is like `_.clone` except that it recursively clones `value`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 1.0.0 | ||
* @category Lang | ||
* @param {*} value The value to recursively clone. | ||
* @returns {*} Returns the deep cloned value. | ||
* @see _.clone | ||
* @example | ||
* | ||
* var objects = [{ 'a': 1 }, { 'b': 2 }]; | ||
* | ||
* var deep = _.cloneDeep(objects); | ||
* console.log(deep[0] === objects[0]); | ||
* // => false | ||
*/ | ||
function cloneDeep(value) { | ||
return baseClone(value, true, true); | ||
} | ||
/** | ||
* Performs a | ||
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) | ||
* comparison between two values to determine if they are equivalent. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to compare. | ||
* @param {*} other The other value to compare. | ||
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. | ||
* @example | ||
* | ||
* var object = { 'a': 1 }; | ||
* var other = { 'a': 1 }; | ||
* | ||
* _.eq(object, object); | ||
* // => true | ||
* | ||
* _.eq(object, other); | ||
* // => false | ||
* | ||
* _.eq('a', 'a'); | ||
* // => true | ||
* | ||
* _.eq('a', Object('a')); | ||
* // => false | ||
* | ||
* _.eq(NaN, NaN); | ||
* // => true | ||
*/ | ||
function eq(value, other) { | ||
return value === other || value !== value && other !== other; | ||
} | ||
/** | ||
* Checks if `value` is likely an `arguments` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an `arguments` object, | ||
* else `false`. | ||
* @example | ||
* | ||
* _.isArguments(function() { return arguments; }()); | ||
* // => true | ||
* | ||
* _.isArguments([1, 2, 3]); | ||
* // => false | ||
*/ | ||
function isArguments(value) { | ||
// Safari 8.1 makes `arguments.callee` enumerable in strict mode. | ||
return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); | ||
} | ||
/** | ||
* Checks if `value` is classified as an `Array` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an array, else `false`. | ||
* @example | ||
* | ||
* _.isArray([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArray(document.body.children); | ||
* // => false | ||
* | ||
* _.isArray('abc'); | ||
* // => false | ||
* | ||
* _.isArray(_.noop); | ||
* // => false | ||
*/ | ||
var isArray = Array.isArray; | ||
/** | ||
* Checks if `value` is array-like. A value is considered array-like if it's | ||
* not a function and has a `value.length` that's an integer greater than or | ||
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is array-like, else `false`. | ||
* @example | ||
* | ||
* _.isArrayLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArrayLike(document.body.children); | ||
* // => true | ||
* | ||
* _.isArrayLike('abc'); | ||
* // => true | ||
* | ||
* _.isArrayLike(_.noop); | ||
* // => false | ||
*/ | ||
function isArrayLike(value) { | ||
return value != null && isLength(value.length) && !isFunction(value); | ||
} | ||
/** | ||
* This method is like `_.isArrayLike` except that it also checks if `value` | ||
* is an object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an array-like object, | ||
* else `false`. | ||
* @example | ||
* | ||
* _.isArrayLikeObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArrayLikeObject(document.body.children); | ||
* // => true | ||
* | ||
* _.isArrayLikeObject('abc'); | ||
* // => false | ||
* | ||
* _.isArrayLikeObject(_.noop); | ||
* // => false | ||
*/ | ||
function isArrayLikeObject(value) { | ||
return isObjectLike(value) && isArrayLike(value); | ||
} | ||
/** | ||
* Checks if `value` is a buffer. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.3.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`. | ||
* @example | ||
* | ||
* _.isBuffer(new Buffer(2)); | ||
* // => true | ||
* | ||
* _.isBuffer(new Uint8Array(2)); | ||
* // => false | ||
*/ | ||
var isBuffer = nativeIsBuffer || stubFalse; | ||
/** | ||
* Checks if `value` is classified as a `Function` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a function, else `false`. | ||
* @example | ||
* | ||
* _.isFunction(_); | ||
* // => true | ||
* | ||
* _.isFunction(/abc/); | ||
* // => false | ||
*/ | ||
function isFunction(value) { | ||
// The use of `Object#toString` avoids issues with the `typeof` operator | ||
// in Safari 8-9 which returns 'object' for typed array and other constructors. | ||
var tag = isObject(value) ? objectToString.call(value) : ''; | ||
return tag == funcTag || tag == genTag; | ||
} | ||
/** | ||
* Checks if `value` is a valid array-like length. | ||
* | ||
* **Note:** This method is loosely based on | ||
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`. | ||
* @example | ||
* | ||
* _.isLength(3); | ||
* // => true | ||
* | ||
* _.isLength(Number.MIN_VALUE); | ||
* // => false | ||
* | ||
* _.isLength(Infinity); | ||
* // => false | ||
* | ||
* _.isLength('3'); | ||
* // => false | ||
*/ | ||
function isLength(value) { | ||
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; | ||
} | ||
/** | ||
* Checks if `value` is the | ||
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) | ||
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an object, else `false`. | ||
* @example | ||
* | ||
* _.isObject({}); | ||
* // => true | ||
* | ||
* _.isObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObject(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
*/ | ||
function isObject(value) { | ||
@@ -1813,129 +695,18 @@ var type = typeof value; | ||
} | ||
/** | ||
* Checks if `value` is object-like. A value is object-like if it's not `null` | ||
* and has a `typeof` result of "object". | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. | ||
* @example | ||
* | ||
* _.isObjectLike({}); | ||
* // => true | ||
* | ||
* _.isObjectLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObjectLike(_.noop); | ||
* // => false | ||
* | ||
* _.isObjectLike(null); | ||
* // => false | ||
*/ | ||
function isObjectLike(value) { | ||
return !!value && typeof value == 'object'; | ||
} | ||
/** | ||
* Creates an array of the own enumerable property names of `object`. | ||
* | ||
* **Note:** Non-object values are coerced to objects. See the | ||
* [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) | ||
* for more details. | ||
* | ||
* @static | ||
* @since 0.1.0 | ||
* @memberOf _ | ||
* @category Object | ||
* @param {Object} object The object to query. | ||
* @returns {Array} Returns the array of property names. | ||
* @example | ||
* | ||
* function Foo() { | ||
* this.a = 1; | ||
* this.b = 2; | ||
* } | ||
* | ||
* Foo.prototype.c = 3; | ||
* | ||
* _.keys(new Foo); | ||
* // => ['a', 'b'] (iteration order is not guaranteed) | ||
* | ||
* _.keys('hi'); | ||
* // => ['0', '1'] | ||
*/ | ||
function keys(object) { | ||
return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object); | ||
} | ||
/** | ||
* This method returns a new empty array. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.13.0 | ||
* @category Util | ||
* @returns {Array} Returns the new empty array. | ||
* @example | ||
* | ||
* var arrays = _.times(2, _.stubArray); | ||
* | ||
* console.log(arrays); | ||
* // => [[], []] | ||
* | ||
* console.log(arrays[0] === arrays[1]); | ||
* // => false | ||
*/ | ||
function stubArray() { | ||
return []; | ||
} | ||
/** | ||
* This method returns `false`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.13.0 | ||
* @category Util | ||
* @returns {boolean} Returns `false`. | ||
* @example | ||
* | ||
* _.times(2, _.stubFalse); | ||
* // => [false, false] | ||
*/ | ||
function stubFalse() { | ||
return false; | ||
} | ||
module.exports = cloneDeep; | ||
}); | ||
/** | ||
* @ignore | ||
*/ | ||
const arrayMutators = ['push', 'unshift', 'pop', 'splice', 'reverse', 'fill', 'sort']; | ||
const isArrayMutator = (target, property) => typeof target[property] === 'function' && arrayMutators.includes(property); | ||
/** | ||
* Creates an observable state from an object | ||
* @name createState | ||
* @param {object} initialState the initial state | ||
* @returns {obserableState} | ||
* @example | ||
* import { createState } from 'obzervable' | ||
* const State = createState( { | ||
* name: 'John Doe', | ||
* age: 27 | ||
* } ) | ||
*/ | ||
var createState = (initialState => { | ||
@@ -1945,74 +716,49 @@ return ((initialState, __subscribers) => { | ||
get: (target, property) => { | ||
const value = target[property]; // Handling objects | ||
if (typeof value === 'object' && value !== null) { | ||
return new Proxy(target[property], handler()); // Handling array mutators | ||
} else if (isArrayMutator(target, property)) { | ||
return function (...args) { | ||
const val = Array.prototype[property].apply(target, args); | ||
__subscribers.forEach(({ | ||
__fn | ||
}) => __fn(initialState)); | ||
return val; | ||
}; | ||
} else if (property === '__subscribe') { | ||
return __fn => __subscribers.push({ | ||
__fn | ||
}); | ||
} else if (property === 'apply') { | ||
/** | ||
* A method to apply multiple changes to the state, any changes are mede on the state will be treated as a single change, can be called on any level of object | ||
* @name apply | ||
* @param {object} changes changes to be applyed to the state | ||
* @example | ||
* import { createState, observe } from 'obzervable' | ||
* const State = createState( { | ||
* jedi: { | ||
* name: 'Obi-Wan Kenobi', | ||
* } | ||
* } ) | ||
* | ||
* const jediNameMap = ( { jedi: { name } } ) => ( { name } ) | ||
* | ||
* observe( State, jediNameMap )( ( { name } ) => { | ||
* console.log( name ) | ||
* } ) | ||
* // Obi-Wan Kenobi | ||
* | ||
* State.jedi.apply( { name: 'Yoda' } ) | ||
* // Yoda | ||
* | ||
* State.apply( { | ||
* jedi: { | ||
* name: 'Anakin Skywalker', | ||
* } | ||
* } ) | ||
* // Anakin Skywalker | ||
*/ | ||
return obj => (modified => { | ||
const subscribersCopy = __subscribers.splice(0, __subscribers.length, { | ||
__fn: () => { | ||
modified = true; | ||
__subscribers.splice(0, __subscribers.length); | ||
} | ||
}); | ||
Object.assign(new Proxy(target, handler()), obj); | ||
__subscribers.splice(0, __subscribers.length, ...subscribersCopy); | ||
modified && __subscribers.forEach(({ | ||
__fn | ||
}) => __fn(initialState)); | ||
})(false); | ||
} else { | ||
return value; | ||
const value = target[property]; | ||
switch (typeof value) { | ||
case 'object': | ||
return value === null ? value : new Proxy(target[property], handler()); | ||
break; | ||
case 'function': | ||
return arrayMutators.includes(property) ? function (...args) { | ||
const value = Array.prototype[property].apply(target, args); | ||
__subscribers.forEach(({ | ||
__fn | ||
}) => __fn(initialState)); | ||
return value; | ||
} : value; | ||
break; | ||
case 'undefined': | ||
switch (property) { | ||
case '__subscribe': | ||
return __fn => __subscribers.push({ | ||
__fn | ||
}); | ||
break; | ||
case 'apply': | ||
return obj => (modified => { | ||
const subscribersCopy = __subscribers.splice(0, __subscribers.length, { | ||
__fn: () => { | ||
modified = true; | ||
__subscribers.splice(0, __subscribers.length); | ||
} | ||
}); | ||
Object.assign(new Proxy(target, handler()), obj); | ||
__subscribers.splice(0, __subscribers.length, ...subscribersCopy); | ||
modified && __subscribers.forEach(({ | ||
__fn | ||
}) => __fn(initialState)); | ||
})(false); | ||
break; | ||
default: | ||
return undefined; | ||
break; | ||
} | ||
default: | ||
return value; | ||
break; | ||
} | ||
}, | ||
set: (target, prop, value) => { | ||
const oldValue = target[prop]; // trigger callback on property change | ||
const oldValue = target[prop]; | ||
if (oldValue !== value) { | ||
@@ -2023,3 +769,2 @@ if (typeof oldValue === 'object' && typeof value === 'object') { | ||
target[prop] = value; | ||
__subscribers.forEach(({ | ||
@@ -2030,7 +775,5 @@ __fn | ||
} | ||
return true; | ||
} | ||
}); | ||
return new Proxy(initialState, handler()); | ||
@@ -2040,45 +783,9 @@ })(lodash_clonedeep(initialState), []); | ||
/** | ||
* Creates an observer that listens to state changes | ||
* @name observe | ||
* @param {obserableState} state | ||
* @param {function=} mapper ( Optional ) a mapper to observe only certain parts of the state, if not specified it will listen to changes in the whole state | ||
* @returns {function} a function that takes your callback and will call it everytime state changes | ||
* @example | ||
* import { createState, observe } from 'obzervable' | ||
* const State = createState( { | ||
* title: 'Shopping list', | ||
* items: [] | ||
* } ) | ||
* | ||
* observe( State, ( { items } ) => ( { items } ) )( ( { items } ) => { | ||
* console.log('shopping list:', items) | ||
* } ) | ||
* // shopping list: [] | ||
* | ||
* observe( State, ( { title } ) => ( { title } ) )( ( { title } ) => { | ||
* console.log('title:', title) | ||
* } ) | ||
* // title: 'Shopping list' | ||
* | ||
* State.items.push( [ 'peanut butter' ] ) | ||
* // shopping list: [ 'peanut butter' ] | ||
* State.items.push( [ 'apples' ] ) | ||
* // shopping list: [ 'peanut butter', 'apples' ] | ||
* State.title = 'New title' | ||
* // title: New title | ||
*/ | ||
var observe = ((state, mapper = null) => fn => { | ||
if (mapper && typeof mapper === 'function') { | ||
return (newState => { | ||
// creating a new state for mapper | ||
const newStore = createState(newState); // // subscribing to changes in the new state | ||
newStore.__subscribe(fn); // // subscribing mapper to changes in the initial state | ||
state.__subscribe(storeCopy => // assigning changes to new state through mapper | ||
const newStore = createState(newState); | ||
newStore.__subscribe(fn); | ||
state.__subscribe(storeCopy => | ||
Object.assign(newStore, mapper(storeCopy))); | ||
return fn(newState); | ||
@@ -2088,3 +795,2 @@ })(mapper(state)); | ||
state.__subscribe(fn); | ||
return fn(state); | ||
@@ -2094,5 +800,2 @@ } | ||
/** | ||
* @ignore | ||
*/ | ||
var index = { | ||
@@ -2099,0 +802,0 @@ createState: createState, |
{ | ||
"name": "obzervable", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"main": "./dist/index.js", | ||
@@ -18,2 +18,3 @@ "repository": "https://github.com/voodoo-child/obzervable.git", | ||
"rollup-plugin-babel": "^4.0.3", | ||
"rollup-plugin-cleanup": "^3.0.0", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
@@ -20,0 +21,0 @@ "rollup-plugin-node-resolve": "^3.4.0" |
# obzervable | ||
![build status](https://travis-ci.org/voodoo-child/observable.svg?branch=master) | ||
![build status](https://travis-ci.org/voodoo-child/obzervable.svg?branch=master) | ||
Create observable states. | ||
*obzervable* is a library for creating observable mutable states. | ||
* Works with nested objects and array mutators. | ||
* Supports mapping of states that allows to listen only to changes of certain properties of the state. | ||
* Can be used to do DOM Manipulations only when they are required. | ||
@@ -31,4 +34,6 @@ # Documentation | ||
const mapCount = ( { count } ) => ( { count } ) | ||
const mapActive = ( { active } ) => ( { active } ) | ||
observe( State, ( { count } ) => ( { count } ) )( ( { count } ) => { | ||
observe( State, mapCount )( ( { count } ) => { | ||
return Counter.innerText = count | ||
@@ -39,3 +44,3 @@ } ); | ||
observe( State, ( { active } ) => ( { active } ) )( ( { active } ) => { | ||
observe( State, mapActive )( ( { active } ) => { | ||
@@ -48,3 +53,3 @@ if ( active ) { | ||
Button.innerText = ( active ) ? 'stop' : 'start' | ||
StartButton.innerText = ( active ) ? 'stop' : 'start' | ||
@@ -51,0 +56,0 @@ return Counter.style.color = ( active ) ? 'green' : 'red' |
Sorry, the diff of this file is not supported yet
72
392273
13
728