mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Cleanup mapClear.
This commit is contained in:
24
lodash.js
24
lodash.js
@@ -1859,13 +1859,24 @@
|
|||||||
var index = -1,
|
var index = -1,
|
||||||
length = values ? values.length : 0;
|
length = values ? values.length : 0;
|
||||||
|
|
||||||
this.__data__ = { 'hash': new Hash, 'map': Map ? new Map : [], 'string': new Hash };
|
this.clear();
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var entry = values[index];
|
var entry = values[index];
|
||||||
this.set(entry[0], entry[1]);
|
this.set(entry[0], entry[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all key-value entries from the map.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @name clear
|
||||||
|
* @memberOf MapCache
|
||||||
|
*/
|
||||||
|
function mapClear() {
|
||||||
|
this.__data__ = { 'hash': new Hash, 'map': Map ? new Map : [], 'string': new Hash };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes `key` and its value from the map.
|
* Removes `key` and its value from the map.
|
||||||
*
|
*
|
||||||
@@ -1939,17 +1950,6 @@
|
|||||||
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 };
|
|
||||||
}
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
33
test/test.js
33
test/test.js
@@ -12329,7 +12329,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should expose a `cache` object on the `memoized` function which implements `Map` interface', function(assert) {
|
QUnit.test('should expose a `cache` object on the `memoized` function which implements `Map` interface', function(assert) {
|
||||||
assert.expect(12);
|
assert.expect(22);
|
||||||
|
|
||||||
lodashStable.times(2, function(index) {
|
lodashStable.times(2, function(index) {
|
||||||
var resolver = index ? identity : null;
|
var resolver = index ? identity : null;
|
||||||
@@ -12341,13 +12341,22 @@
|
|||||||
var cache = memoized.cache;
|
var cache = memoized.cache;
|
||||||
|
|
||||||
memoized('a');
|
memoized('a');
|
||||||
|
memoized('b');
|
||||||
|
memoized('c');
|
||||||
|
|
||||||
assert.strictEqual(cache.has('a'), true);
|
assert.strictEqual(cache.has('a'), true);
|
||||||
|
assert.strictEqual(cache.has('b'), true);
|
||||||
|
assert.strictEqual(cache.has('c'), true);
|
||||||
|
|
||||||
assert.strictEqual(cache.get('a'), 'value:a');
|
assert.strictEqual(cache.get('a'), 'value:a');
|
||||||
assert.strictEqual(cache['delete']('a'), true);
|
assert.strictEqual(cache['delete']('a'), true);
|
||||||
assert.strictEqual(cache.has('a'), false);
|
assert.strictEqual(cache.has('a'), false);
|
||||||
assert.strictEqual(cache.get('a'), undefined);
|
assert.strictEqual(cache.get('a'), undefined);
|
||||||
assert.strictEqual(cache['delete']('a'), false);
|
assert.strictEqual(cache['delete']('a'), false);
|
||||||
|
|
||||||
|
assert.strictEqual(cache.clear(), undefined);
|
||||||
|
assert.strictEqual(cache.has('b'), false);
|
||||||
|
assert.strictEqual(cache.has('c'), false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -12485,28 +12494,6 @@
|
|||||||
|
|
||||||
_.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