mirror of
https://github.com/BreizhHardware/memoizee.git
synced 2026-01-18 16:37:21 +01:00
- Move out main modules from `lib` folder - Introduce `normalizer` based configurations, and convert primitive and regular handlers into thos normalizers (can be found in lib/normalizers folder). Custom normalizers can be provided at run time via `normaizer` option - Provide `plain` module which does not load any extensions or normalizers. Any extensions that have to be used should be required upfront and normalizers should be provided directly - Remove `method` option, instead `methods` and `methods-plan` modules are provided which generate descriptors for lazy created memoized methods - `profile` is no longer extension. To be used it should be required directly - Improve logic for `async` handling - Take out `max` extensionLRU logic into external `lru-queue` package - Remove `context` option - Remove possibility to access original arguments when resolvers are used - Assure expected length of memoized functions
33 lines
663 B
JavaScript
33 lines
663 B
JavaScript
'use strict';
|
|
|
|
var memoize = require('../../..');
|
|
|
|
module.exports = {
|
|
"": function (a) {
|
|
var i = 0, fn = function () { ++i; return 3; };
|
|
|
|
fn = memoize(fn);
|
|
a(fn(), 3, "First");
|
|
a(fn(1), 3, "Second");
|
|
a(fn(5), 3, "Third");
|
|
a(i, 1, "Called once");
|
|
},
|
|
"Delete": function (a) {
|
|
var i = 0, fn, mfn, x = {};
|
|
|
|
fn = function (a, b, c) {
|
|
return a + (++i);
|
|
};
|
|
mfn = memoize(fn, { length: 0 });
|
|
a(mfn(3), 4, "Init");
|
|
a(mfn(5), 4, "Other");
|
|
a(i, 1, "Pre clear");
|
|
mfn.delete(6, x, 1);
|
|
a(i, 1, "After clear");
|
|
a(mfn(6, x, 1), 8, "Reinit");
|
|
a(i, 2, "Reinit count");
|
|
a(mfn(3, x, 1), 8, "Reinit Cached");
|
|
a(i, 2, "Reinit count");
|
|
}
|
|
};
|