mirror of
https://github.com/BreizhHardware/memoizee.git
synced 2026-01-18 16:37:21 +01:00
Remove support for serialize option
Instead support function value for `normalizer`
This commit is contained in:
2
index.js
2
index.js
@@ -7,7 +7,7 @@ var normalizeOpts = require('es5-ext/object/normalize-options')
|
||||
module.exports = function (fn/*, options*/) {
|
||||
var options = normalizeOpts(arguments[1]), length;
|
||||
|
||||
if (!options.normalizer && !options.serialize) {
|
||||
if (!options.normalizer) {
|
||||
length = options.length = resolveLength(options.length, fn.length, options.async);
|
||||
if (length === 0) {
|
||||
options.normalizer = require('./lib/normalizers/0');
|
||||
|
||||
@@ -27,18 +27,18 @@ module.exports = function (original, length, options) {
|
||||
else memLength = original.length;
|
||||
|
||||
if (options.normalizer) {
|
||||
get = callable(options.normalizer.get);
|
||||
if (options.normalizer.set !== undefined) {
|
||||
set = callable(options.normalizer.set);
|
||||
del = callable(options.normalizer.delete);
|
||||
clear = callable(options.normalizer.clear);
|
||||
if (typeof options.normalizer === 'function') {
|
||||
set = get = options.normalizer;
|
||||
} else {
|
||||
set = get;
|
||||
get = callable(options.normalizer.get);
|
||||
if (options.normalizer.set !== undefined) {
|
||||
set = callable(options.normalizer.set);
|
||||
del = callable(options.normalizer.delete);
|
||||
clear = callable(options.normalizer.clear);
|
||||
} else {
|
||||
set = get;
|
||||
}
|
||||
}
|
||||
} else if (options.serialize) {
|
||||
set = get = (function (serialize) {
|
||||
return function (args) { return serialize.apply(null, args); };
|
||||
}(callable(options.serialize)));
|
||||
}
|
||||
|
||||
if (options.resolvers != null) {
|
||||
|
||||
@@ -90,9 +90,9 @@ module.exports = function (t, a) {
|
||||
}
|
||||
};
|
||||
},
|
||||
"Serialize": function () {
|
||||
"Normalizer function": function () {
|
||||
var i = 0, fn = function () { ++i; return join.call(arguments, '|'); }, mfn;
|
||||
mfn = t(fn, { serialize: Boolean });
|
||||
mfn = t(fn, { normalizer: function (args) { return Boolean(args[0]); } });
|
||||
a(mfn(false, 'raz'), 'false|raz', "#1");
|
||||
a(mfn(0, 'dwa'), 'false|raz', "#2");
|
||||
a(i, 1, "Called once");
|
||||
|
||||
Reference in New Issue
Block a user