Comparing version 0.3.1 to 0.3.2
22
index.js
@@ -12,14 +12,14 @@ 'use strict'; | ||
length = options.length = resolveLength(options.length, fn.length, options.async); | ||
if (length === 0) { | ||
options.normalizer = require('./normalizers/0'); | ||
} else if (options.primitive) { | ||
if (length === false) { | ||
options.normalizer = require('./normalizers/primitive'); | ||
} else if (length > 1) { | ||
options.normalizer = require('./normalizers/get-primitive-fixed')(length); | ||
if (length !== 0) { | ||
if (options.primitive) { | ||
if (length === false) { | ||
options.normalizer = require('./normalizers/primitive'); | ||
} else if (length > 1) { | ||
options.normalizer = require('./normalizers/get-primitive-fixed')(length); | ||
} | ||
} else { | ||
if (length === false) options.normalizer = require('./normalizers/get')(); | ||
else if (length === 1) options.normalizer = require('./normalizers/get-1')(); | ||
else options.normalizer = require('./normalizers/get-fixed')(length); | ||
} | ||
} else { | ||
if (length === false) options.normalizer = require('./normalizers/get')(); | ||
else if (length === 1) options.normalizer = require('./normalizers/get-1')(); | ||
else options.normalizer = require('./normalizers/get-fixed')(length); | ||
} | ||
@@ -26,0 +26,0 @@ } |
@@ -23,3 +23,3 @@ 'use strict'; | ||
module.exports = function (original, length, options) { | ||
var cache = create(null), conf, memLength, get, set, del, clear | ||
var cache = create(null), conf, memLength, get, set, del, clear, extDel | ||
, getListeners, setListeners, deleteListeners, memoized, resolve, resolvers; | ||
@@ -77,2 +77,18 @@ if (length !== false) memLength = length; | ||
}, memLength); | ||
} else if (length === 0) { | ||
memoized = function () { | ||
var result; | ||
if (hasOwnProperty.call(cache, 'data')) { | ||
if (getListeners) conf.emit('get', 'data', arguments, this); | ||
return cache.data; | ||
} | ||
if (!arguments.length) result = call.call(original, this); | ||
else result = apply.call(original, this, arguments); | ||
if (hasOwnProperty.call(cache, 'data')) { | ||
throw customError("Circular invocation", 'CIRCULAR_INVOCATION'); | ||
} | ||
cache.data = result; | ||
if (setListeners) conf.emit('set', 'data'); | ||
return result; | ||
}; | ||
} else { | ||
@@ -131,5 +147,4 @@ memoized = function (arg) { | ||
}; | ||
defineProperties(memoized, { | ||
__memoized__: d(true), | ||
delete: d(get ? defineLength(function (arg) { | ||
if (get) { | ||
extDel = defineLength(function (arg) { | ||
var id, args = arguments; | ||
@@ -140,6 +155,14 @@ if (resolve) args = resolve(args); | ||
conf.delete(id); | ||
}, memLength) : function (arg) { | ||
}, memLength); | ||
} else if (length === 0) { | ||
extDel = function () { return conf.delete('data'); }; | ||
} else { | ||
extDel = function (arg) { | ||
if (resolve) arg = resolve(arguments)[0]; | ||
return conf.delete(arg); | ||
}), | ||
}; | ||
} | ||
defineProperties(memoized, { | ||
__memoized__: d(true), | ||
delete: d(extDel), | ||
clear: d(conf.clear) | ||
@@ -146,0 +169,0 @@ }); |
{ | ||
"name": "memoizee", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Memoize/cache", | ||
@@ -28,3 +28,3 @@ "author": "Mariusz Nowak <medikoo@medikoo.com> (http://www.medikoo.com/)", | ||
"d": "~0.1.1", | ||
"es5-ext": "~0.10.2", | ||
"es5-ext": "~0.10.4", | ||
"event-emitter": "~0.3.1", | ||
@@ -31,0 +31,0 @@ "lru-queue": "0.1.x", |
@@ -1,3 +0,1 @@ | ||
// To be used internally, memoize factory | ||
'use strict'; | ||
@@ -4,0 +2,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129794
47
3641
Updatedes5-ext@~0.10.4