Skip to content

Commit

Permalink
Update up to changes to WeakMap
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Apr 13, 2015
1 parent 2bccb6f commit 453ee0d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -163,7 +163,7 @@ Object.defineProperties(Foo.prototype, memoizeMethods({
In that case memoization cache is not bound to memoized function (which we may want to keep forever), but to objects for which given results were generated.

This mode works only for functions of which first argument is expected to be an object.
It can be combined with other options mentioned across documentation. However due to WeakMap specificity global clear is not possible with [dispose callback](#registering-dispose-callback) registered.
It can be combined with other options mentioned across documentation. However due to WeakMap specificity global clear is not possible.

```javascript
var memoize = require('memoizee/weak');
Expand Down
14 changes: 3 additions & 11 deletions lib/weak.js
Expand Up @@ -14,13 +14,7 @@ var customError = require('es5-ext/error/custom')
, resolveNormalize = require('./resolve-normalize')

, slice = Array.prototype.slice, defineProperties = Object.defineProperties
, hasOwnProperty = Object.prototype.hasOwnProperty
, clearOnDispose;

clearOnDispose = function () {
throw customError("Clear of Weak Map based configuration is not possible together with " +
" 'dispose' option", 'CLEAR_WITH_DISPOSE');
};
, hasOwnProperty = Object.prototype.hasOwnProperty;

module.exports = function (memoize) {
return function (fn/*, options*/) {
Expand Down Expand Up @@ -54,8 +48,7 @@ module.exports = function (memoize) {
delete: d(function (obj) {
if (resolve) obj = resolve(arguments)[0];
return map.delete(obj);
}),
clear: d(map.clear.bind(map))
})
});
}
memoized = defineProperties(defineLength(function (obj) {
Expand Down Expand Up @@ -89,8 +82,7 @@ module.exports = function (memoize) {
memoizer = map.get(obj);
if (!memoizer) return;
memoizer.delete.apply(this, slice.call(args, 1));
}, length)),
clear: d(options.dispose ? clearOnDispose : map.clear.bind(map))
}, length))
});
if (!options.refCounter || !extensions.refCounter) return memoized;
defineProperties(memoized, {
Expand Down

0 comments on commit 453ee0d

Please sign in to comment.