mirror of
https://github.com/BreizhHardware/memoizee.git
synced 2026-01-18 16:37:21 +01:00
refactor: update after change of linter
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
/* global console */
|
||||
/* eslint no-console: 0, id-length: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Simple benchmark for very simple memoization case (fibonacci series)
|
||||
@@ -12,12 +15,20 @@ var forEach = require("es5-ext/object/for-each")
|
||||
, underscore = require("underscore").memoize
|
||||
, lodash = require("lodash").memoize
|
||||
, lruCache = require("lru-cache")
|
||||
, lruSecondary = require("secondary-cache/lib/lru-cache")
|
||||
, lruSecondary = require("secondary-cache/lib/lru-cache");
|
||||
|
||||
, now = Date.now
|
||||
|
||||
, time, getFib, lru, memo, total, index = 3000, count = 10, i, lruMax = 1000
|
||||
, data = {}, lruObj;
|
||||
var now = Date.now
|
||||
, time
|
||||
, getFib
|
||||
, lru
|
||||
, memo
|
||||
, total
|
||||
, index = 3000
|
||||
, count = 10
|
||||
, i
|
||||
, lruMax = 1000
|
||||
, data = {}
|
||||
, lruObj;
|
||||
|
||||
getFib = function (memoize, opts) {
|
||||
var fib = memoize(function (x) {
|
||||
@@ -117,8 +128,13 @@ while (i--) {
|
||||
}
|
||||
data["secondary-cache LRU (max: 1000)"] = total;
|
||||
|
||||
forEach(data, function (value, name, obj, index) {
|
||||
console.log(index + 1 + ":", pad.call(value, " ", 5) + "ms ", name);
|
||||
}, null, function (a, b) {
|
||||
return this[a] - this[b];
|
||||
});
|
||||
forEach(
|
||||
data,
|
||||
function (value, name, obj, currentIndex) {
|
||||
console.log(currentIndex + 1 + ":", pad.call(value, " ", 5) + "ms ", name);
|
||||
},
|
||||
null,
|
||||
function (a, b) {
|
||||
return this[a] - this[b];
|
||||
}
|
||||
);
|
||||
|
||||
39
ext/async.js
39
ext/async.js
@@ -1,3 +1,5 @@
|
||||
/* eslint consistent-this: 0, no-shadow:0, no-eq-null: 0, eqeqeq: 0, no-unused-vars: 0 */
|
||||
|
||||
// Support for asynchronous functions
|
||||
|
||||
"use strict";
|
||||
@@ -6,16 +8,18 @@ var aFrom = require("es5-ext/array/from")
|
||||
, objectMap = require("es5-ext/object/map")
|
||||
, mixin = require("es5-ext/object/mixin")
|
||||
, defineLength = require("es5-ext/function/_define-length")
|
||||
, nextTick = require("next-tick")
|
||||
, nextTick = require("next-tick");
|
||||
|
||||
, slice = Array.prototype.slice
|
||||
, apply = Function.prototype.apply, create = Object.create
|
||||
, hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
var slice = Array.prototype.slice, apply = Function.prototype.apply, create = Object.create;
|
||||
|
||||
require("../lib/registered-extensions").async = function (tbi, conf) {
|
||||
var waiting = create(null), cache = create(null)
|
||||
, base = conf.memoized, original = conf.original
|
||||
, currentCallback, currentContext, currentArgs;
|
||||
var waiting = create(null)
|
||||
, cache = create(null)
|
||||
, base = conf.memoized
|
||||
, original = conf.original
|
||||
, currentCallback
|
||||
, currentContext
|
||||
, currentArgs;
|
||||
|
||||
// Initial
|
||||
conf.memoized = defineLength(function (arg) {
|
||||
@@ -27,8 +31,8 @@ require("../lib/registered-extensions").async = function (tbi, conf) {
|
||||
return base.apply(currentContext = this, currentArgs = args);
|
||||
}, base);
|
||||
try {
|
||||
mixin(conf.memoized, base);
|
||||
} catch (ignore) {}
|
||||
mixin(conf.memoized, base);
|
||||
} catch (ignore) {}
|
||||
|
||||
// From cache (sync)
|
||||
conf.on("get", function (id) {
|
||||
@@ -74,7 +78,7 @@ require("../lib/registered-extensions").async = function (tbi, conf) {
|
||||
if (id == null) {
|
||||
// Shouldn't happen, means async callback was called sync way
|
||||
nextTick(apply.bind(self, this, arguments));
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
delete self.id;
|
||||
cb = waiting[id];
|
||||
@@ -82,7 +86,7 @@ require("../lib/registered-extensions").async = function (tbi, conf) {
|
||||
if (!cb) {
|
||||
// Already processed,
|
||||
// outcome of race condition: asyncFn(1, cb), asyncFn.clear(), asyncFn(1, cb)
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
args = aFrom(arguments);
|
||||
if (conf.has(id)) {
|
||||
@@ -97,8 +101,8 @@ require("../lib/registered-extensions").async = function (tbi, conf) {
|
||||
result = apply.call(cb, this, args);
|
||||
} else {
|
||||
cb.forEach(function (cb) {
|
||||
result = apply.call(cb, this, args);
|
||||
}, this);
|
||||
result = apply.call(cb, this, args);
|
||||
}, this);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@@ -146,8 +150,11 @@ require("../lib/registered-extensions").async = function (tbi, conf) {
|
||||
conf.on("clear", function () {
|
||||
var oldCache = cache;
|
||||
cache = create(null);
|
||||
conf.emit("clearasync", objectMap(oldCache, function (data) {
|
||||
return slice.call(data.args, 1);
|
||||
}));
|
||||
conf.emit(
|
||||
"clearasync",
|
||||
objectMap(oldCache, function (data) {
|
||||
return slice.call(data.args, 1);
|
||||
})
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint consistent-this: 0 */
|
||||
|
||||
// Timeout cached values
|
||||
|
||||
"use strict";
|
||||
@@ -7,10 +9,9 @@ var aFrom = require("es5-ext/array/from")
|
||||
, nextTick = require("next-tick")
|
||||
, isPromise = require("is-promise")
|
||||
, timeout = require("timers-ext/valid-timeout")
|
||||
, extensions = require("../lib/registered-extensions")
|
||||
, extensions = require("../lib/registered-extensions");
|
||||
|
||||
, noop = Function.prototype
|
||||
, max = Math.max, min = Math.min, create = Object.create;
|
||||
var noop = Function.prototype, max = Math.max, min = Math.min, create = Object.create;
|
||||
|
||||
extensions.maxAge = function (maxAge, conf, options) {
|
||||
var timeouts, postfix, preFetchAge, preFetchTimeouts;
|
||||
@@ -20,11 +21,12 @@ extensions.maxAge = function (maxAge, conf, options) {
|
||||
|
||||
timeouts = create(null);
|
||||
postfix = (options.async && extensions.async) || (options.promise && extensions.promise)
|
||||
? "async" : "";
|
||||
? "async"
|
||||
: "";
|
||||
conf.on("set" + postfix, function (id) {
|
||||
timeouts[id] = setTimeout(function () {
|
||||
conf.delete(id);
|
||||
}, maxAge);
|
||||
conf.delete(id);
|
||||
}, maxAge);
|
||||
if (!preFetchTimeouts) return;
|
||||
if (preFetchTimeouts[id]) {
|
||||
if (preFetchTimeouts[id] !== "nextTick") clearTimeout(preFetchTimeouts[id]);
|
||||
@@ -42,7 +44,7 @@ extensions.maxAge = function (maxAge, conf, options) {
|
||||
});
|
||||
|
||||
if (options.preFetch) {
|
||||
if ((options.preFetch === true) || isNaN(options.preFetch)) {
|
||||
if (options.preFetch === true || isNaN(options.preFetch)) {
|
||||
preFetchAge = 0.333;
|
||||
} else {
|
||||
preFetchAge = max(min(Number(options.preFetch), 1), 0);
|
||||
@@ -78,8 +80,8 @@ extensions.maxAge = function (maxAge, conf, options) {
|
||||
|
||||
conf.on("clear" + postfix, function () {
|
||||
forEach(timeouts, function (id) {
|
||||
clearTimeout(id);
|
||||
});
|
||||
clearTimeout(id);
|
||||
});
|
||||
timeouts = {};
|
||||
if (preFetchTimeouts) {
|
||||
forEach(preFetchTimeouts, function (id) {
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
/* eslint consistent-this: 0 */
|
||||
|
||||
// Support for functions returning promise
|
||||
|
||||
"use strict";
|
||||
|
||||
var objectMap = require("es5-ext/object/map")
|
||||
, isPromise = require("is-promise")
|
||||
, nextTick = require("next-tick")
|
||||
, nextTick = require("next-tick");
|
||||
|
||||
, create = Object.create, hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
var create = Object.create;
|
||||
|
||||
require("../lib/registered-extensions").promise = function (mode, conf) {
|
||||
var waiting = create(null), cache = create(null), promises = create(null);
|
||||
@@ -26,10 +28,12 @@ require("../lib/registered-extensions").promise = function (mode, conf) {
|
||||
var onSuccess = function (result) {
|
||||
var count = waiting[id];
|
||||
if (isFailed) {
|
||||
throw new Error("Memoizee error: Promise resolved with both failure and success," +
|
||||
" this can be result of unordered done & finally resolution.\n" +
|
||||
"Instead of `promise: true` consider configuring memoization via `promise: 'then'` or " +
|
||||
"`promise: 'done'");
|
||||
throw new Error(
|
||||
"Memoizee error: Promise resolved with both failure and success," +
|
||||
" this can be result of unordered done & finally resolution.\n" +
|
||||
"Instead of `promise: true` consider configuring memoization via " +
|
||||
"`promise: 'then'` or `promise: 'done'"
|
||||
);
|
||||
}
|
||||
if (!count) return; // Deleted from cache before resolved
|
||||
delete waiting[id];
|
||||
@@ -44,9 +48,9 @@ require("../lib/registered-extensions").promise = function (mode, conf) {
|
||||
conf.delete(id);
|
||||
};
|
||||
|
||||
if ((mode !== "then") && (typeof promise.done === "function")) {
|
||||
if (mode !== "then" && typeof promise.done === "function") {
|
||||
// Optimal promise resolution
|
||||
if ((mode !== "done") && (typeof promise.finally === "function")) {
|
||||
if (mode !== "done" && typeof promise.finally === "function") {
|
||||
// Use 'finally' to not register error handling (still proper behavior is subject to
|
||||
// used implementation, if library throws unconditionally even on handled errors
|
||||
// switch to 'then' mode)
|
||||
@@ -59,12 +63,16 @@ require("../lib/registered-extensions").promise = function (mode, conf) {
|
||||
}
|
||||
} else {
|
||||
// With no `done` it's best we can do.
|
||||
// Side effect is that it mutes any eventual "Unhandled error" events on returned promise
|
||||
promise.then(function (result) {
|
||||
nextTick(onSuccess.bind(this, result));
|
||||
}, function () {
|
||||
nextTick(onFailure);
|
||||
});
|
||||
// Side effect is that it mutes any eventual "Unhandled error" events
|
||||
// on returned promise
|
||||
promise.then(
|
||||
function (result) {
|
||||
nextTick(onSuccess.bind(this, result));
|
||||
},
|
||||
function () {
|
||||
nextTick(onFailure);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -77,15 +85,15 @@ require("../lib/registered-extensions").promise = function (mode, conf) {
|
||||
}
|
||||
promise = promises[id];
|
||||
var emit = function () {
|
||||
conf.emit("getasync", id, args, context);
|
||||
};
|
||||
conf.emit("getasync", id, args, context);
|
||||
};
|
||||
if (isPromise(promise)) {
|
||||
if (typeof promise.done === "function") promise.done(emit);
|
||||
else {
|
||||
promise.then(function () {
|
||||
nextTick(emit);
|
||||
});
|
||||
}
|
||||
promise.then(function () {
|
||||
nextTick(emit);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
emit();
|
||||
}
|
||||
@@ -110,8 +118,11 @@ require("../lib/registered-extensions").promise = function (mode, conf) {
|
||||
cache = create(null);
|
||||
waiting = create(null);
|
||||
promises = create(null);
|
||||
conf.emit("clearasync", objectMap(oldCache, function (data) {
|
||||
return [data];
|
||||
}));
|
||||
conf.emit(
|
||||
"clearasync",
|
||||
objectMap(oldCache, function (data) {
|
||||
return [data];
|
||||
})
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint no-eq-null: 0, eqeqeq: 0, no-unused-vars: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var customError = require("es5-ext/error/custom")
|
||||
@@ -5,16 +7,32 @@ var customError = require("es5-ext/error/custom")
|
||||
, d = require("d")
|
||||
, ee = require("event-emitter").methods
|
||||
, resolveResolve = require("./resolve-resolve")
|
||||
, resolveNormalize = require("./resolve-normalize")
|
||||
, resolveNormalize = require("./resolve-normalize");
|
||||
|
||||
, apply = Function.prototype.apply, call = Function.prototype.call
|
||||
, create = Object.create, hasOwnProperty = Object.prototype.hasOwnProperty
|
||||
var apply = Function.prototype.apply
|
||||
, call = Function.prototype.call
|
||||
, create = Object.create
|
||||
, defineProperties = Object.defineProperties
|
||||
, on = ee.on, emit = ee.emit;
|
||||
, on = ee.on
|
||||
, emit = ee.emit;
|
||||
|
||||
module.exports = function (original, length, options) {
|
||||
var cache = create(null), conf, memLength, get, set, del, clear, extDel,
|
||||
extGet, extHas, normalizer, getListeners, setListeners, deleteListeners, memoized, resolve;
|
||||
var cache = create(null)
|
||||
, conf
|
||||
, memLength
|
||||
, get
|
||||
, set
|
||||
, del
|
||||
, clear
|
||||
, extDel
|
||||
, extGet
|
||||
, extHas
|
||||
, normalizer
|
||||
, getListeners
|
||||
, setListeners
|
||||
, deleteListeners
|
||||
, memoized
|
||||
, resolve;
|
||||
if (length !== false) memLength = length;
|
||||
else if (isNaN(original.length)) memLength = 1;
|
||||
else memLength = original.length;
|
||||
@@ -59,8 +77,8 @@ module.exports = function (original, length, options) {
|
||||
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 (arguments.length) result = apply.call(original, this, arguments);
|
||||
else result = call.call(original, this);
|
||||
if (hasOwnProperty.call(cache, "data")) {
|
||||
throw customError("Circular invocation", "CIRCULAR_INVOCATION");
|
||||
}
|
||||
@@ -97,8 +115,8 @@ module.exports = function (original, length, options) {
|
||||
return String(args[0]);
|
||||
},
|
||||
has: function (id) {
|
||||
return hasOwnProperty.call(cache, id);
|
||||
},
|
||||
return hasOwnProperty.call(cache, id);
|
||||
},
|
||||
delete: function (id) {
|
||||
var result;
|
||||
if (!hasOwnProperty.call(cache, id)) return;
|
||||
@@ -121,8 +139,8 @@ module.exports = function (original, length, options) {
|
||||
},
|
||||
emit: emit,
|
||||
updateEnv: function () {
|
||||
original = conf.original;
|
||||
}
|
||||
original = conf.original;
|
||||
}
|
||||
};
|
||||
if (get) {
|
||||
extDel = defineLength(function (arg) {
|
||||
@@ -134,8 +152,8 @@ module.exports = function (original, length, options) {
|
||||
}, memLength);
|
||||
} else if (length === 0) {
|
||||
extDel = function () {
|
||||
return conf.delete("data");
|
||||
};
|
||||
return conf.delete("data");
|
||||
};
|
||||
} else {
|
||||
extDel = function (arg) {
|
||||
if (resolve) arg = resolve(arguments)[0];
|
||||
|
||||
@@ -9,13 +9,17 @@ var forEach = require("es5-ext/object/for-each")
|
||||
|
||||
module.exports = function (memoize) {
|
||||
return function (props) {
|
||||
forEach(props, function (desc, name) {
|
||||
forEach(props, function (desc) {
|
||||
var fn = callable(desc.value), length;
|
||||
desc.value = function (options) {
|
||||
if (options.getNormalizer) {
|
||||
options = normalizeOpts(options);
|
||||
if (length === undefined) {
|
||||
length = resolveLength(options.length, fn.length, options.async && extensions.async);
|
||||
length = resolveLength(
|
||||
options.length,
|
||||
fn.length,
|
||||
options.async && extensions.async
|
||||
);
|
||||
}
|
||||
options.normalizer = options.getNormalizer(length);
|
||||
delete options.getNormalizer;
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
"use strict";
|
||||
|
||||
var toArray = require("es5-ext/array/to-array")
|
||||
, callable = require("es5-ext/object/valid-callable")
|
||||
, isValue = require("es5-ext/object/is-value")
|
||||
, callable = require("es5-ext/object/valid-callable");
|
||||
|
||||
, slice = Array.prototype.slice
|
||||
, resolveArgs;
|
||||
var slice = Array.prototype.slice, resolveArgs;
|
||||
|
||||
resolveArgs = function (args) {
|
||||
return this.map(function (r, i) {
|
||||
return r ? r(args[i]) : args[i];
|
||||
return this.map(function (resolve, i) {
|
||||
return resolve ? resolve(args[i]) : args[i];
|
||||
}).concat(slice.call(args, this.length));
|
||||
};
|
||||
|
||||
module.exports = function (resolvers) {
|
||||
resolvers = toArray(resolvers);
|
||||
resolvers.forEach(function (r) {
|
||||
if (r != null) callable(r);
|
||||
resolvers.forEach(function (resolve) {
|
||||
if (isValue(resolve)) callable(resolve);
|
||||
});
|
||||
return resolveArgs.bind(resolvers);
|
||||
};
|
||||
|
||||
159
lib/weak.js
159
lib/weak.js
@@ -11,13 +11,12 @@ var customError = require("es5-ext/error/custom")
|
||||
, resolveLength = require("./resolve-length")
|
||||
, extensions = require("./registered-extensions")
|
||||
, resolveResolve = require("./resolve-resolve")
|
||||
, resolveNormalize = require("./resolve-normalize")
|
||||
, resolveNormalize = require("./resolve-normalize");
|
||||
|
||||
, slice = Array.prototype.slice, defineProperties = Object.defineProperties
|
||||
, hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
var slice = Array.prototype.slice, defineProperties = Object.defineProperties;
|
||||
|
||||
module.exports = function (memoize) {
|
||||
return function (fn/*, options*/) {
|
||||
return function (fn /*, options*/) {
|
||||
var map, length, options = normalizeOpts(arguments[1]), memoized, resolve, normalizer;
|
||||
|
||||
callable(fn);
|
||||
@@ -32,80 +31,104 @@ module.exports = function (memoize) {
|
||||
if (options.resolvers) resolve = resolveResolve(options.resolvers);
|
||||
if (options.normalizer) normalizer = resolveNormalize(options.normalizer);
|
||||
|
||||
if ((length === 1) && !normalizer && !options.async && !options.dispose && !options.maxAge &&
|
||||
!options.max && !options.refCounter) {
|
||||
return defineProperties(function (obj) {
|
||||
var result, args = arguments;
|
||||
if (resolve) args = resolve(args);
|
||||
obj = args[0];
|
||||
if (map.has(obj)) return map.get(obj);
|
||||
result = fn.apply(this, args);
|
||||
if (map.has(obj)) throw customError("Circular invocation", "CIRCULAR_INVOCATION");
|
||||
map.set(obj, result);
|
||||
return result;
|
||||
}, {
|
||||
__memoized__: d(true),
|
||||
delete: d(function (obj) {
|
||||
if (resolve) obj = resolve(arguments)[0];
|
||||
return map.delete(obj);
|
||||
})
|
||||
});
|
||||
}
|
||||
memoized = defineProperties(defineLength(function (obj) {
|
||||
var memoizer, args = arguments;
|
||||
if (resolve) {
|
||||
args = resolve(args);
|
||||
obj = args[0];
|
||||
}
|
||||
memoizer = map.get(obj);
|
||||
if (!memoizer) {
|
||||
if (normalizer) {
|
||||
options = copy(options);
|
||||
options.normalizer = copy(normalizer);
|
||||
options.normalizer.get = partial.call(options.normalizer.get, obj);
|
||||
options.normalizer.set = partial.call(options.normalizer.set, obj);
|
||||
if (options.normalizer.delete) {
|
||||
options.normalizer.delete = partial.call(options.normalizer.delete, obj);
|
||||
if (
|
||||
length === 1 &&
|
||||
!normalizer &&
|
||||
!options.async &&
|
||||
!options.dispose &&
|
||||
!options.maxAge &&
|
||||
!options.max &&
|
||||
!options.refCounter
|
||||
) {
|
||||
return defineProperties(
|
||||
function (obj) {
|
||||
var result, args = arguments;
|
||||
if (resolve) args = resolve(args);
|
||||
obj = args[0];
|
||||
if (map.has(obj)) return map.get(obj);
|
||||
result = fn.apply(this, args);
|
||||
if (map.has(obj)) {
|
||||
throw customError("Circular invocation", "CIRCULAR_INVOCATION");
|
||||
}
|
||||
map.set(obj, result);
|
||||
return result;
|
||||
},
|
||||
{
|
||||
__memoized__: d(true),
|
||||
delete: d(function (obj) {
|
||||
if (resolve) obj = resolve(arguments)[0];
|
||||
return map.delete(obj);
|
||||
})
|
||||
}
|
||||
map.set(obj, memoizer = memoize(partial.call(fn, obj), options));
|
||||
}
|
||||
return memoizer.apply(this, slice.call(args, 1));
|
||||
}, length), {
|
||||
__memoized__: d(true),
|
||||
delete: d(defineLength(function (obj) {
|
||||
);
|
||||
}
|
||||
memoized = defineProperties(
|
||||
defineLength(function (obj) {
|
||||
var memoizer, args = arguments;
|
||||
if (resolve) {
|
||||
args = resolve(args);
|
||||
obj = args[0];
|
||||
}
|
||||
memoizer = map.get(obj);
|
||||
if (!memoizer) return;
|
||||
memoizer.delete.apply(this, slice.call(args, 1));
|
||||
}, length))
|
||||
});
|
||||
if (!memoizer) {
|
||||
if (normalizer) {
|
||||
options = copy(options);
|
||||
options.normalizer = copy(normalizer);
|
||||
options.normalizer.get = partial.call(options.normalizer.get, obj);
|
||||
options.normalizer.set = partial.call(options.normalizer.set, obj);
|
||||
if (options.normalizer.delete) {
|
||||
options.normalizer.delete = partial.call(
|
||||
options.normalizer.delete,
|
||||
obj
|
||||
);
|
||||
}
|
||||
}
|
||||
map.set(obj, memoizer = memoize(partial.call(fn, obj), options));
|
||||
}
|
||||
return memoizer.apply(this, slice.call(args, 1));
|
||||
}, length),
|
||||
{
|
||||
__memoized__: d(true),
|
||||
delete: d(
|
||||
defineLength(function (obj) {
|
||||
var memoizer, args = arguments;
|
||||
if (resolve) {
|
||||
args = resolve(args);
|
||||
obj = args[0];
|
||||
}
|
||||
memoizer = map.get(obj);
|
||||
if (!memoizer) return;
|
||||
memoizer.delete.apply(this, slice.call(args, 1));
|
||||
}, length)
|
||||
)
|
||||
}
|
||||
);
|
||||
if (!options.refCounter) return memoized;
|
||||
defineProperties(memoized, {
|
||||
deleteRef: d(defineLength(function (obj) {
|
||||
var memoizer, args = arguments;
|
||||
if (resolve) {
|
||||
args = resolve(args);
|
||||
obj = args[0];
|
||||
}
|
||||
memoizer = map.get(obj);
|
||||
if (!memoizer) return null;
|
||||
return memoizer.deleteRef.apply(this, slice.call(args, 1));
|
||||
}, length)),
|
||||
getRefCount: d(defineLength(function (obj) {
|
||||
var memoizer, args = arguments;
|
||||
if (resolve) {
|
||||
args = resolve(args);
|
||||
obj = args[0];
|
||||
}
|
||||
memoizer = map.get(obj);
|
||||
if (!memoizer) return 0;
|
||||
return memoizer.getRefCount.apply(this, slice.call(args, 1));
|
||||
}, length))
|
||||
deleteRef: d(
|
||||
defineLength(function (obj) {
|
||||
var memoizer, args = arguments;
|
||||
if (resolve) {
|
||||
args = resolve(args);
|
||||
obj = args[0];
|
||||
}
|
||||
memoizer = map.get(obj);
|
||||
if (!memoizer) return null;
|
||||
return memoizer.deleteRef.apply(this, slice.call(args, 1));
|
||||
}, length)
|
||||
),
|
||||
getRefCount: d(
|
||||
defineLength(function (obj) {
|
||||
var memoizer, args = arguments;
|
||||
if (resolve) {
|
||||
args = resolve(args);
|
||||
obj = args[0];
|
||||
}
|
||||
memoizer = map.get(obj);
|
||||
if (!memoizer) return 0;
|
||||
return memoizer.getRefCount.apply(this, slice.call(args, 1));
|
||||
}, length)
|
||||
)
|
||||
});
|
||||
return memoized;
|
||||
};
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
module.exports = function (length) {
|
||||
if (!length) {
|
||||
return function () {
|
||||
return "";
|
||||
};
|
||||
return "";
|
||||
};
|
||||
}
|
||||
return function (args) {
|
||||
var id = String(args[0]), i = 0, l = length;
|
||||
while (--l) {
|
||||
id += "\u0001" + args[++i];
|
||||
}
|
||||
var id = String(args[0]), i = 0, currentLength = length;
|
||||
while (--currentLength) {
|
||||
id += "\u0001" + args[++i];
|
||||
}
|
||||
return id;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
/* eslint max-statements: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var indexOf = require("es5-ext/array/#/e-index-of")
|
||||
, create = Object.create;
|
||||
var indexOf = require("es5-ext/array/#/e-index-of");
|
||||
|
||||
var create = Object.create;
|
||||
|
||||
module.exports = function () {
|
||||
var lastId = 0, map = [], cache = create(null);
|
||||
@@ -10,7 +13,7 @@ module.exports = function () {
|
||||
var index = 0, set = map, i, length = args.length;
|
||||
if (length === 0) return set[length] || null;
|
||||
if ((set = set[length])) {
|
||||
while (index < (length - 1)) {
|
||||
while (index < length - 1) {
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) return null;
|
||||
set = set[1][i];
|
||||
@@ -31,7 +34,7 @@ module.exports = function () {
|
||||
set[length] = [[], []];
|
||||
}
|
||||
set = set[length];
|
||||
while (index < (length - 1)) {
|
||||
while (index < length - 1) {
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) {
|
||||
i = set[0].push(args[index]) - 1;
|
||||
@@ -50,12 +53,11 @@ module.exports = function () {
|
||||
return lastId;
|
||||
},
|
||||
delete: function (id) {
|
||||
var index = 0, set = map, i, args = cache[id], length = args.length
|
||||
, path = [];
|
||||
var index = 0, set = map, i, args = cache[id], length = args.length, path = [];
|
||||
if (length === 0) {
|
||||
delete set[length];
|
||||
} else if ((set = set[length])) {
|
||||
while (index < (length - 1)) {
|
||||
while (index < length - 1) {
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) {
|
||||
return;
|
||||
|
||||
106
package.json
106
package.json
@@ -1,53 +1,57 @@
|
||||
{
|
||||
"name": "memoizee",
|
||||
"version": "0.4.6",
|
||||
"description": "Memoize/cache function results",
|
||||
"author": "Mariusz Nowak <medikoo@medikoo.com> (http://www.medikoo.com/)",
|
||||
"keywords": [
|
||||
"memoize",
|
||||
"memoizer",
|
||||
"cache",
|
||||
"memoization",
|
||||
"memo",
|
||||
"memcached",
|
||||
"hashing.",
|
||||
"storage",
|
||||
"caching",
|
||||
"memory",
|
||||
"gc",
|
||||
"weak",
|
||||
"garbage",
|
||||
"collector",
|
||||
"async"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/medikoo/memoizee.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"d": "1",
|
||||
"es5-ext": "^0.10.13",
|
||||
"es6-weak-map": "^2.0.1",
|
||||
"event-emitter": "^0.3.4",
|
||||
"is-promise": "^2.1",
|
||||
"lru-queue": "0.1",
|
||||
"next-tick": "1",
|
||||
"timers-ext": "0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^4.2.0",
|
||||
"eslint-config-medikoo-es5": "^1.4.1",
|
||||
"plain-promise": "^0.1.1",
|
||||
"tad": "^0.2.7"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "medikoo-es5",
|
||||
"root": true
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint --ignore-path=.gitignore .",
|
||||
"lint-medikoo": "xlint --linter=node_modules/xlint-jslint-medikoo/index.js",
|
||||
"test": "tad"
|
||||
},
|
||||
"license": "MIT"
|
||||
"name": "memoizee",
|
||||
"version": "0.4.6",
|
||||
"description": "Memoize/cache function results",
|
||||
"author": "Mariusz Nowak <medikoo@medikoo.com> (http://www.medikoo.com/)",
|
||||
"keywords": [
|
||||
"memoize",
|
||||
"memoizer",
|
||||
"cache",
|
||||
"memoization",
|
||||
"memo",
|
||||
"memcached",
|
||||
"hashing.",
|
||||
"storage",
|
||||
"caching",
|
||||
"memory",
|
||||
"gc",
|
||||
"weak",
|
||||
"garbage",
|
||||
"collector",
|
||||
"async"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/medikoo/memoizee.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"d": "1",
|
||||
"es5-ext": "^0.10.13",
|
||||
"es6-weak-map": "^2.0.1",
|
||||
"event-emitter": "^0.3.4",
|
||||
"is-promise": "^2.1",
|
||||
"lru-queue": "0.1",
|
||||
"next-tick": "1",
|
||||
"timers-ext": "0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^4.2.0",
|
||||
"eslint-config-medikoo-es5": "^1.4.1",
|
||||
"plain-promise": "^0.1.1",
|
||||
"tad": "^0.2.7"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "medikoo-es5",
|
||||
"root": true,
|
||||
"globals": {
|
||||
"setTimeout": true,
|
||||
"clearTimeout": true
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint --ignore-path=.gitignore .",
|
||||
"lint-medikoo": "xlint --linter=node_modules/xlint-jslint-medikoo/index.js",
|
||||
"test": "tad"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
|
||||
10
plain.js
10
plain.js
@@ -4,11 +4,9 @@ var callable = require("es5-ext/object/valid-callable")
|
||||
, forEach = require("es5-ext/object/for-each")
|
||||
, extensions = require("./lib/registered-extensions")
|
||||
, configure = require("./lib/configure-map")
|
||||
, resolveLength = require("./lib/resolve-length")
|
||||
, resolveLength = require("./lib/resolve-length");
|
||||
|
||||
, hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
|
||||
module.exports = function self (fn/*, options */) {
|
||||
module.exports = function self (fn /*, options */) {
|
||||
var options, length, conf;
|
||||
|
||||
callable(fn);
|
||||
@@ -28,8 +26,8 @@ module.exports = function self (fn/*, options */) {
|
||||
conf = configure(fn, length, options);
|
||||
|
||||
// Bind eventual extensions
|
||||
forEach(extensions, function (fn, name) {
|
||||
if (options[name]) fn(options[name], conf, options);
|
||||
forEach(extensions, function (extFn, name) {
|
||||
if (options[name]) extFn(options[name], conf, options);
|
||||
});
|
||||
|
||||
if (self.__profiler__) self.__profiler__(conf);
|
||||
|
||||
131
profile.js
131
profile.js
@@ -2,40 +2,46 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var partial = require("es5-ext/function/#/partial")
|
||||
, forEach = require("es5-ext/object/for-each")
|
||||
, pad = require("es5-ext/string/#/pad")
|
||||
, compact = require("es5-ext/array/#/compact")
|
||||
, d = require("d")
|
||||
, memoize = require("./plain")
|
||||
var partial = require("es5-ext/function/#/partial")
|
||||
, forEach = require("es5-ext/object/for-each")
|
||||
, pad = require("es5-ext/string/#/pad")
|
||||
, compact = require("es5-ext/array/#/compact")
|
||||
, d = require("d")
|
||||
, memoize = require("./plain");
|
||||
|
||||
, max = Math.max
|
||||
, stats = exports.statistics = {};
|
||||
var max = Math.max, stats = exports.statistics = {};
|
||||
|
||||
Object.defineProperty(memoize, "__profiler__", d(function (conf) {
|
||||
var id, source, data, stack;
|
||||
stack = (new Error()).stack;
|
||||
if (!stack || !stack.split("\n").slice(3).some(function (line) {
|
||||
if ((line.indexOf("/memoizee/") === -1) &&
|
||||
(line.indexOf(" (native)") === -1)) {
|
||||
source = line.replace(/\n/g, "\\n").trim();
|
||||
return true;
|
||||
}
|
||||
})) {
|
||||
source = "unknown";
|
||||
}
|
||||
id = compact.call([conf.profileName, source]).join(", ");
|
||||
Object.defineProperty(
|
||||
memoize,
|
||||
"__profiler__",
|
||||
d(function (conf) {
|
||||
var id, source, data, stack;
|
||||
stack = new Error().stack;
|
||||
if (
|
||||
!stack ||
|
||||
!stack.split("\n").slice(3).some(function (line) {
|
||||
if (line.indexOf("/memoizee/") === -1 && line.indexOf(" (native)") === -1) {
|
||||
source = line.replace(/\n/g, "\\n").trim();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
) {
|
||||
source = "unknown";
|
||||
}
|
||||
id = compact.call([conf.profileName, source]).join(", ");
|
||||
|
||||
if (!stats[id]) stats[id] = { initial: 0, cached: 0 };
|
||||
data = stats[id];
|
||||
if (!stats[id]) stats[id] = { initial: 0, cached: 0 };
|
||||
data = stats[id];
|
||||
|
||||
conf.on("set", function () {
|
||||
++data.initial;
|
||||
});
|
||||
conf.on("get", function () {
|
||||
++data.cached;
|
||||
});
|
||||
}));
|
||||
conf.on("set", function () {
|
||||
++data.initial;
|
||||
});
|
||||
conf.on("get", function () {
|
||||
++data.cached;
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
exports.log = function () {
|
||||
var initial, cached, ordered, ipad, cpad, ppad, toPrc, log;
|
||||
@@ -43,41 +49,62 @@ exports.log = function () {
|
||||
initial = cached = 0;
|
||||
ordered = [];
|
||||
|
||||
toPrc = function (initial, cached) {
|
||||
if (!initial && !cached) {
|
||||
toPrc = function (initialCount, cachedCount) {
|
||||
if (!initialCount && !cachedCount) {
|
||||
return "0.00";
|
||||
}
|
||||
return ((cached / (initial + cached)) * 100).toFixed(2);
|
||||
return (cachedCount / (initialCount + cachedCount) * 100).toFixed(2);
|
||||
};
|
||||
|
||||
log = "------------------------------------------------------------\n";
|
||||
log += "Memoize statistics:\n\n";
|
||||
|
||||
forEach(stats, function (data, name) {
|
||||
initial += data.initial;
|
||||
cached += data.cached;
|
||||
ordered.push([name, data]);
|
||||
}, null, function (a, b) {
|
||||
return (this[b].initial + this[b].cached) -
|
||||
(this[a].initial + this[a].cached);
|
||||
});
|
||||
forEach(
|
||||
stats,
|
||||
function (data, name) {
|
||||
initial += data.initial;
|
||||
cached += data.cached;
|
||||
ordered.push([name, data]);
|
||||
},
|
||||
null,
|
||||
function (nameA, nameB) {
|
||||
return (
|
||||
this[nameB].initial +
|
||||
this[nameB].cached -
|
||||
(this[nameA].initial + this[nameA].cached)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipad = partial.call(pad, " ",
|
||||
max(String(initial).length, "Init".length));
|
||||
ipad = partial.call(pad, " ", max(String(initial).length, "Init".length));
|
||||
cpad = partial.call(pad, " ", max(String(cached).length, "Cache".length));
|
||||
ppad = partial.call(pad, " ", "%Cache".length);
|
||||
log += ipad.call("Init") + " " +
|
||||
cpad.call("Cache") + " " +
|
||||
ppad.call("%Cache") + " Source location\n";
|
||||
log += ipad.call(initial) + " " +
|
||||
cpad.call(cached) + " " +
|
||||
ppad.call(toPrc(initial, cached)) + " (all)\n";
|
||||
log +=
|
||||
ipad.call("Init") +
|
||||
" " +
|
||||
cpad.call("Cache") +
|
||||
" " +
|
||||
ppad.call("%Cache") +
|
||||
" Source location\n";
|
||||
log +=
|
||||
ipad.call(initial) +
|
||||
" " +
|
||||
cpad.call(cached) +
|
||||
" " +
|
||||
ppad.call(toPrc(initial, cached)) +
|
||||
" (all)\n";
|
||||
ordered.forEach(function (data) {
|
||||
var name = data[0];
|
||||
data = data[1];
|
||||
log += ipad.call(data.initial) + " " +
|
||||
cpad.call(data.cached) + " " +
|
||||
ppad.call(toPrc(data.initial, data.cached)) + " " + name + "\n";
|
||||
log +=
|
||||
ipad.call(data.initial) +
|
||||
" " +
|
||||
cpad.call(data.cached) +
|
||||
" " +
|
||||
ppad.call(toPrc(data.initial, data.cached)) +
|
||||
" " +
|
||||
name +
|
||||
"\n";
|
||||
});
|
||||
log += "------------------------------------------------------------\n";
|
||||
return log;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint id-length: 0, func-names: 0, handle-callback-err: 0, max-lines: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..")
|
||||
@@ -18,39 +20,67 @@ module.exports = function () {
|
||||
|
||||
mfn = memoize(fn, { async: true });
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}), u, "Initial");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}), u, "Initial #3");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}),
|
||||
u,
|
||||
"Initial"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Init Called");
|
||||
a(invoked, 5, "Cb Called");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Init Called #2");
|
||||
@@ -58,14 +88,22 @@ module.exports = function () {
|
||||
|
||||
mfn.delete(3, 7);
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 3, "Init After delete");
|
||||
@@ -87,31 +125,59 @@ module.exports = function () {
|
||||
|
||||
mfn = memoize(fn, { async: true, dispose: a.never });
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #1");
|
||||
}), u, "Initial");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #2");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result B #1");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #3");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result B #2");
|
||||
}), u, "Initial #3");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #1");
|
||||
}),
|
||||
u,
|
||||
"Initial"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result B #1");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #3");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result B #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 4, "Again Called #2");
|
||||
@@ -133,43 +199,79 @@ module.exports = function () {
|
||||
|
||||
mfn = memoize(fn, { async: true, primitive: true });
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}), u, "Initial");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}), u, "Initial #3");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}),
|
||||
u,
|
||||
"Initial"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Again Called #2");
|
||||
|
||||
mfn.delete(3, 7);
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 3, "Call After delete");
|
||||
@@ -190,31 +292,59 @@ module.exports = function () {
|
||||
|
||||
mfn = memoize(fn, { async: true, primitive: true });
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #1");
|
||||
}), u, "Initial");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #2");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result B #1");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #3");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result B #2");
|
||||
}), u, "Initial #3");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #1");
|
||||
}),
|
||||
u,
|
||||
"Initial"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result B #1");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #3");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result B #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 4, "Again Called #2");
|
||||
@@ -223,12 +353,16 @@ module.exports = function () {
|
||||
});
|
||||
},
|
||||
"Primitive null arg case": function (a, d) {
|
||||
var x = {}, mfn = memoize(function f (id, cb) {
|
||||
cb(null, x);
|
||||
}, {
|
||||
async: true,
|
||||
primitive: true
|
||||
});
|
||||
var x = {}
|
||||
, mfn = memoize(
|
||||
function f (id, cb) {
|
||||
cb(null, x);
|
||||
},
|
||||
{
|
||||
async: true,
|
||||
primitive: true
|
||||
}
|
||||
);
|
||||
|
||||
mfn(null, function (err, res) {
|
||||
a.deep([err, res], [null, x], "Args");
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint id-length: 0, max-lines: 0, max-statements: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..")
|
||||
@@ -10,13 +12,14 @@ module.exports = function () {
|
||||
Regular: {
|
||||
"Sync": function (a) {
|
||||
var mfn, fn, value = [], x, invoked;
|
||||
fn = function (x, y) {
|
||||
return x + y;
|
||||
};
|
||||
mfn = memoize(fn, { dispose: function (val) {
|
||||
value.push(val);
|
||||
} });
|
||||
|
||||
fn = function (arg1, arg2) {
|
||||
return arg1 + arg2;
|
||||
};
|
||||
mfn = memoize(fn, {
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
});
|
||||
mfn(3, 7);
|
||||
mfn(5, 8);
|
||||
mfn(12, 4);
|
||||
@@ -34,12 +37,16 @@ module.exports = function () {
|
||||
|
||||
x = {};
|
||||
invoked = false;
|
||||
mfn = memoize(function () {
|
||||
return x;
|
||||
},
|
||||
{ dispose: function (val) {
|
||||
invoked = val;
|
||||
} });
|
||||
mfn = memoize(
|
||||
function () {
|
||||
return x;
|
||||
},
|
||||
{
|
||||
dispose: function (val) {
|
||||
invoked = val;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
mfn.delete();
|
||||
a(invoked, false, "No args: Post invalid delete");
|
||||
@@ -51,12 +58,14 @@ module.exports = function () {
|
||||
"Ref counter": function (a) {
|
||||
var mfn, fn, value = [];
|
||||
fn = function (x, y) {
|
||||
return x + y;
|
||||
};
|
||||
mfn = memoize(fn, { refCounter: true,
|
||||
return x + y;
|
||||
};
|
||||
mfn = memoize(fn, {
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
} });
|
||||
value.push(val);
|
||||
}
|
||||
});
|
||||
|
||||
mfn(3, 7);
|
||||
mfn(5, 8);
|
||||
@@ -80,15 +89,17 @@ module.exports = function () {
|
||||
var mfn, fn, u = {}, value = [];
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
cb(null, x + y);
|
||||
});
|
||||
cb(null, x + y);
|
||||
});
|
||||
return u;
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { async: true,
|
||||
mfn = memoize(fn, {
|
||||
async: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
} });
|
||||
value.push(val);
|
||||
}
|
||||
});
|
||||
|
||||
mfn(3, 7, function () {
|
||||
mfn(5, 8, function () {
|
||||
@@ -114,32 +125,38 @@ module.exports = function () {
|
||||
var mfn, fn, value = [];
|
||||
fn = function (x, y) {
|
||||
return new Promise(function (res) {
|
||||
res(x + y);
|
||||
});
|
||||
res(x + y);
|
||||
});
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true,
|
||||
mfn = memoize(fn, {
|
||||
promise: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
} });
|
||||
value.push(val);
|
||||
}
|
||||
});
|
||||
|
||||
mfn(3, 7).done(function () {
|
||||
mfn(5, 8).done(function () {
|
||||
mfn(12, 4).done(delay(function () {
|
||||
a.deep(value, [], "Pre");
|
||||
mfn.delete(5, 8);
|
||||
a.deep(value, [13], "#1");
|
||||
value = [];
|
||||
mfn.delete(12, 4);
|
||||
a.deep(value, [16], "#2");
|
||||
mfn(12, 4).done(
|
||||
delay(function () {
|
||||
a.deep(value, [], "Pre");
|
||||
mfn.delete(5, 8);
|
||||
a.deep(value, [13], "#1");
|
||||
value = [];
|
||||
mfn.delete(12, 4);
|
||||
a.deep(value, [16], "#2");
|
||||
|
||||
value = [];
|
||||
mfn(77, 11).done(delay(function () {
|
||||
mfn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
d();
|
||||
}));
|
||||
}));
|
||||
value = [];
|
||||
mfn(77, 11).done(
|
||||
delay(function () {
|
||||
mfn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
d();
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -148,11 +165,13 @@ module.exports = function () {
|
||||
"Sync": function (a) {
|
||||
var mfn, fn, value = [];
|
||||
fn = function (x, y) {
|
||||
return x + y;
|
||||
};
|
||||
mfn = memoize(fn, { dispose: function (val) {
|
||||
value.push(val);
|
||||
} });
|
||||
return x + y;
|
||||
};
|
||||
mfn = memoize(fn, {
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
});
|
||||
|
||||
mfn(3, 7);
|
||||
mfn(5, 8);
|
||||
@@ -172,12 +191,14 @@ module.exports = function () {
|
||||
"Ref counter": function (a) {
|
||||
var mfn, fn, value = [];
|
||||
fn = function (x, y) {
|
||||
return x + y;
|
||||
};
|
||||
mfn = memoize(fn, { refCounter: true,
|
||||
return x + y;
|
||||
};
|
||||
mfn = memoize(fn, {
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
} });
|
||||
value.push(val);
|
||||
}
|
||||
});
|
||||
|
||||
mfn(3, 7);
|
||||
mfn(5, 8);
|
||||
@@ -201,15 +222,17 @@ module.exports = function () {
|
||||
var mfn, fn, u = {}, value = [];
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
cb(null, x + y);
|
||||
});
|
||||
cb(null, x + y);
|
||||
});
|
||||
return u;
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { async: true,
|
||||
mfn = memoize(fn, {
|
||||
async: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
} });
|
||||
value.push(val);
|
||||
}
|
||||
});
|
||||
|
||||
mfn(3, 7, function () {
|
||||
mfn(5, 8, function () {
|
||||
@@ -235,32 +258,38 @@ module.exports = function () {
|
||||
var mfn, fn, value = [];
|
||||
fn = function (x, y) {
|
||||
return new Promise(function (res) {
|
||||
res(x + y);
|
||||
});
|
||||
res(x + y);
|
||||
});
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true,
|
||||
mfn = memoize(fn, {
|
||||
promise: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
} });
|
||||
value.push(val);
|
||||
}
|
||||
});
|
||||
|
||||
mfn(3, 7).done(function () {
|
||||
mfn(5, 8).done(function () {
|
||||
mfn(12, 4).done(delay(function () {
|
||||
a.deep(value, [], "Pre");
|
||||
mfn.delete(5, 8);
|
||||
a.deep(value, [13], "#1");
|
||||
value = [];
|
||||
mfn.delete(12, 4);
|
||||
a.deep(value, [16], "#2");
|
||||
mfn(12, 4).done(
|
||||
delay(function () {
|
||||
a.deep(value, [], "Pre");
|
||||
mfn.delete(5, 8);
|
||||
a.deep(value, [13], "#1");
|
||||
value = [];
|
||||
mfn.delete(12, 4);
|
||||
a.deep(value, [16], "#2");
|
||||
|
||||
value = [];
|
||||
mfn(77, 11).done(delay(function () {
|
||||
mfn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
d();
|
||||
}));
|
||||
}));
|
||||
value = [];
|
||||
mfn(77, 11).done(
|
||||
delay(function () {
|
||||
mfn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
d();
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
/* eslint max-lines: 0, id-length: 0, func-names: 0, handle-callback-err: 0, max-lines: 0,
|
||||
no-unused-vars: 0, max-nested-callbacks: 0, no-shadow: 0, max-len: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..")
|
||||
@@ -12,7 +15,9 @@ module.exports = function () {
|
||||
return {
|
||||
Regular: {
|
||||
Sync: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
var mfn,
|
||||
fn,
|
||||
i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return x + y;
|
||||
@@ -56,7 +61,9 @@ module.exports = function () {
|
||||
}, 20);
|
||||
},
|
||||
Promise: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
var mfn,
|
||||
fn,
|
||||
i = 0;
|
||||
fn = function (x, y) {
|
||||
return new Promise(function (res) {
|
||||
++i;
|
||||
@@ -110,7 +117,10 @@ module.exports = function () {
|
||||
}, 20);
|
||||
},
|
||||
Async: function (a, d) {
|
||||
var mfn, fn, u = {}, i = 0;
|
||||
var mfn,
|
||||
fn,
|
||||
u = {},
|
||||
i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
++i;
|
||||
@@ -121,41 +131,77 @@ module.exports = function () {
|
||||
|
||||
mfn = memoize(fn, { async: true, maxAge: 100 });
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}), u, "Initial");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}), u, "Initial #3");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}),
|
||||
u,
|
||||
"Initial"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
);
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Again Called #2");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 4, "Call After clear");
|
||||
@@ -167,7 +213,9 @@ module.exports = function () {
|
||||
},
|
||||
Primitive: {
|
||||
Sync: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
var mfn,
|
||||
fn,
|
||||
i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return x + y;
|
||||
@@ -206,7 +254,10 @@ module.exports = function () {
|
||||
}, 20);
|
||||
},
|
||||
Async: function (a, d) {
|
||||
var mfn, fn, u = {}, i = 0;
|
||||
var mfn,
|
||||
fn,
|
||||
u = {},
|
||||
i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
++i;
|
||||
@@ -217,41 +268,77 @@ module.exports = function () {
|
||||
|
||||
mfn = memoize(fn, { async: true, primitive: true, maxAge: 100 });
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}), u, "Initial");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}), u, "Initial #3");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}),
|
||||
u,
|
||||
"Initial"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
);
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Again Called #2");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 4, "Call After clear");
|
||||
@@ -261,7 +348,9 @@ module.exports = function () {
|
||||
}, 20);
|
||||
},
|
||||
Promise: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
var mfn,
|
||||
fn,
|
||||
i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
return new Promise(function (res) {
|
||||
++i;
|
||||
@@ -317,7 +406,9 @@ module.exports = function () {
|
||||
},
|
||||
Refetch: {
|
||||
Default: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
var mfn,
|
||||
fn,
|
||||
i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return x + y;
|
||||
@@ -372,17 +463,18 @@ module.exports = function () {
|
||||
d();
|
||||
}, 200);
|
||||
}, 200);
|
||||
|
||||
}, 200);
|
||||
}, 300);
|
||||
},
|
||||
Async: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
var mfn,
|
||||
fn,
|
||||
i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
++i;
|
||||
setTimeout(function () {
|
||||
cb(null, x + y);
|
||||
}, 0);
|
||||
cb(null, x + y);
|
||||
}, 0);
|
||||
};
|
||||
mfn = memoize(fn, { maxAge: 600, preFetch: true, async: true });
|
||||
|
||||
@@ -416,42 +508,142 @@ module.exports = function () {
|
||||
a(result, 13, "Result: Wait After B");
|
||||
a(i, 3, "Called: Wait After B");
|
||||
mfn(3, 7, function (err, result) {
|
||||
a(result, 10, "Result: Wait After #2");
|
||||
a(
|
||||
result,
|
||||
10,
|
||||
"Result: Wait After #2"
|
||||
);
|
||||
a(i, 4, "Called: Wait After #2");
|
||||
mfn(5, 8, function (err, result) {
|
||||
a(result, 13, "Result: Wait After B #2");
|
||||
a(i, 4, "Called: Wait After B #2");
|
||||
a(
|
||||
result,
|
||||
13,
|
||||
"Result: Wait After B #2"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
4,
|
||||
"Called: Wait After B #2"
|
||||
);
|
||||
setTimeout(function () {
|
||||
a(i, 4, "Called: After Refetch: Before");
|
||||
mfn(3, 7, function (err, result) {
|
||||
a(result, 10, "Result: After Refetch");
|
||||
a(i, 4, "Called: After Refetch: After");
|
||||
mfn(5, 8, function (err, result) {
|
||||
a(result, 13, "Result: After Refetch B");
|
||||
a(i, 4, "Called: After Refetch B: After");
|
||||
setTimeout(function () {
|
||||
mfn(3, 7, function (err, result) {
|
||||
a(result, 10, "Result: After Refetch #2");
|
||||
a(i, 4, "Called: After Refetch #2");
|
||||
mfn(5, 8, function (err, result) {
|
||||
a(result, 13, "Result: After Refetch #2 B");
|
||||
a(i, 5, "Called: After Refetch #2 B");
|
||||
mfn(3, 7, function (err, result) {
|
||||
a(result, 10, "Result: After Refetch #3");
|
||||
a(i, 6, "Called: After Refetch #3");
|
||||
mfn(5, 8, function (err, result) {
|
||||
a(result, 13, "Result: After Refetch #3 B");
|
||||
a(i, 6, "Called: After Refetch #3 B");
|
||||
d();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 200);
|
||||
a(
|
||||
i,
|
||||
4,
|
||||
"Called: After Refetch: Before"
|
||||
);
|
||||
mfn(3, 7, function (
|
||||
err,
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
10,
|
||||
"Result: After Refetch"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
4,
|
||||
"Called: After Refetch: After"
|
||||
);
|
||||
mfn(5, 8, function (
|
||||
err,
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
13,
|
||||
"Result: After Refetch B"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
4,
|
||||
"Called: After Refetch B: After"
|
||||
);
|
||||
setTimeout(
|
||||
function () {
|
||||
mfn(
|
||||
3,
|
||||
7,
|
||||
function (
|
||||
err,
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
10,
|
||||
"Result: After Refetch #2"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
4,
|
||||
"Called: After Refetch #2"
|
||||
);
|
||||
mfn(
|
||||
5,
|
||||
8,
|
||||
function (
|
||||
err,
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
13,
|
||||
"Result: After Refetch #2 B"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
5,
|
||||
"Called: After Refetch #2 B"
|
||||
);
|
||||
mfn(
|
||||
3,
|
||||
7,
|
||||
function (
|
||||
err,
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
10,
|
||||
"Result: After Refetch #3"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
6,
|
||||
"Called: After Refetch #3"
|
||||
);
|
||||
mfn(
|
||||
5,
|
||||
8,
|
||||
function (
|
||||
err,
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
13,
|
||||
"Result: After Refetch #3 B"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
6,
|
||||
"Called: After Refetch #3 B"
|
||||
);
|
||||
d();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
200
|
||||
);
|
||||
});
|
||||
});
|
||||
}, 200);
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -465,15 +657,16 @@ module.exports = function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
},
|
||||
Promise: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
var mfn,
|
||||
fn,
|
||||
i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return new Promise(function (res) {
|
||||
res(x + y);
|
||||
});
|
||||
res(x + y);
|
||||
});
|
||||
};
|
||||
mfn = memoize(fn, { maxAge: 600, preFetch: true, promise: true });
|
||||
|
||||
@@ -500,53 +693,186 @@ module.exports = function () {
|
||||
a(result, 13, "Result: Wait B");
|
||||
a(i, 2, "Called: Wait B");
|
||||
setTimeout(function () {
|
||||
mfn(3, 7).done(delay(function (result) {
|
||||
a(result, 10, "Result: Wait After");
|
||||
a(i, 3, "Called: Wait After");
|
||||
mfn(5, 8).done(delay(function (result) {
|
||||
a(result, 13, "Result: Wait After B");
|
||||
a(i, 4, "Called: Wait After B");
|
||||
mfn(3, 7).done(delay(function (result) {
|
||||
a(result, 10, "Result: Wait After #2");
|
||||
a(i, 4, "Called: Wait After #2");
|
||||
mfn(5, 8).done(function (result) {
|
||||
a(result, 13, "Result: Wait After B #2");
|
||||
a(i, 4, "Called: Wait After B #2");
|
||||
setTimeout(function () {
|
||||
a(i, 4, "Called: After Refetch: Before");
|
||||
mfn(3, 7).done(function (result) {
|
||||
a(result, 10, "Result: After Refetch");
|
||||
a(i, 4, "Called: After Refetch: After");
|
||||
mfn(5, 8).done(function (result) {
|
||||
a(result, 13, "Result: After Refetch B");
|
||||
a(i, 4, "Called: After Refetch B: After");
|
||||
setTimeout(function () {
|
||||
mfn(3, 7).done(delay(function (result) {
|
||||
a(result, 10, "Result: After Refetch #2");
|
||||
a(i, 5, "Called: After Refetch #2");
|
||||
mfn(5, 8).done(delay(function (result) {
|
||||
a(result, 13, "Result: After Refetch #2 B");
|
||||
a(i, 6, "Called: After Refetch #2 B");
|
||||
mfn(3, 7).done(function (result) {
|
||||
a(result, 10, "Result: After Refetch #3");
|
||||
a(i, 6, "Called: After Refetch #3");
|
||||
mfn(5, 8).done(function (result) {
|
||||
a(result, 13, "Result: After Refetch #3 B");
|
||||
a(i, 6, "Called: After Refetch #3 B");
|
||||
d();
|
||||
});
|
||||
});
|
||||
}, 0));
|
||||
}, 0));
|
||||
}, 200);
|
||||
mfn(3, 7).done(
|
||||
delay(function (result) {
|
||||
a(result, 10, "Result: Wait After");
|
||||
a(i, 3, "Called: Wait After");
|
||||
mfn(5, 8).done(
|
||||
delay(function (result) {
|
||||
a(
|
||||
result,
|
||||
13,
|
||||
"Result: Wait After B"
|
||||
);
|
||||
a(i, 4, "Called: Wait After B");
|
||||
mfn(3, 7).done(
|
||||
delay(function (result) {
|
||||
a(
|
||||
result,
|
||||
10,
|
||||
"Result: Wait After #2"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
4,
|
||||
"Called: Wait After #2"
|
||||
);
|
||||
mfn(5, 8).done(function (
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
13,
|
||||
"Result: Wait After B #2"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
4,
|
||||
"Called: Wait After B #2"
|
||||
);
|
||||
setTimeout(
|
||||
function () {
|
||||
a(
|
||||
i,
|
||||
4,
|
||||
"Called: After Refetch: Before"
|
||||
);
|
||||
mfn(
|
||||
3,
|
||||
7
|
||||
).done(
|
||||
function (
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
10,
|
||||
"Result: After Refetch"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
4,
|
||||
"Called: After Refetch: After"
|
||||
);
|
||||
mfn(
|
||||
5,
|
||||
8
|
||||
).done(
|
||||
function (
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
13,
|
||||
"Result: After Refetch B"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
4,
|
||||
"Called: After Refetch B: After"
|
||||
);
|
||||
setTimeout(
|
||||
function () {
|
||||
mfn(
|
||||
3,
|
||||
7
|
||||
).done(
|
||||
delay(
|
||||
function (
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
10,
|
||||
"Result: After Refetch #2"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
5,
|
||||
"Called: After Refetch #2"
|
||||
);
|
||||
mfn(
|
||||
5,
|
||||
8
|
||||
).done(
|
||||
delay(
|
||||
function (
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
13,
|
||||
"Result: After Refetch #2 B"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
6,
|
||||
"Called: After Refetch #2 B"
|
||||
);
|
||||
mfn(
|
||||
3,
|
||||
7
|
||||
).done(
|
||||
function (
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
10,
|
||||
"Result: After Refetch #3"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
6,
|
||||
"Called: After Refetch #3"
|
||||
);
|
||||
mfn(
|
||||
5,
|
||||
8
|
||||
).done(
|
||||
function (
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
13,
|
||||
"Result: After Refetch #3 B"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
6,
|
||||
"Called: After Refetch #3 B"
|
||||
);
|
||||
d();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
0
|
||||
)
|
||||
);
|
||||
},
|
||||
0
|
||||
)
|
||||
);
|
||||
},
|
||||
200
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
200
|
||||
);
|
||||
});
|
||||
});
|
||||
}, 200);
|
||||
|
||||
});
|
||||
}));
|
||||
}, 0));
|
||||
}, 0));
|
||||
})
|
||||
);
|
||||
}, 0)
|
||||
);
|
||||
}, 0)
|
||||
);
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
@@ -556,10 +882,11 @@ module.exports = function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
},
|
||||
Custom: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
var mfn,
|
||||
fn,
|
||||
i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return x + y;
|
||||
@@ -613,7 +940,6 @@ module.exports = function () {
|
||||
d();
|
||||
}, 200);
|
||||
}, 300);
|
||||
|
||||
}, 100);
|
||||
}, 450);
|
||||
}
|
||||
|
||||
1783
test/ext/max.js
1783
test/ext/max.js
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,5 @@
|
||||
/* eslint id-length: 0, handle-callback-err: 0, no-undef: 0, no-unused-vars: 0, func-names: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..")
|
||||
@@ -219,14 +221,17 @@ module.exports = function () {
|
||||
},
|
||||
"Primitive null arg case": function (a, d) {
|
||||
var mfn, x = {};
|
||||
mfn = memoize(function f (id) {
|
||||
return new Promise(function (res) {
|
||||
res(x);
|
||||
});
|
||||
}, {
|
||||
promise: true,
|
||||
primitive: true
|
||||
});
|
||||
mfn = memoize(
|
||||
function f (id) {
|
||||
return new Promise(function (res) {
|
||||
res(x);
|
||||
});
|
||||
},
|
||||
{
|
||||
promise: true,
|
||||
primitive: true
|
||||
}
|
||||
);
|
||||
|
||||
mfn(null).done(function (res) {
|
||||
a.deep(res, x, "Args");
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint max-lines: 0, id-length: 0, no-undef: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..")
|
||||
@@ -7,9 +9,12 @@ var memoize = require("../..")
|
||||
module.exports = function () {
|
||||
return {
|
||||
"Regular": function (a) {
|
||||
var i = 0, fn = function (x, y, z) {
|
||||
++i; return x + y + z;
|
||||
}, mfn;
|
||||
var i = 0
|
||||
, fn = function (x, y, z) {
|
||||
++i;
|
||||
return x + y + z;
|
||||
}
|
||||
, mfn;
|
||||
mfn = memoize(fn, { refCounter: true });
|
||||
a(mfn.deleteRef(3, 5, 7), null, "Delete before");
|
||||
a(mfn(3, 5, 7), 15, "Initial");
|
||||
@@ -42,31 +47,59 @@ module.exports = function () {
|
||||
|
||||
a(mfn.deleteRef(3, 7), null, "Delete ref before");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}), u, "Initial");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}), u, "Initial #3");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}),
|
||||
u,
|
||||
"Initial"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Again Called #2");
|
||||
@@ -76,12 +109,20 @@ module.exports = function () {
|
||||
a(mfn.deleteRef(3, 7), false, "Delete ref #3");
|
||||
a(mfn.deleteRef(3, 7), true, "Delete ref Final");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 3, "Call After delete");
|
||||
@@ -95,8 +136,8 @@ module.exports = function () {
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return new Promise(function (res) {
|
||||
res(x + y);
|
||||
});
|
||||
res(x + y);
|
||||
});
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true, refCounter: true });
|
||||
@@ -152,9 +193,12 @@ module.exports = function () {
|
||||
}, 10);
|
||||
},
|
||||
"Primitive": function (a) {
|
||||
var i = 0, fn = function (x, y, z) {
|
||||
++i; return x + y + z;
|
||||
}, mfn;
|
||||
var i = 0
|
||||
, fn = function (x, y, z) {
|
||||
++i;
|
||||
return x + y + z;
|
||||
}
|
||||
, mfn;
|
||||
mfn = memoize(fn, { primitive: true, refCounter: true });
|
||||
a(mfn.deleteRef(3, 5, 7), null, "Delete before");
|
||||
a(mfn(3, 5, 7), 15, "Initial");
|
||||
@@ -187,31 +231,59 @@ module.exports = function () {
|
||||
|
||||
a(mfn.deleteRef(3, 7), null, "Delete ref before");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}), u, "Initial");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}), u, "Initial #2");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}), u, "Initial #3");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}),
|
||||
u,
|
||||
"Initial"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Again Called #2");
|
||||
@@ -221,12 +293,20 @@ module.exports = function () {
|
||||
a(mfn.deleteRef(3, 7), false, "Delete ref #3");
|
||||
a(mfn.deleteRef(3, 7), true, "Delete ref Final");
|
||||
|
||||
a(mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}), u, "Again: Initial");
|
||||
a(mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}), u, "Again B: Initial");
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 3, "Call After delete");
|
||||
@@ -240,8 +320,8 @@ module.exports = function () {
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return new Promise(function (res) {
|
||||
res(x + y);
|
||||
});
|
||||
res(x + y);
|
||||
});
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true, primitive: true, refCounter: true });
|
||||
|
||||
2065
test/index.js
2065
test/index.js
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,5 @@
|
||||
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var aFrom = require("es5-ext/array/from")
|
||||
@@ -6,39 +8,55 @@ var aFrom = require("es5-ext/array/from")
|
||||
module.exports = function () {
|
||||
return {
|
||||
"One arg": function (a) {
|
||||
var i = 0, fn = function (x) {
|
||||
++i; return x;
|
||||
}, mfn
|
||||
, y = { toString: function () {
|
||||
return "foo";
|
||||
} };
|
||||
var i = 0
|
||||
, fn = function (x) {
|
||||
++i;
|
||||
return x;
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
mfn = memoize(fn, { primitive: true });
|
||||
a(mfn(y), y, "#1");
|
||||
a(mfn("foo"), y, "#2");
|
||||
a(i, 1, "Called once");
|
||||
},
|
||||
"Clear cache": function (a) {
|
||||
var i = 0, fn = function (x, y, z) {
|
||||
++i; return x + y + z;
|
||||
}, mfn
|
||||
, y = { toString: function () {
|
||||
return "foo";
|
||||
} };
|
||||
var i = 0
|
||||
, fn = function (x, y, z) {
|
||||
++i;
|
||||
return x + y + z;
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
mfn = memoize(fn, { primitive: true });
|
||||
a(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
|
||||
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
|
||||
a(i, 1, "Called once");
|
||||
mfn.delete("foo", { toString: function () {
|
||||
return "bar";
|
||||
} },
|
||||
"zeta");
|
||||
mfn.delete(
|
||||
"foo",
|
||||
{
|
||||
toString: function () {
|
||||
return "bar";
|
||||
}
|
||||
},
|
||||
"zeta"
|
||||
);
|
||||
a(mfn(y, "bar", "zeta"), "foobarzeta", "#3");
|
||||
a(i, 2, "Called twice");
|
||||
},
|
||||
"_get": function (a) {
|
||||
var fn = function (x) {
|
||||
return x;
|
||||
}, mfn;
|
||||
return x;
|
||||
}
|
||||
, mfn;
|
||||
mfn = memoize(fn);
|
||||
a(mfn._get("foo"), undefined);
|
||||
mfn("foo");
|
||||
@@ -46,8 +64,9 @@ module.exports = function () {
|
||||
},
|
||||
"_has": function (a) {
|
||||
var fn = function (x) {
|
||||
return x;
|
||||
}, mfn;
|
||||
return x;
|
||||
}
|
||||
, mfn;
|
||||
mfn = memoize(fn);
|
||||
a(mfn._has("foo"), false);
|
||||
mfn("foo");
|
||||
@@ -72,10 +91,13 @@ module.exports = function () {
|
||||
},
|
||||
"Resolvers": function () {
|
||||
var i = 0, fn, r;
|
||||
fn = memoize(function () {
|
||||
++i; return arguments;
|
||||
},
|
||||
{ length: 3, resolvers: [Boolean, String] });
|
||||
fn = memoize(
|
||||
function () {
|
||||
++i;
|
||||
return arguments;
|
||||
},
|
||||
{ length: 3, resolvers: [Boolean, String] }
|
||||
);
|
||||
return {
|
||||
"No args": function (a) {
|
||||
i = 0;
|
||||
@@ -85,9 +107,13 @@ module.exports = function () {
|
||||
a(i, 1, "Called once");
|
||||
},
|
||||
"One arg": function (a) {
|
||||
var fn = memoize(function (elo) {
|
||||
++i; return arguments;
|
||||
}, { resolvers: [Boolean] });
|
||||
var fn = memoize(
|
||||
function (elo) {
|
||||
++i;
|
||||
return arguments;
|
||||
},
|
||||
{ resolvers: [Boolean] }
|
||||
);
|
||||
a.deep(aFrom(r = fn("elo")), [true], "First");
|
||||
},
|
||||
"Some Args": function (a) {
|
||||
@@ -99,8 +125,7 @@ module.exports = function () {
|
||||
a(i, 1, "Called once");
|
||||
return {
|
||||
Other: function (a) {
|
||||
a.deep(aFrom(r = fn(1, 34, x, 34)),
|
||||
[true, "34", x, 34], "Second");
|
||||
a.deep(aFrom(r = fn(1, 34, x, 34)), [true, "34", x, 34], "Second");
|
||||
a(fn(1, 34, x, 89), r, "Third");
|
||||
a(i, 2, "Called once");
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint id-length: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var d = require("d")
|
||||
@@ -9,15 +11,23 @@ require("../ext/ref-counter");
|
||||
module.exports = function (t, a) {
|
||||
var value = [], obj = {};
|
||||
t = t(memoize);
|
||||
Object.defineProperties(obj, t({
|
||||
someFn: d(function (x, y) {
|
||||
a(this, obj); return x + y;
|
||||
},
|
||||
{ refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
} })
|
||||
}));
|
||||
Object.defineProperties(
|
||||
obj,
|
||||
t({
|
||||
someFn: d(
|
||||
function (x, y) {
|
||||
a(this, obj);
|
||||
return x + y;
|
||||
},
|
||||
{
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
obj = Object.create(obj);
|
||||
obj.someFn(3, 7);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint no-empty-function: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = function (t, a) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..");
|
||||
@@ -8,13 +10,18 @@ require("../ext/ref-counter");
|
||||
module.exports = function (t, a) {
|
||||
var value = [], obj = {}, memoized, count = 0, x, y, z;
|
||||
t = t(memoize);
|
||||
memoized = t(function (arg, x, y) {
|
||||
a(arg, obj); return x + y;
|
||||
},
|
||||
{ refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
} });
|
||||
memoized = t(
|
||||
function (arg, x, y) {
|
||||
a(arg, obj);
|
||||
return x + y;
|
||||
},
|
||||
{
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
a(memoized(obj, 3, 7), 10);
|
||||
a(memoized(obj, 5, 8), 13);
|
||||
@@ -36,8 +43,8 @@ dispose: function (val) {
|
||||
y = {};
|
||||
z = {};
|
||||
memoized = t(function (arg) {
|
||||
return ++count;
|
||||
});
|
||||
return ++count;
|
||||
});
|
||||
a(memoized(x), 1);
|
||||
a(memoized(y), 2);
|
||||
a(memoized(x), 1);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint id-length: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var d = require("d");
|
||||
@@ -7,15 +9,23 @@ require("../ext/ref-counter");
|
||||
|
||||
module.exports = function (t, a) {
|
||||
var value = [], obj = {};
|
||||
Object.defineProperties(obj, t({
|
||||
someFn: d(function (x, y) {
|
||||
a(this, obj); return x + y;
|
||||
},
|
||||
{ refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
} })
|
||||
}));
|
||||
Object.defineProperties(
|
||||
obj,
|
||||
t({
|
||||
someFn: d(
|
||||
function (x, y) {
|
||||
a(this, obj);
|
||||
return x + y;
|
||||
},
|
||||
{
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
obj = Object.create(obj);
|
||||
obj.someFn(3, 7);
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
/* eslint id-length: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var d = require("d");
|
||||
|
||||
module.exports = function (t, a) {
|
||||
var value = [], obj = {};
|
||||
Object.defineProperties(obj, t({
|
||||
someFn: d(function (x, y) {
|
||||
a(this, obj); return x + y;
|
||||
},
|
||||
{ refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
} })
|
||||
}));
|
||||
Object.defineProperties(
|
||||
obj,
|
||||
t({
|
||||
someFn: d(
|
||||
function (x, y) {
|
||||
a(this, obj);
|
||||
return x + y;
|
||||
},
|
||||
{
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
obj = Object.create(obj);
|
||||
obj.someFn(3, 7);
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..");
|
||||
|
||||
module.exports = {
|
||||
"": function (t, a) {
|
||||
var i = 0, fn = function (x) {
|
||||
++i; return x;
|
||||
};
|
||||
var i = 0
|
||||
, fn = function (x) {
|
||||
++i;
|
||||
return x;
|
||||
};
|
||||
|
||||
fn = memoize(fn);
|
||||
return {
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..");
|
||||
|
||||
module.exports = {
|
||||
"": function (a) {
|
||||
var i = 0, fn = function (x, y, z) {
|
||||
++i; return [x, y, z];
|
||||
}, r;
|
||||
var i = 0
|
||||
, fn = function (x, y, z) {
|
||||
++i;
|
||||
return [x, y, z];
|
||||
}
|
||||
, r;
|
||||
|
||||
fn = memoize(fn);
|
||||
return {
|
||||
|
||||
@@ -1,35 +1,52 @@
|
||||
/* eslint id-length: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..");
|
||||
|
||||
module.exports = {
|
||||
"": function (a) {
|
||||
var i = 0, fn = function (x, y, z) {
|
||||
++i; return x + y + z;
|
||||
}, mfn
|
||||
, y = { toString: function () {
|
||||
return "foo";
|
||||
} };
|
||||
var i = 0
|
||||
, fn = function (x, y, z) {
|
||||
++i;
|
||||
return x + y + z;
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
mfn = memoize(fn, { primitive: true });
|
||||
a(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
|
||||
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
|
||||
a(i, 1, "Called once");
|
||||
},
|
||||
"Delete": function (a) {
|
||||
var i = 0, fn = function (x, y, z) {
|
||||
++i; return x + y + z;
|
||||
}, mfn
|
||||
, y = { toString: function () {
|
||||
return "foo";
|
||||
} };
|
||||
var i = 0
|
||||
, fn = function (x, y, z) {
|
||||
++i;
|
||||
return x + y + z;
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
mfn = memoize(fn, { primitive: true });
|
||||
a(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
|
||||
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
|
||||
a(i, 1, "Called once");
|
||||
mfn.delete("foo", { toString: function () {
|
||||
return "bar";
|
||||
} },
|
||||
"zeta");
|
||||
mfn.delete(
|
||||
"foo",
|
||||
{
|
||||
toString: function () {
|
||||
return "bar";
|
||||
}
|
||||
},
|
||||
"zeta"
|
||||
);
|
||||
a(mfn(y, "bar", "zeta"), "foobarzeta", "#3");
|
||||
a(i, 2, "Called twice");
|
||||
},
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var aFrom = require("es5-ext/array/from")
|
||||
@@ -6,9 +8,12 @@ var aFrom = require("es5-ext/array/from")
|
||||
module.exports = function () {
|
||||
return {
|
||||
"": function (a) {
|
||||
var i = 0, fn = function () {
|
||||
++i; return arguments;
|
||||
}, r;
|
||||
var i = 0
|
||||
, fn = function () {
|
||||
++i;
|
||||
return arguments;
|
||||
}
|
||||
, r;
|
||||
|
||||
fn = memoize(fn, { length: false });
|
||||
return {
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
/* eslint id-length: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..")
|
||||
|
||||
, join = Array.prototype.join;
|
||||
, join = Array.prototype.join;
|
||||
|
||||
module.exports = function (a) {
|
||||
var i = 0, fn = function () {
|
||||
++i; return join.call(arguments, "|");
|
||||
}
|
||||
, y = { toString: function () {
|
||||
return "foo";
|
||||
} }, mfn;
|
||||
var i = 0
|
||||
, fn = function () {
|
||||
++i;
|
||||
return join.call(arguments, "|");
|
||||
}
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
}
|
||||
, mfn;
|
||||
mfn = memoize(fn, { primitive: true, length: false });
|
||||
a(mfn(y, "bar", "zeta"), "foo|bar|zeta", "#1");
|
||||
a(mfn("foo", "bar", "zeta"), "foo|bar|zeta", "#2");
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
/* eslint id-length: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = function (t) {
|
||||
return {
|
||||
"": function (a) {
|
||||
var i = 0, fn = function (x) {
|
||||
++i; return x;
|
||||
}, mfn
|
||||
, y = { toString: function () {
|
||||
return "foo";
|
||||
} };
|
||||
var i = 0
|
||||
, fn = function (x) {
|
||||
++i;
|
||||
return x;
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
mfn = t(fn, { primitive: true });
|
||||
a(typeof mfn, "function", "Returns");
|
||||
a(mfn.__memoized__, true, "Marked");
|
||||
@@ -18,20 +25,30 @@ module.exports = function (t) {
|
||||
a(i, 1, "Called once");
|
||||
},
|
||||
"Clear cache": function (a) {
|
||||
var i = 0, fn = function (x, y, z) {
|
||||
++i; return x + y + z;
|
||||
}, mfn
|
||||
, y = { toString: function () {
|
||||
return "foo";
|
||||
} };
|
||||
var i = 0
|
||||
, fn = function (x, y, z) {
|
||||
++i;
|
||||
return x + y + z;
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
mfn = t(fn, { primitive: true });
|
||||
a(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
|
||||
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
|
||||
a(i, 1, "Called once");
|
||||
mfn.delete("foo", { toString: function () {
|
||||
return "bar";
|
||||
} },
|
||||
"zeta");
|
||||
mfn.delete(
|
||||
"foo",
|
||||
{
|
||||
toString: function () {
|
||||
return "bar";
|
||||
}
|
||||
},
|
||||
"zeta"
|
||||
);
|
||||
a(mfn(y, "bar", "zeta"), "foobarzeta", "#3");
|
||||
a(i, 2, "Called twice");
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint no-empty-function: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../plain");
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
require("../ext/dispose");
|
||||
@@ -5,13 +7,18 @@ require("../ext/ref-counter");
|
||||
|
||||
module.exports = function (t, a) {
|
||||
var value = [], obj = {}, memoized, count = 0, x, y, z;
|
||||
memoized = t(function (arg, x, y) {
|
||||
a(arg, obj); return x + y;
|
||||
},
|
||||
{ refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
} });
|
||||
memoized = t(
|
||||
function (arg, x, y) {
|
||||
a(arg, obj);
|
||||
return x + y;
|
||||
},
|
||||
{
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
a(memoized(obj, 3, 7), 10);
|
||||
a(memoized(obj, 5, 8), 13);
|
||||
@@ -33,8 +40,8 @@ dispose: function (val) {
|
||||
y = {};
|
||||
z = {};
|
||||
memoized = t(function (arg) {
|
||||
return ++count;
|
||||
});
|
||||
return ++count;
|
||||
});
|
||||
a(memoized(x), 1);
|
||||
a(memoized(y), 2);
|
||||
a(memoized(x), 1);
|
||||
|
||||
34
test/weak.js
34
test/weak.js
@@ -1,14 +1,21 @@
|
||||
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = function (t, a, d) {
|
||||
var value = [], obj = {}, memoized, count = 0, x, y, z;
|
||||
memoized = t(function (arg, x, y) {
|
||||
a(arg, obj); return x + y;
|
||||
},
|
||||
{ refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
} });
|
||||
memoized = t(
|
||||
function (arg, x, y) {
|
||||
a(arg, obj);
|
||||
return x + y;
|
||||
},
|
||||
{
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
a(memoized(obj, 3, 7), 10);
|
||||
a(memoized(obj, 5, 8), 13);
|
||||
@@ -30,8 +37,8 @@ dispose: function (val) {
|
||||
y = {};
|
||||
z = {};
|
||||
memoized = t(function (arg) {
|
||||
return ++count;
|
||||
});
|
||||
return ++count;
|
||||
});
|
||||
a(memoized(x), 1);
|
||||
a(memoized(y), 2);
|
||||
a(memoized(x), 1);
|
||||
@@ -39,9 +46,12 @@ dispose: function (val) {
|
||||
a(count, 3);
|
||||
|
||||
count = 0;
|
||||
memoized = t(function (arg) {
|
||||
return ++count;
|
||||
}, { maxAge: 1 });
|
||||
memoized = t(
|
||||
function (arg) {
|
||||
return ++count;
|
||||
},
|
||||
{ maxAge: 1 }
|
||||
);
|
||||
|
||||
memoized(obj);
|
||||
setTimeout(function () {
|
||||
|
||||
Reference in New Issue
Block a user