mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Add clear method to MapCache.
This commit is contained in:
committed by
John-David Dalton
parent
71fb66dc37
commit
380435d020
12
lodash.js
12
lodash.js
@@ -1939,6 +1939,17 @@
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the map data
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @name clear
|
||||||
|
* @memberOf MapCache
|
||||||
|
*/
|
||||||
|
function mapClear() {
|
||||||
|
this.__data__ = { 'hash': new Hash, 'map': Map ? new Map : [], 'string': new Hash };
|
||||||
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13737,6 +13748,7 @@
|
|||||||
Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto;
|
Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto;
|
||||||
|
|
||||||
// Add functions to the `MapCache`.
|
// Add functions to the `MapCache`.
|
||||||
|
MapCache.prototype.clear = mapClear;
|
||||||
MapCache.prototype['delete'] = mapDelete;
|
MapCache.prototype['delete'] = mapDelete;
|
||||||
MapCache.prototype.get = mapGet;
|
MapCache.prototype.get = mapGet;
|
||||||
MapCache.prototype.has = mapHas;
|
MapCache.prototype.has = mapHas;
|
||||||
|
|||||||
22
test/test.js
22
test/test.js
@@ -12485,6 +12485,28 @@
|
|||||||
|
|
||||||
_.memoize.Cache = oldCache;
|
_.memoize.Cache = oldCache;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should allow clearing cache', function(assert) {
|
||||||
|
assert.expect(5);
|
||||||
|
|
||||||
|
var memoized = _.memoize(_.identity);
|
||||||
|
|
||||||
|
assert.strictEqual(memoized.cache.has('a'), false);
|
||||||
|
|
||||||
|
memoized('a');
|
||||||
|
|
||||||
|
assert.strictEqual(memoized.cache.has('a'), true);
|
||||||
|
|
||||||
|
memoized.cache.clear();
|
||||||
|
|
||||||
|
assert.strictEqual(memoized.cache.has('a'), false);
|
||||||
|
|
||||||
|
memoized('a');
|
||||||
|
memoized('b');
|
||||||
|
|
||||||
|
assert.strictEqual(memoized.cache.has('a'), true);
|
||||||
|
assert.strictEqual(memoized.cache.has('b'), true);
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user