react / wstein / node_modules / browserify / node_modules / browser-pack / node_modules / combine-source-map / node_modules / lodash.memoize / index.js
80552 views/**1* lodash 3.0.4 (Custom Build) <https://lodash.com/>2* Build: `lodash modern modularize exports="npm" -o ./`3* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>4* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>5* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors6* Available under MIT license <https://lodash.com/license>7*/89/** Used as the `TypeError` message for "Functions" methods. */10var FUNC_ERROR_TEXT = 'Expected a function';1112/** Used for native method references. */13var objectProto = Object.prototype;1415/** Used to check objects for own properties. */16var hasOwnProperty = objectProto.hasOwnProperty;1718/**19* Creates a cache object to store key/value pairs.20*21* @private22* @static23* @name Cache24* @memberOf _.memoize25*/26function MapCache() {27this.__data__ = {};28}2930/**31* Removes `key` and its value from the cache.32*33* @private34* @name delete35* @memberOf _.memoize.Cache36* @param {string} key The key of the value to remove.37* @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.38*/39function mapDelete(key) {40return this.has(key) && delete this.__data__[key];41}4243/**44* Gets the cached value for `key`.45*46* @private47* @name get48* @memberOf _.memoize.Cache49* @param {string} key The key of the value to get.50* @returns {*} Returns the cached value.51*/52function mapGet(key) {53return key == '__proto__' ? undefined : this.__data__[key];54}5556/**57* Checks if a cached value for `key` exists.58*59* @private60* @name has61* @memberOf _.memoize.Cache62* @param {string} key The key of the entry to check.63* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.64*/65function mapHas(key) {66return key != '__proto__' && hasOwnProperty.call(this.__data__, key);67}6869/**70* Sets `value` to `key` of the cache.71*72* @private73* @name set74* @memberOf _.memoize.Cache75* @param {string} key The key of the value to cache.76* @param {*} value The value to cache.77* @returns {Object} Returns the cache object.78*/79function mapSet(key, value) {80if (key != '__proto__') {81this.__data__[key] = value;82}83return this;84}8586/**87* Creates a function that memoizes the result of `func`. If `resolver` is88* provided it determines the cache key for storing the result based on the89* arguments provided to the memoized function. By default, the first argument90* provided to the memoized function is coerced to a string and used as the91* cache key. The `func` is invoked with the `this` binding of the memoized92* function.93*94* **Note:** The cache is exposed as the `cache` property on the memoized95* function. Its creation may be customized by replacing the `_.memoize.Cache`96* constructor with one whose instances implement the [`Map`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-map-prototype-object)97* method interface of `get`, `has`, and `set`.98*99* @static100* @memberOf _101* @category Function102* @param {Function} func The function to have its output memoized.103* @param {Function} [resolver] The function to resolve the cache key.104* @returns {Function} Returns the new memoizing function.105* @example106*107* var upperCase = _.memoize(function(string) {108* return string.toUpperCase();109* });110*111* upperCase('fred');112* // => 'FRED'113*114* // modifying the result cache115* upperCase.cache.set('fred', 'BARNEY');116* upperCase('fred');117* // => 'BARNEY'118*119* // replacing `_.memoize.Cache`120* var object = { 'user': 'fred' };121* var other = { 'user': 'barney' };122* var identity = _.memoize(_.identity);123*124* identity(object);125* // => { 'user': 'fred' }126* identity(other);127* // => { 'user': 'fred' }128*129* _.memoize.Cache = WeakMap;130* var identity = _.memoize(_.identity);131*132* identity(object);133* // => { 'user': 'fred' }134* identity(other);135* // => { 'user': 'barney' }136*/137function memoize(func, resolver) {138if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {139throw new TypeError(FUNC_ERROR_TEXT);140}141var memoized = function() {142var args = arguments,143key = resolver ? resolver.apply(this, args) : args[0],144cache = memoized.cache;145146if (cache.has(key)) {147return cache.get(key);148}149var result = func.apply(this, args);150memoized.cache = cache.set(key, result);151return result;152};153memoized.cache = new memoize.Cache;154return memoized;155}156157// Add functions to the `Map` cache.158MapCache.prototype['delete'] = mapDelete;159MapCache.prototype.get = mapGet;160MapCache.prototype.has = mapHas;161MapCache.prototype.set = mapSet;162163// Assign cache to `_.memoize`.164memoize.Cache = MapCache;165166module.exports = memoize;167168169