mirror of
https://github.com/biobulkbende/biobulkbende.org.git
synced 2025-10-11 15:14:59 +00:00
structure, layout and automation
This commit is contained in:
413
node_modules/memoizee/test/ext/async.js
generated
vendored
Normal file
413
node_modules/memoizee/test/ext/async.js
generated
vendored
Normal file
@ -0,0 +1,413 @@
|
||||
/* eslint id-length: 0, func-names: 0, handle-callback-err: 0, max-lines: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..")
|
||||
, nextTick = require("next-tick");
|
||||
|
||||
module.exports = function () {
|
||||
return {
|
||||
"Regular": {
|
||||
Success: function (a, d) {
|
||||
var mfn, fn, u = {}, i = 0, invoked = 0;
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
++i;
|
||||
cb(null, x + y);
|
||||
});
|
||||
return u;
|
||||
};
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Init Called #2");
|
||||
a(invoked, 7, "Cb Called #2");
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 3, "Init After delete");
|
||||
a(invoked, 9, "Cb After delete");
|
||||
d();
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
Error: function (a, d) {
|
||||
var mfn, fn, u = {}, i = 0, e = new Error("Test");
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
++i;
|
||||
cb(e);
|
||||
});
|
||||
return u;
|
||||
};
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 4, "Again Called #2");
|
||||
d();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
"Primitive": {
|
||||
"Success": function (a, d) {
|
||||
var mfn, fn, u = {}, i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
++i;
|
||||
cb(null, x + y);
|
||||
});
|
||||
return u;
|
||||
};
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 3, "Call After delete");
|
||||
d();
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
"Error": function (a, d) {
|
||||
var mfn, fn, u = {}, i = 0, e = new Error("Test");
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
++i;
|
||||
cb(e);
|
||||
});
|
||||
return u;
|
||||
};
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 4, "Again Called #2");
|
||||
d();
|
||||
});
|
||||
});
|
||||
},
|
||||
"Primitive null arg case": function (a, d) {
|
||||
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");
|
||||
d();
|
||||
});
|
||||
}
|
||||
},
|
||||
"Sync Clear": function (a, d) {
|
||||
var mfn, fn;
|
||||
fn = function (x, cb) {
|
||||
nextTick(function () {
|
||||
cb(null, x);
|
||||
});
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { async: true });
|
||||
mfn(1, function (err, i) {
|
||||
a(i, 1, "First");
|
||||
});
|
||||
mfn.clear();
|
||||
mfn(2, function (err, i) {
|
||||
a(i, 2, "Second");
|
||||
d();
|
||||
});
|
||||
},
|
||||
"Sync Clear: Primitive": function (a, d) {
|
||||
var mfn, fn;
|
||||
fn = function (x, cb) {
|
||||
nextTick(function () {
|
||||
cb(null, x);
|
||||
});
|
||||
};
|
||||
mfn = memoize(fn, { async: true, primitive: true });
|
||||
|
||||
mfn(2, function (err, i) {
|
||||
a(i, 2, "First");
|
||||
});
|
||||
mfn(1, function (err, i) {
|
||||
a(i, 1, "Second");
|
||||
nextTick(d);
|
||||
});
|
||||
mfn.clear();
|
||||
mfn(2, function (err, i) {
|
||||
a(i, 2, "Third");
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
243
node_modules/memoizee/test/ext/dispose.js
generated
vendored
Normal file
243
node_modules/memoizee/test/ext/dispose.js
generated
vendored
Normal file
@ -0,0 +1,243 @@
|
||||
/* eslint id-length: 0, max-lines: 0, max-statements: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..")
|
||||
, nextTick = require("next-tick")
|
||||
, delay = require("timers-ext/delay")
|
||||
, Promise = require("plain-promise");
|
||||
|
||||
module.exports = function () {
|
||||
return {
|
||||
Regular: {
|
||||
"Sync": function (a) {
|
||||
var mfn, fn, value = [], x, invoked;
|
||||
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);
|
||||
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);
|
||||
mfn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
|
||||
x = {};
|
||||
invoked = false;
|
||||
mfn = memoize(function () { return x; }, {
|
||||
dispose: function (val) { invoked = val; }
|
||||
});
|
||||
|
||||
mfn.delete();
|
||||
a(invoked, false, "No args: Post invalid delete");
|
||||
mfn();
|
||||
a(invoked, false, "No args: Post cache");
|
||||
mfn.delete();
|
||||
a(invoked, x, "No args: Pre delete");
|
||||
},
|
||||
"Ref counter": function (a) {
|
||||
var mfn, fn, value = [];
|
||||
fn = function (x, y) { return x + y; };
|
||||
mfn = memoize(fn, {
|
||||
refCounter: true,
|
||||
dispose: function (val) { value.push(val); }
|
||||
});
|
||||
|
||||
mfn(3, 7);
|
||||
mfn(5, 8);
|
||||
mfn(12, 4);
|
||||
a.deep(value, [], "Pre");
|
||||
mfn(5, 8);
|
||||
mfn.deleteRef(5, 8);
|
||||
a.deep(value, [], "Pre");
|
||||
mfn.deleteRef(5, 8);
|
||||
a.deep(value, [13], "#1");
|
||||
value = [];
|
||||
mfn.deleteRef(12, 4);
|
||||
a.deep(value, [16], "#2");
|
||||
|
||||
value = [];
|
||||
mfn(77, 11);
|
||||
mfn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
},
|
||||
"Async": function (a, d) {
|
||||
var mfn, fn, u = {}, value = [];
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () { cb(null, x + y); });
|
||||
return u;
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { async: true, dispose: function (val) { value.push(val); } });
|
||||
|
||||
mfn(3, 7, function () {
|
||||
mfn(5, 8, function () {
|
||||
mfn(12, 4, 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, function () {
|
||||
mfn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
d();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
"Promise": function (a, d) {
|
||||
var mfn, fn, value = [];
|
||||
fn = function (x, y) {
|
||||
return new Promise(function (res) { res(x + y); });
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true, dispose: function (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");
|
||||
|
||||
value = [];
|
||||
mfn(77, 11).done(
|
||||
delay(function () {
|
||||
mfn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
d();
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
Primitive: {
|
||||
"Sync": function (a) {
|
||||
var mfn, fn, value = [];
|
||||
fn = function (x, y) { return x + y; };
|
||||
mfn = memoize(fn, { dispose: function (val) { value.push(val); } });
|
||||
|
||||
mfn(3, 7);
|
||||
mfn(5, 8);
|
||||
mfn(12, 4);
|
||||
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);
|
||||
mfn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
},
|
||||
"Ref counter": function (a) {
|
||||
var mfn, fn, value = [];
|
||||
fn = function (x, y) { return x + y; };
|
||||
mfn = memoize(fn, {
|
||||
refCounter: true,
|
||||
dispose: function (val) { value.push(val); }
|
||||
});
|
||||
|
||||
mfn(3, 7);
|
||||
mfn(5, 8);
|
||||
mfn(12, 4);
|
||||
a.deep(value, [], "Pre");
|
||||
mfn(5, 8);
|
||||
mfn.deleteRef(5, 8);
|
||||
a.deep(value, [], "Pre");
|
||||
mfn.deleteRef(5, 8);
|
||||
a.deep(value, [13], "#1");
|
||||
value = [];
|
||||
mfn.deleteRef(12, 4);
|
||||
a.deep(value, [16], "#2");
|
||||
|
||||
value = [];
|
||||
mfn(77, 11);
|
||||
mfn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
},
|
||||
"Async": function (a, d) {
|
||||
var mfn, fn, u = {}, value = [];
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () { cb(null, x + y); });
|
||||
return u;
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { async: true, dispose: function (val) { value.push(val); } });
|
||||
|
||||
mfn(3, 7, function () {
|
||||
mfn(5, 8, function () {
|
||||
mfn(12, 4, 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, function () {
|
||||
mfn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
d();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
"Promise": function (a, d) {
|
||||
var mfn, fn, value = [];
|
||||
fn = function (x, y) {
|
||||
return new Promise(function (res) { res(x + y); });
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true, dispose: function (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");
|
||||
|
||||
value = [];
|
||||
mfn(77, 11).done(
|
||||
delay(function () {
|
||||
mfn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
d();
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
860
node_modules/memoizee/test/ext/max-age.js
generated
vendored
Normal file
860
node_modules/memoizee/test/ext/max-age.js
generated
vendored
Normal file
@ -0,0 +1,860 @@
|
||||
/* 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("../..")
|
||||
, nextTick = require("next-tick")
|
||||
, delay = require("timers-ext/delay")
|
||||
, Promise = require("plain-promise");
|
||||
|
||||
require("../../ext/async");
|
||||
require("../../ext/promise");
|
||||
|
||||
module.exports = function () {
|
||||
return {
|
||||
Regular: {
|
||||
Sync: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return x + y;
|
||||
};
|
||||
mfn = memoize(fn, { maxAge: 100 });
|
||||
|
||||
a(mfn(3, 7), 10, "Result #1");
|
||||
a(i, 1, "Called #1");
|
||||
a(mfn(3, 7), 10, "Result #2");
|
||||
a(i, 1, "Called #2");
|
||||
a(mfn(5, 8), 13, "Result B #1");
|
||||
a(i, 2, "Called B #1");
|
||||
a(mfn(3, 7), 10, "Result #3");
|
||||
a(i, 2, "Called #3");
|
||||
a(mfn(5, 8), 13, "Result B #2");
|
||||
a(i, 2, "Called B #2");
|
||||
|
||||
setTimeout(function () {
|
||||
a(mfn(3, 7), 10, "Result: Wait");
|
||||
a(i, 2, "Called: Wait");
|
||||
a(mfn(5, 8), 13, "Result: Wait B");
|
||||
a(i, 2, "Called: Wait B");
|
||||
|
||||
a(mfn(9, 1), 10, "Result: C");
|
||||
a(i, 3, "Called: C");
|
||||
setTimeout(function () {
|
||||
a(mfn(3, 7), 10, "Result: Wait After");
|
||||
a(i, 4, "Called: Wait After");
|
||||
a(mfn(5, 8), 13, "Result: Wait After B");
|
||||
a(i, 5, "Called: Wait After B");
|
||||
|
||||
a(mfn(3, 7), 10, "Result: Wait After #2");
|
||||
a(i, 5, "Called: Wait After #2");
|
||||
a(mfn(5, 8), 13, "Result: Wait After B #2");
|
||||
a(i, 5, "Called: Wait After B #2");
|
||||
|
||||
a(mfn(9, 1), 10, "Result: WiatC");
|
||||
a(i, 5, "Called: Wait C");
|
||||
d();
|
||||
}, 70);
|
||||
}, 40);
|
||||
},
|
||||
Promise: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
return new Promise(function (res) {
|
||||
++i;
|
||||
res(x + y);
|
||||
});
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true, maxAge: 100 });
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Result #1"); });
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Result #2"); });
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Result #3"); });
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Result #4"); });
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Result #5"); });
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Again: Result #1"); });
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Again: Result #2"); });
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Again Called #2");
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Again: Result #1"); });
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Again: Result #2"); });
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 4, "Call After clear");
|
||||
d();
|
||||
});
|
||||
}, 100);
|
||||
}, 20);
|
||||
},
|
||||
Async: function (a, d) {
|
||||
var mfn, fn, u = {}, i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
++i;
|
||||
cb(null, x + y);
|
||||
});
|
||||
return u;
|
||||
};
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 4, "Call After clear");
|
||||
d();
|
||||
});
|
||||
}, 100);
|
||||
}, 20);
|
||||
}
|
||||
},
|
||||
Primitive: {
|
||||
Sync: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return x + y;
|
||||
};
|
||||
mfn = memoize(fn, { primitive: true, maxAge: 100 });
|
||||
|
||||
a(mfn(3, 7), 10, "Result #1");
|
||||
a(i, 1, "Called #1");
|
||||
a(mfn(3, 7), 10, "Result #2");
|
||||
a(i, 1, "Called #2");
|
||||
a(mfn(5, 8), 13, "Result B #1");
|
||||
a(i, 2, "Called B #1");
|
||||
a(mfn(3, 7), 10, "Result #3");
|
||||
a(i, 2, "Called #3");
|
||||
a(mfn(5, 8), 13, "Result B #2");
|
||||
a(i, 2, "Called B #2");
|
||||
|
||||
setTimeout(function () {
|
||||
a(mfn(3, 7), 10, "Result: Wait");
|
||||
a(i, 2, "Called: Wait");
|
||||
a(mfn(5, 8), 13, "Result: Wait B");
|
||||
a(i, 2, "Called: Wait B");
|
||||
|
||||
setTimeout(function () {
|
||||
a(mfn(3, 7), 10, "Result: Wait After");
|
||||
a(i, 3, "Called: Wait After");
|
||||
a(mfn(5, 8), 13, "Result: Wait After B");
|
||||
a(i, 4, "Called: Wait After B");
|
||||
|
||||
a(mfn(3, 7), 10, "Result: Wait After #2");
|
||||
a(i, 4, "Called: Wait After #2");
|
||||
a(mfn(5, 8), 13, "Result: Wait After B #2");
|
||||
a(i, 4, "Called: Wait After B #2");
|
||||
d();
|
||||
}, 100);
|
||||
}, 20);
|
||||
},
|
||||
Async: function (a, d) {
|
||||
var mfn, fn, u = {}, i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
++i;
|
||||
cb(null, x + y);
|
||||
});
|
||||
return u;
|
||||
};
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 4, "Call After clear");
|
||||
d();
|
||||
});
|
||||
}, 100);
|
||||
}, 20);
|
||||
},
|
||||
Promise: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
return new Promise(function (res) {
|
||||
++i;
|
||||
res(x + y);
|
||||
});
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true, primitive: true, maxAge: 100 });
|
||||
|
||||
mfn(3, 7).done(function (res) { a.deep(res, 10, "Result #1"); });
|
||||
mfn(3, 7).done(function (res) { a.deep(res, 10, "Result #2"); });
|
||||
mfn(5, 8).done(function (res) { a.deep(res, 13, "Result B #1"); });
|
||||
mfn(3, 7).done(function (res) { a.deep(res, 10, "Result #3"); });
|
||||
mfn(5, 8).done(function (res) { a.deep(res, 13, "Result B #2"); });
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
mfn(3, 7).done(function (res) { a.deep(res, 10, "Again: Result"); });
|
||||
mfn(5, 8).done(function (res) { a.deep(res, 13, "Again B: Result"); });
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Again Called #2");
|
||||
|
||||
mfn(3, 7).done(function (res) { a.deep(res, 10, "Again: Result"); });
|
||||
mfn(5, 8).done(function (res) { a.deep(res, 13, "Again B: Result"); });
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 4, "Call After clear");
|
||||
d();
|
||||
});
|
||||
}, 100);
|
||||
}, 20);
|
||||
}
|
||||
},
|
||||
Refetch: {
|
||||
Default: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return x + y;
|
||||
};
|
||||
mfn = memoize(fn, { maxAge: 600, preFetch: true });
|
||||
|
||||
a(mfn(3, 7), 10, "Result #1");
|
||||
a(i, 1, "Called #1");
|
||||
a(mfn(3, 7), 10, "Result #2");
|
||||
a(i, 1, "Called #2");
|
||||
a(mfn(5, 8), 13, "Result B #1");
|
||||
a(i, 2, "Called B #1");
|
||||
a(mfn(3, 7), 10, "Result #3");
|
||||
a(i, 2, "Called #3");
|
||||
a(mfn(5, 8), 13, "Result B #2");
|
||||
a(i, 2, "Called B #2");
|
||||
|
||||
setTimeout(function () {
|
||||
a(mfn(3, 7), 10, "Result: Wait");
|
||||
a(i, 2, "Called: Wait");
|
||||
a(mfn(5, 8), 13, "Result: Wait B");
|
||||
a(i, 2, "Called: Wait B");
|
||||
|
||||
setTimeout(function () {
|
||||
a(mfn(3, 7), 10, "Result: Wait After");
|
||||
a(i, 2, "Called: Wait After");
|
||||
a(mfn(5, 8), 13, "Result: Wait After B");
|
||||
a(i, 2, "Called: Wait After B");
|
||||
|
||||
a(mfn(3, 7), 10, "Result: Wait After #2");
|
||||
a(i, 2, "Called: Wait After #2");
|
||||
a(mfn(5, 8), 13, "Result: Wait After B #2");
|
||||
a(i, 2, "Called: Wait After B #2");
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 4, "Called: After Refetch: Before");
|
||||
a(mfn(3, 7), 10, "Result: After Refetch");
|
||||
a(i, 4, "Called: After Refetch: After");
|
||||
a(mfn(5, 8), 13, "Result: After Refetch B");
|
||||
a(i, 4, "Called: After Refetch B: After");
|
||||
|
||||
setTimeout(function () {
|
||||
a(mfn(3, 7), 10, "Result: After Refetch #2");
|
||||
a(i, 4, "Called: After Refetch #2");
|
||||
a(mfn(5, 8), 13, "Result: After Refetch #2 B");
|
||||
a(i, 4, "Called: After Refetch #2 B");
|
||||
|
||||
a(mfn(3, 7), 10, "Result: After Refetch #3");
|
||||
a(i, 4, "Called: After Refetch #3");
|
||||
a(mfn(5, 8), 13, "Result: After Refetch #3 B");
|
||||
a(i, 4, "Called: After Refetch #3 B");
|
||||
d();
|
||||
}, 200);
|
||||
}, 200);
|
||||
}, 200);
|
||||
}, 300);
|
||||
},
|
||||
Async: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
++i;
|
||||
setTimeout(function () { cb(null, x + y); }, 0);
|
||||
};
|
||||
mfn = memoize(fn, { maxAge: 600, preFetch: true, async: true });
|
||||
|
||||
// 1.Start
|
||||
mfn(3, 7, function (err, result) {
|
||||
a(result, 10, "Result #1");
|
||||
a(i, 1, "Called #1");
|
||||
mfn(3, 7, function (err, result) {
|
||||
a(result, 10, "Result #2");
|
||||
a(i, 1, "Called #2");
|
||||
mfn(5, 8, function (err, result) {
|
||||
a(result, 13, "Result B #1");
|
||||
a(i, 2, "Called B #1");
|
||||
mfn(3, 7, function (err, result) {
|
||||
a(result, 10, "Result #3");
|
||||
a(i, 2, "Called #3");
|
||||
mfn(5, 8, function (err, result) {
|
||||
a(result, 13, "Result B #2");
|
||||
a(i, 2, "Called B #2");
|
||||
// 2. Wait 300ms
|
||||
setTimeout(function () {
|
||||
// From cache, prefetch not triggered
|
||||
mfn(3, 7, function (err, result) {
|
||||
a(result, 10, "Result: Wait");
|
||||
a(i, 2, "Called: Wait");
|
||||
mfn(5, 8, function (err, result) {
|
||||
a(result, 13, "Result: Wait B");
|
||||
a(i, 2, "Called: Wait B");
|
||||
// Wait 200ms
|
||||
setTimeout(function () {
|
||||
// From cache, prefetch triggered
|
||||
mfn(3, 7, function (err, result) {
|
||||
a(result, 10, "Result: Wait After");
|
||||
a(i, 2, "Called: Wait After");
|
||||
mfn(5, 8, function (err, result) {
|
||||
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(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"
|
||||
);
|
||||
// Wait 200ms
|
||||
setTimeout(function () {
|
||||
// From cache, prefetch not triggered
|
||||
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"
|
||||
);
|
||||
// Wait 250ms
|
||||
setTimeout(
|
||||
function () {
|
||||
// From cache, prefetch triggered
|
||||
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();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
250
|
||||
);
|
||||
});
|
||||
});
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
}, 300);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
Promise: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return new Promise(function (res) { res(x + y); });
|
||||
};
|
||||
mfn = memoize(fn, { maxAge: 1200, preFetch: true, promise: true });
|
||||
|
||||
mfn(3, 7).done(function (result) {
|
||||
a(result, 10, "Result #1");
|
||||
a(i, 1, "Called #1");
|
||||
mfn(3, 7).done(function (result) {
|
||||
a(result, 10, "Result #2");
|
||||
a(i, 1, "Called #2");
|
||||
mfn(5, 8).done(function (result) {
|
||||
a(result, 13, "Result B #1");
|
||||
a(i, 2, "Called B #1");
|
||||
mfn(3, 7).done(function (result) {
|
||||
a(result, 10, "Result #3");
|
||||
a(i, 2, "Called #3");
|
||||
mfn(5, 8).done(function (result) {
|
||||
a(result, 13, "Result B #2");
|
||||
a(i, 2, "Called B #2");
|
||||
// 600
|
||||
setTimeout(function () {
|
||||
mfn(3, 7).done(function (result) {
|
||||
a(result, 10, "Result: Wait");
|
||||
a(i, 2, "Called: Wait");
|
||||
mfn(5, 8).done(function (result) {
|
||||
a(result, 13, "Result: Wait B");
|
||||
a(i, 2, "Called: Wait B");
|
||||
// 400
|
||||
setTimeout(function () {
|
||||
mfn(3, 7).done(
|
||||
// 0
|
||||
delay(function (result) {
|
||||
a(result, 10, "Result: Wait After");
|
||||
a(i, 3, "Called: Wait After");
|
||||
mfn(5, 8).done(
|
||||
// 0
|
||||
delay(function (result) {
|
||||
a(
|
||||
result, 13,
|
||||
"Result: Wait After B"
|
||||
);
|
||||
a(i, 4, "Called: Wait After B");
|
||||
mfn(3, 7).done(
|
||||
// next tick
|
||||
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"
|
||||
);
|
||||
// 400
|
||||
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"
|
||||
);
|
||||
// 400
|
||||
setTimeout(
|
||||
function () {
|
||||
mfn(
|
||||
3,
|
||||
7
|
||||
).done(
|
||||
// 0
|
||||
delay(
|
||||
function (
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result,
|
||||
10,
|
||||
"Result: After Refetch #2"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
5,
|
||||
"Called: After Refetch #2"
|
||||
);
|
||||
mfn(
|
||||
5,
|
||||
8
|
||||
).done(
|
||||
// 0
|
||||
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
|
||||
)
|
||||
);
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
}, 0)
|
||||
);
|
||||
}, 0)
|
||||
);
|
||||
}, 400);
|
||||
});
|
||||
});
|
||||
}, 600);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
Custom: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return x + y;
|
||||
};
|
||||
mfn = memoize(fn, { maxAge: 6000, preFetch: 1 / 6 });
|
||||
a(mfn(3, 7), 10, "Result #1");
|
||||
a(i, 1, "Called #1");
|
||||
a(mfn(3, 7), 10, "Result #2");
|
||||
a(i, 1, "Called #2");
|
||||
a(mfn(5, 8), 13, "Result B #1");
|
||||
a(i, 2, "Called B #1");
|
||||
a(mfn(3, 7), 10, "Result #3");
|
||||
a(i, 2, "Called #3");
|
||||
a(mfn(5, 8), 13, "Result B #2");
|
||||
a(i, 2, "Called B #2");
|
||||
|
||||
setTimeout(function () {
|
||||
a(mfn(3, 7), 10, "Result: Wait");
|
||||
a(i, 2, "Called: Wait");
|
||||
a(mfn(5, 8), 13, "Result: Wait B");
|
||||
a(i, 2, "Called: Wait B");
|
||||
|
||||
setTimeout(function () {
|
||||
a(mfn(3, 7), 10, "Result: Wait After");
|
||||
a(i, 2, "Called: Wait After");
|
||||
a(mfn(5, 8), 13, "Result: Wait After B");
|
||||
a(i, 2, "Called: Wait After B");
|
||||
|
||||
a(mfn(3, 7), 10, "Result: Wait After #2");
|
||||
a(i, 2, "Called: Wait After #2");
|
||||
a(mfn(5, 8), 13, "Result: Wait After B #2");
|
||||
a(i, 2, "Called: Wait After B #2");
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 4, "Called: After Refetch: Before");
|
||||
a(mfn(3, 7), 10, "Result: After Refetch");
|
||||
a(i, 4, "Called: After Refetch: After");
|
||||
a(mfn(5, 8), 13, "Result: After Refetch B");
|
||||
a(i, 4, "Called: After Refetch B: After");
|
||||
|
||||
setTimeout(function () {
|
||||
a(mfn(3, 7), 10, "Result: After Refetch #2");
|
||||
a(i, 4, "Called: After Refetch #2");
|
||||
a(mfn(5, 8), 13, "Result: After Refetch #2 B");
|
||||
a(i, 4, "Called: After Refetch #2 B");
|
||||
|
||||
a(mfn(3, 7), 10, "Result: After Refetch #3");
|
||||
a(i, 4, "Called: After Refetch #3");
|
||||
a(mfn(5, 8), 13, "Result: After Refetch #3 B");
|
||||
a(i, 4, "Called: After Refetch #3 B");
|
||||
d();
|
||||
}, 2000);
|
||||
}, 3000);
|
||||
}, 1000);
|
||||
}, 4500);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
1677
node_modules/memoizee/test/ext/max.js
generated
vendored
Normal file
1677
node_modules/memoizee/test/ext/max.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
326
node_modules/memoizee/test/ext/promise.js
generated
vendored
Normal file
326
node_modules/memoizee/test/ext/promise.js
generated
vendored
Normal file
@ -0,0 +1,326 @@
|
||||
/* eslint id-length: 0, handle-callback-err: 0, no-undef: 0, no-unused-vars: 0, func-names: 0,
|
||||
max-lines: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..")
|
||||
, nextTick = require("next-tick")
|
||||
, Promise = require("plain-promise")
|
||||
, Bluebird = require("bluebird");
|
||||
|
||||
Bluebird.config({
|
||||
cancellation: true
|
||||
});
|
||||
|
||||
module.exports = function () {
|
||||
return {
|
||||
"Regular": {
|
||||
Success: function (a, d) {
|
||||
var mfn, fn, i = 0, invoked = 0;
|
||||
fn = function (x, y) {
|
||||
return new Promise(function (res) {
|
||||
++i;
|
||||
res(x + y);
|
||||
});
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true });
|
||||
|
||||
mfn(3, 7).done(function (res) {
|
||||
++invoked;
|
||||
a(res, 10, "Result #1");
|
||||
}, a.never);
|
||||
|
||||
mfn(3, 7).done(function (res) {
|
||||
++invoked;
|
||||
a(res, 10, "Result #2");
|
||||
}, a.never);
|
||||
|
||||
mfn(5, 8).done(function (res) {
|
||||
++invoked;
|
||||
a(res, 13, "Result B #1");
|
||||
}, a.never);
|
||||
|
||||
mfn(3, 7).done(function (res) {
|
||||
++invoked;
|
||||
a(res, 10, "Result #3");
|
||||
}, a.never);
|
||||
|
||||
mfn(5, 8).done(function (res) {
|
||||
++invoked;
|
||||
a(res, 13, "Result B #2");
|
||||
}, a.never);
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Init Called");
|
||||
a(invoked, 5, "Cb Called");
|
||||
|
||||
mfn(3, 7).done(function (res) {
|
||||
++invoked;
|
||||
a(res, 10, "Again: Result");
|
||||
}, a.never);
|
||||
|
||||
mfn(5, 8).done(function (res) {
|
||||
++invoked;
|
||||
a(res, 13, "Again B: Result");
|
||||
}, a.never);
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Init Called #2");
|
||||
a(invoked, 7, "Cb Called #2");
|
||||
|
||||
mfn.delete(3, 7);
|
||||
|
||||
mfn(3, 7).done(function (res) {
|
||||
++invoked;
|
||||
a(res, 10, "Again: Result");
|
||||
}, a.never);
|
||||
|
||||
mfn(5, 8).done(function (res) {
|
||||
++invoked;
|
||||
a(res, 13, "Again B: Result");
|
||||
}, a.never);
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 3, "Init After delete");
|
||||
a(invoked, 9, "Cb After delete");
|
||||
d();
|
||||
}, 10);
|
||||
}, 10);
|
||||
}, 10);
|
||||
},
|
||||
Error: function (a, d) {
|
||||
var mfn, fn, i = 0, e = new Error("Test");
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return new Promise(function (res, rej) { rej(e); });
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: "done", dispose: a.never });
|
||||
|
||||
mfn(3, 7).done(a.never, function (err) { a(err, e, "Result #1"); });
|
||||
|
||||
mfn(5, 8).done(a.never, function (err) { a(err, e, "Result B #2"); });
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
mfn(3, 7).done(a.never, function (err) { a(err, e, "Again: Result"); });
|
||||
|
||||
mfn(5, 8).done(a.never, function (err) { a(err, e, "Again B: Result"); });
|
||||
|
||||
setTimeout(function (err) {
|
||||
a(i, 4, "Again Called #2");
|
||||
d();
|
||||
}, 10);
|
||||
}, 10);
|
||||
}
|
||||
},
|
||||
"Cancellation": {
|
||||
Immediate: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
var p = new Bluebird(function (res) {
|
||||
setTimeout(function () {
|
||||
res(x + y);
|
||||
}, 100);
|
||||
});
|
||||
p.cancel();
|
||||
return p;
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true });
|
||||
|
||||
mfn(3, 7).done(a.never, function (err) {
|
||||
a.throws(function () {
|
||||
throw err;
|
||||
}, Bluebird.CancellationError, "Result #1");
|
||||
});
|
||||
|
||||
mfn(5, 8).done(a.never, function (err) {
|
||||
a.throws(function () {
|
||||
throw err;
|
||||
}, Bluebird.CancellationError, "Result B #2");
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
mfn(3, 7).done(a.never, function (err) {
|
||||
a.throws(function () {
|
||||
throw err;
|
||||
}, Bluebird.CancellationError, "Again: Result");
|
||||
});
|
||||
|
||||
mfn(5, 8).done(a.never, function (err) {
|
||||
a.throws(function () {
|
||||
throw err;
|
||||
}, Bluebird.CancellationError, "Again B: Result");
|
||||
});
|
||||
|
||||
setTimeout(function (err) {
|
||||
a(i, 4, "Again Called #2");
|
||||
d();
|
||||
}, 10);
|
||||
}, 10);
|
||||
},
|
||||
Delayed: function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
var p = new Bluebird(function (res) {
|
||||
setTimeout(function () {
|
||||
res(x + y);
|
||||
}, 100);
|
||||
});
|
||||
nextTick(function () {
|
||||
p.cancel();
|
||||
}, 1);
|
||||
return p;
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true });
|
||||
|
||||
mfn(3, 7).done(a.never, a.never);
|
||||
|
||||
mfn(5, 8).done(a.never, a.never);
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
mfn(3, 7).done(a.never, a.never);
|
||||
|
||||
mfn(5, 8).done(a.never, a.never);
|
||||
|
||||
setTimeout(function (err) {
|
||||
a(i, 4, "Again Called #2");
|
||||
d();
|
||||
}, 500);
|
||||
}, 500);
|
||||
}
|
||||
},
|
||||
"Primitive": {
|
||||
"Success": function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
return new Promise(function (res) {
|
||||
++i;
|
||||
res(x + y);
|
||||
});
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true, primitive: true });
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Result #1"); }, a.never);
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Result #2"); }, a.never);
|
||||
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Result B #1"); }, a.never);
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Result #3"); }, a.never);
|
||||
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Result B #2"); }, a.never);
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Again: Result"); }, a.never);
|
||||
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Again B: Result"); }, a.never);
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Again Called #2");
|
||||
|
||||
mfn.delete(3, 7);
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Again: Result"); }, a.never);
|
||||
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Again B: Result"); }, a.never);
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 3, "Call After delete");
|
||||
d();
|
||||
}, 10);
|
||||
}, 10);
|
||||
}, 10);
|
||||
},
|
||||
"Error": function (a, d) {
|
||||
var mfn, fn, i = 0, e = new Error("Test");
|
||||
fn = function (x, y) {
|
||||
return new Promise(function (res, rej) {
|
||||
++i;
|
||||
rej(e);
|
||||
});
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: "done", primitive: true });
|
||||
|
||||
mfn(3, 7).done(a.never, function (err) { a(err, e, "Result #1"); });
|
||||
|
||||
mfn(5, 8).done(a.never, function (err) { a(err, e, "Result B #2"); });
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
mfn(3, 7).done(a.never, function (err) { a(err, e, "Again: Result"); });
|
||||
|
||||
mfn(5, 8).done(a.never, function (err) { a(err, e, "Again B: Result"); });
|
||||
|
||||
setTimeout(function (err) {
|
||||
a(i, 4, "Again Called #2");
|
||||
d();
|
||||
}, 10);
|
||||
}, 10);
|
||||
},
|
||||
"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(null).done(function (res) {
|
||||
a.deep(res, x, "Args");
|
||||
d();
|
||||
}, a.never);
|
||||
}
|
||||
},
|
||||
"Sync Clear": function (a, d) {
|
||||
var mfn, fn;
|
||||
fn = function (x) {
|
||||
return new Promise(function (res) {
|
||||
nextTick(function () { res(x); });
|
||||
});
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true });
|
||||
|
||||
mfn(1).done(function (res) { a(res, 1, "First"); }, a.never);
|
||||
|
||||
mfn(2).done(function (res) {
|
||||
a(res, 2, "Second");
|
||||
d();
|
||||
}, a.never);
|
||||
},
|
||||
"Sync Clear: Primitive": function (a, d) {
|
||||
var mfn, fn;
|
||||
fn = function (x) {
|
||||
return new Promise(function (res) {
|
||||
nextTick(function () { res(x); });
|
||||
});
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true, primitive: true });
|
||||
|
||||
mfn(1).done(function (res) { a(res, 1, "First"); }, a.never);
|
||||
|
||||
mfn(2).done(function (res) {
|
||||
a(res, 2, "Second");
|
||||
d();
|
||||
}, a.never);
|
||||
}
|
||||
};
|
||||
};
|
302
node_modules/memoizee/test/ext/ref-counter.js
generated
vendored
Normal file
302
node_modules/memoizee/test/ext/ref-counter.js
generated
vendored
Normal file
@ -0,0 +1,302 @@
|
||||
/* eslint max-lines: 0, id-length: 0, no-undef: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..")
|
||||
, nextTick = require("next-tick")
|
||||
, Promise = require("plain-promise");
|
||||
|
||||
module.exports = function () {
|
||||
return {
|
||||
"Regular": function (a) {
|
||||
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");
|
||||
a(mfn(3, 5, 7), 15, "Cache");
|
||||
a(mfn.deleteRef(3, 5, 7), false, "Delete #1");
|
||||
mfn(3, 5, 7);
|
||||
a(mfn.deleteRef(3, 5, 7), false, "Delete #2");
|
||||
mfn(3, 5, 7);
|
||||
a(mfn.deleteRef(3, 5, 7), false, "Delete #3");
|
||||
mfn(3, 5, 7);
|
||||
a(i, 1, "Not deleteed");
|
||||
a(mfn.deleteRef(3, 5, 7), false, "Delete #4");
|
||||
a(mfn.deleteRef(3, 5, 7), true, "Delete final");
|
||||
mfn(3, 5, 7);
|
||||
a(i, 2, "Restarted");
|
||||
mfn(3, 5, 7);
|
||||
a(i, 2, "Cached again");
|
||||
},
|
||||
"Regular: Async": function (a, d) {
|
||||
var mfn, fn, u = {}, i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
++i;
|
||||
cb(null, x + y);
|
||||
});
|
||||
return u;
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { async: true, refCounter: true });
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Again Called #2");
|
||||
|
||||
a(mfn.deleteRef(3, 7), false, "Delete ref #1");
|
||||
a(mfn.deleteRef(3, 7), false, "Delete ref #2");
|
||||
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"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 3, "Call After delete");
|
||||
d();
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
"Regular: Promise": function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return new Promise(function (res) { res(x + y); });
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true, refCounter: true });
|
||||
|
||||
a(mfn.deleteRef(3, 7), null, "Delete ref before");
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Result #1"); });
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Result #2"); });
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Result B #1"); });
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Result #3"); });
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Result B #2"); });
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Again: Result"); });
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Again B: Result"); });
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Again Called #2");
|
||||
|
||||
a(mfn.deleteRef(3, 7), false, "Delete ref #1");
|
||||
a(mfn.deleteRef(3, 7), false, "Delete ref #2");
|
||||
a(mfn.deleteRef(3, 7), false, "Delete ref #3");
|
||||
a(mfn.deleteRef(3, 7), true, "Delete ref Final");
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Again: Result"); });
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Again B: Result"); });
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 3, "Call After delete");
|
||||
d();
|
||||
}, 10);
|
||||
}, 10);
|
||||
}, 10);
|
||||
},
|
||||
"Primitive": function (a) {
|
||||
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");
|
||||
a(mfn(3, 5, 7), 15, "Cache");
|
||||
a(mfn.deleteRef(3, 5, 7), false, "Delete #1");
|
||||
mfn(3, 5, 7);
|
||||
a(mfn.deleteRef(3, 5, 7), false, "Delete #2");
|
||||
mfn(3, 5, 7);
|
||||
a(mfn.deleteRef(3, 5, 7), false, "Delete #3");
|
||||
mfn(3, 5, 7);
|
||||
a(i, 1, "Not deleteed");
|
||||
a(mfn.deleteRef(3, 5, 7), false, "Delete #4");
|
||||
a(mfn.deleteRef(3, 5, 7), true, "Delete final");
|
||||
mfn(3, 5, 7);
|
||||
a(i, 2, "Restarted");
|
||||
mfn(3, 5, 7);
|
||||
a(i, 2, "Cached again");
|
||||
},
|
||||
"Primitive: Async": function (a, d) {
|
||||
var mfn, fn, u = {}, i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
++i;
|
||||
cb(null, x + y);
|
||||
});
|
||||
return u;
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { async: true, primitive: true, refCounter: true });
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 2, "Again Called #2");
|
||||
|
||||
a(mfn.deleteRef(3, 7), false, "Delete ref #1");
|
||||
a(mfn.deleteRef(3, 7), false, "Delete ref #2");
|
||||
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"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
a(i, 3, "Call After delete");
|
||||
d();
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
"Primitive: Promise": function (a, d) {
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return new Promise(function (res) { res(x + y); });
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true, primitive: true, refCounter: true });
|
||||
|
||||
a(mfn.deleteRef(3, 7), null, "Delete ref before");
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Result #1"); });
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Result #2"); });
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Result B #1"); });
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Result #3"); });
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Result B #2"); });
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Called #2");
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Again: Result"); });
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Again B: Result"); });
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 2, "Again Called #2");
|
||||
|
||||
a(mfn.deleteRef(3, 7), false, "Delete ref #1");
|
||||
a(mfn.deleteRef(3, 7), false, "Delete ref #2");
|
||||
a(mfn.deleteRef(3, 7), false, "Delete ref #3");
|
||||
a(mfn.deleteRef(3, 7), true, "Delete ref Final");
|
||||
|
||||
mfn(3, 7).done(function (res) { a(res, 10, "Again: Result"); });
|
||||
mfn(5, 8).done(function (res) { a(res, 13, "Again B: Result"); });
|
||||
|
||||
setTimeout(function () {
|
||||
a(i, 3, "Call After delete");
|
||||
d();
|
||||
}, 10);
|
||||
}, 10);
|
||||
}, 10);
|
||||
}
|
||||
};
|
||||
};
|
2474
node_modules/memoizee/test/index.js
generated
vendored
Normal file
2474
node_modules/memoizee/test/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
156
node_modules/memoizee/test/lib/configure-map.js
generated
vendored
Normal file
156
node_modules/memoizee/test/lib/configure-map.js
generated
vendored
Normal file
@ -0,0 +1,156 @@
|
||||
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var aFrom = require("es5-ext/array/from")
|
||||
, memoize = require("../..");
|
||||
|
||||
module.exports = function () {
|
||||
return {
|
||||
"One arg": function (a) {
|
||||
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");
|
||||
},
|
||||
"No args": function (a) {
|
||||
var i = 0
|
||||
, fn = function () {
|
||||
++i;
|
||||
return "foo";
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
mfn = memoize(fn);
|
||||
a(mfn._has(), false);
|
||||
a(mfn(), "foo", "#1");
|
||||
a(mfn._has(), true);
|
||||
mfn();
|
||||
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";
|
||||
}
|
||||
};
|
||||
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"
|
||||
);
|
||||
a(mfn(y, "bar", "zeta"), "foobarzeta", "#3");
|
||||
a(i, 2, "Called twice");
|
||||
},
|
||||
"_get": function (a) {
|
||||
var fn = function (x) {
|
||||
return x;
|
||||
}
|
||||
, mfn;
|
||||
mfn = memoize(fn);
|
||||
a(mfn._get("foo"), undefined);
|
||||
mfn("foo");
|
||||
a(mfn._get("foo"), "foo");
|
||||
},
|
||||
"_has": function (a) {
|
||||
var fn = function (x) {
|
||||
return x;
|
||||
}
|
||||
, mfn;
|
||||
mfn = memoize(fn);
|
||||
a(mfn._has("foo"), false);
|
||||
mfn("foo");
|
||||
a(mfn._has("foo"), true);
|
||||
},
|
||||
"Circular": function (a) {
|
||||
var i = 0, fn;
|
||||
fn = memoize(function (x) {
|
||||
if (++i < 2) fn(x);
|
||||
});
|
||||
a.throws(function () {
|
||||
fn("foo");
|
||||
}, "CIRCULAR_INVOCATION");
|
||||
|
||||
i = 0;
|
||||
fn = memoize(function (x, y) {
|
||||
if (++i < 2) fn(x, y);
|
||||
});
|
||||
a.throws(function () {
|
||||
fn("foo", "bar");
|
||||
}, "CIRCULAR_INVOCATION");
|
||||
},
|
||||
"Resolvers": function () {
|
||||
var i = 0, fn, r;
|
||||
fn = memoize(
|
||||
function () {
|
||||
++i;
|
||||
return arguments;
|
||||
},
|
||||
{ length: 3, resolvers: [Boolean, String] }
|
||||
);
|
||||
return {
|
||||
"No args": function (a) {
|
||||
i = 0;
|
||||
a.deep(aFrom(r = fn()), [false, "undefined"], "First");
|
||||
a(fn(), r, "Second");
|
||||
a(fn(), r, "Third");
|
||||
a(i, 1, "Called once");
|
||||
},
|
||||
"One arg": function (a) {
|
||||
var fn = memoize(
|
||||
function (elo) {
|
||||
++i;
|
||||
return arguments;
|
||||
},
|
||||
{ resolvers: [Boolean] }
|
||||
);
|
||||
a.deep(aFrom(r = fn("elo")), [true], "First");
|
||||
},
|
||||
"Some Args": function (a) {
|
||||
var x = {};
|
||||
i = 0;
|
||||
a.deep(aFrom(r = fn(0, 34, x, 45)), [false, "34", x, 45], "First");
|
||||
a(fn(0, 34, x, 22), r, "Second");
|
||||
a(fn(0, 34, x, false), r, "Third");
|
||||
a(i, 1, "Called once");
|
||||
return {
|
||||
Other: function (a) {
|
||||
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");
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
50
node_modules/memoizee/test/lib/methods.js
generated
vendored
Normal file
50
node_modules/memoizee/test/lib/methods.js
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
/* eslint id-length: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var d = require("d")
|
||||
, memoize = require("../..");
|
||||
|
||||
require("../ext/dispose");
|
||||
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);
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
obj = Object.create(obj);
|
||||
obj.someFn(3, 7);
|
||||
obj.someFn(5, 8);
|
||||
obj.someFn(12, 4);
|
||||
a.deep(value, [], "Pre");
|
||||
obj.someFn(5, 8);
|
||||
obj.someFn.deleteRef(5, 8);
|
||||
a.deep(value, [], "Pre");
|
||||
obj.someFn.deleteRef(5, 8);
|
||||
a.deep(value, [13], "#1");
|
||||
value = [];
|
||||
obj.someFn.deleteRef(12, 4);
|
||||
a.deep(value, [16], "#2");
|
||||
|
||||
value = [];
|
||||
obj.someFn(77, 11);
|
||||
obj.someFn.clear();
|
||||
a.deep(value, [10, 88], "Clear");
|
||||
};
|
6
node_modules/memoizee/test/lib/registered-extensions.js
generated
vendored
Normal file
6
node_modules/memoizee/test/lib/registered-extensions.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function (t, a) {
|
||||
require("../../ext/async");
|
||||
a(typeof t.async, "function");
|
||||
};
|
10
node_modules/memoizee/test/lib/resolve-length.js
generated
vendored
Normal file
10
node_modules/memoizee/test/lib/resolve-length.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function (t, a) {
|
||||
a(t(1, 2), 1, "Options");
|
||||
a(t(1, 2, true), 1, "Options: Async ");
|
||||
a(t(undefined, 2), 2, "Function");
|
||||
a(t(undefined, 2, true), 1, "Function: Async");
|
||||
a(t(undefined, undefined, false), 1, "Unknown");
|
||||
a(t(undefined, undefined, true), 1, "Unknown: async");
|
||||
};
|
9
node_modules/memoizee/test/lib/resolve-normalize.js
generated
vendored
Normal file
9
node_modules/memoizee/test/lib/resolve-normalize.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/* eslint no-empty-function: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = function (t, a) {
|
||||
var fn = function () {}, resolved = t(fn);
|
||||
a.deep(resolved, { get: fn, set: fn });
|
||||
a.deep(t(resolved), { get: fn, set: fn });
|
||||
};
|
5
node_modules/memoizee/test/lib/resolve-resolve.js
generated
vendored
Normal file
5
node_modules/memoizee/test/lib/resolve-resolve.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function (t, a) {
|
||||
a.deep(t([String, null, Number])([23, "foo", "45", "elo"]), ["23", "foo", 45, "elo"]);
|
||||
};
|
53
node_modules/memoizee/test/lib/weak.js
generated
vendored
Normal file
53
node_modules/memoizee/test/lib/weak.js
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..");
|
||||
|
||||
require("../ext/dispose");
|
||||
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);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
a(memoized(obj, 3, 7), 10);
|
||||
a(memoized(obj, 5, 8), 13);
|
||||
a(memoized(obj, 12, 4), 16);
|
||||
a.deep(value, [], "Pre");
|
||||
a(memoized(obj, 5, 8), 13);
|
||||
memoized.deleteRef(obj, 5, 8);
|
||||
a.deep(value, [], "Pre");
|
||||
memoized.deleteRef(obj, 5, 8);
|
||||
a.deep(value, [13], "#1");
|
||||
value = [];
|
||||
memoized.deleteRef(obj, 12, 4);
|
||||
a.deep(value, [16], "#2");
|
||||
|
||||
value = [];
|
||||
memoized(obj, 77, 11);
|
||||
|
||||
x = {};
|
||||
y = {};
|
||||
z = {};
|
||||
memoized = t(function (arg) {
|
||||
return ++count;
|
||||
});
|
||||
a(memoized(x), 1);
|
||||
a(memoized(y), 2);
|
||||
a(memoized(x), 1);
|
||||
a(memoized(z), 3);
|
||||
a(count, 3);
|
||||
};
|
48
node_modules/memoizee/test/methods-plain.js
generated
vendored
Normal file
48
node_modules/memoizee/test/methods-plain.js
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
/* eslint id-length: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var d = require("d");
|
||||
|
||||
require("../ext/dispose");
|
||||
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);
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
obj = Object.create(obj);
|
||||
obj.someFn(3, 7);
|
||||
obj.someFn(5, 8);
|
||||
obj.someFn(12, 4);
|
||||
a.deep(value, [], "Pre");
|
||||
obj.someFn(5, 8);
|
||||
obj.someFn.deleteRef(5, 8);
|
||||
a.deep(value, [], "Pre");
|
||||
obj.someFn.deleteRef(5, 8);
|
||||
a.deep(value, [13], "#1");
|
||||
value = [];
|
||||
obj.someFn.deleteRef(12, 4);
|
||||
a.deep(value, [16], "#2");
|
||||
|
||||
value = [];
|
||||
obj.someFn(77, 11);
|
||||
obj.someFn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
};
|
45
node_modules/memoizee/test/methods.js
generated
vendored
Normal file
45
node_modules/memoizee/test/methods.js
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
obj = Object.create(obj);
|
||||
obj.someFn(3, 7);
|
||||
obj.someFn(5, 8);
|
||||
obj.someFn(12, 4);
|
||||
a.deep(value, [], "Pre");
|
||||
obj.someFn(5, 8);
|
||||
obj.someFn.deleteRef(5, 8);
|
||||
a.deep(value, [], "Pre");
|
||||
obj.someFn.deleteRef(5, 8);
|
||||
a.deep(value, [13], "#1");
|
||||
value = [];
|
||||
obj.someFn.deleteRef(12, 4);
|
||||
a.deep(value, [16], "#2");
|
||||
|
||||
value = [];
|
||||
obj.someFn(77, 11);
|
||||
obj.someFn.clear();
|
||||
a.deep(value, [10, 88], "Clear all");
|
||||
};
|
62
node_modules/memoizee/test/normalizers/get-1.js
generated
vendored
Normal file
62
node_modules/memoizee/test/normalizers/get-1.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
/* 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;
|
||||
};
|
||||
|
||||
fn = memoize(fn);
|
||||
return {
|
||||
"No arg": function () {
|
||||
i = 0;
|
||||
a(fn(), undefined, "First");
|
||||
a(fn(), undefined, "Second");
|
||||
a(fn(), undefined, "Third");
|
||||
a(i, 1, "Called once");
|
||||
},
|
||||
"Arg": function () {
|
||||
var x = {};
|
||||
i = 0;
|
||||
a(fn(x, 8), x, "First");
|
||||
a(fn(x, 4), x, "Second");
|
||||
a(fn(x, 2), x, "Third");
|
||||
a(i, 1, "Called once");
|
||||
},
|
||||
"Other Arg": function () {
|
||||
var x = {};
|
||||
i = 0;
|
||||
a(fn(x, 2), x, "First");
|
||||
a(fn(x, 9), x, "Second");
|
||||
a(fn(x, 3), x, "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: 1 });
|
||||
a(mfn(3), 4, "Init");
|
||||
a(mfn(4, x, 1), 6, "Init #2");
|
||||
mfn.delete(4);
|
||||
a(mfn(3, x, 1), 4, "Cached");
|
||||
mfn(3, x, 1);
|
||||
a(i, 2, "Pre clear");
|
||||
mfn.delete(3, x, 1);
|
||||
a(i, 2, "After clear");
|
||||
a(mfn(3, x, 1), 6, "Reinit");
|
||||
a(i, 3, "Reinit count");
|
||||
a(mfn(3, x, 1), 6, "Reinit Cached");
|
||||
a(i, 3, "Reinit count");
|
||||
}
|
||||
};
|
98
node_modules/memoizee/test/normalizers/get-fixed.js
generated
vendored
Normal file
98
node_modules/memoizee/test/normalizers/get-fixed.js
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
/* 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;
|
||||
|
||||
fn = memoize(fn);
|
||||
return {
|
||||
"No args": function () {
|
||||
i = 0;
|
||||
a.deep(r = fn(), [undefined, undefined, undefined], "First");
|
||||
a(fn(), r, "Second");
|
||||
a(fn(), r, "Third");
|
||||
a(i, 1, "Called once");
|
||||
},
|
||||
"Some Args": function () {
|
||||
var x = {};
|
||||
i = 0;
|
||||
a.deep(r = fn(x, 8), [x, 8, undefined], "First");
|
||||
a(fn(x, 8), r, "Second");
|
||||
a(fn(x, 8), r, "Third");
|
||||
a(i, 1, "Called once");
|
||||
return {
|
||||
Other: function () {
|
||||
a.deep(r = fn(x, 5), [x, 5, undefined], "Second");
|
||||
a(fn(x, 5), r, "Third");
|
||||
a(i, 2, "Called once");
|
||||
}
|
||||
};
|
||||
},
|
||||
"Full stuff": function () {
|
||||
var x = {};
|
||||
i = 0;
|
||||
a.deep(r = fn(x, 8, 23, 98), [x, 8, 23], "First");
|
||||
a(fn(x, 8, 23, 43), r, "Second");
|
||||
a(fn(x, 8, 23, 9), r, "Third");
|
||||
a(i, 1, "Called once");
|
||||
return {
|
||||
Other: function () {
|
||||
a.deep(r = fn(x, 23, 8, 13), [x, 23, 8], "Second");
|
||||
a(fn(x, 23, 8, 22), r, "Third");
|
||||
a(i, 2, "Called once");
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
"Delete": function (a) {
|
||||
var i = 0, fn, mfn, x = {};
|
||||
|
||||
fn = function (a, b, c) {
|
||||
return a + ++i;
|
||||
};
|
||||
mfn = memoize(fn);
|
||||
a(mfn(3, x, 1), 4, "Init");
|
||||
a(mfn(4, x, 1), 6, "Init #2");
|
||||
mfn.delete(4, x, 1);
|
||||
a(mfn(3, x, 1), 4, "Cached");
|
||||
mfn(3, x, 1);
|
||||
a(i, 2, "Pre clear");
|
||||
mfn.delete(3, x, 1);
|
||||
a(i, 2, "After clear");
|
||||
a(mfn(3, x, 1), 6, "Reinit");
|
||||
a(i, 3, "Reinit count");
|
||||
a(mfn(3, x, 1), 6, "Reinit Cached");
|
||||
a(i, 3, "Reinit count");
|
||||
},
|
||||
"Clear": function (a) {
|
||||
var i = 0, fn, x = {};
|
||||
|
||||
fn = function () {
|
||||
++i;
|
||||
return arguments;
|
||||
};
|
||||
|
||||
fn = memoize(fn, { length: 3 });
|
||||
fn(1, x, 3);
|
||||
fn(1, x, 4);
|
||||
fn(1, x, 3);
|
||||
fn(1, x, 4);
|
||||
a(i, 2, "Pre clear");
|
||||
fn.clear();
|
||||
fn(1, x, 3);
|
||||
fn(1, x, 4);
|
||||
fn(1, x, 3);
|
||||
fn(1, x, 4);
|
||||
a(i, 4, "After clear");
|
||||
}
|
||||
};
|
70
node_modules/memoizee/test/normalizers/get-primitive-fixed.js
generated
vendored
Normal file
70
node_modules/memoizee/test/normalizers/get-primitive-fixed.js
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
/* 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";
|
||||
}
|
||||
};
|
||||
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";
|
||||
}
|
||||
};
|
||||
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"
|
||||
);
|
||||
a(mfn(y, "bar", "zeta"), "foobarzeta", "#3");
|
||||
a(i, 2, "Called twice");
|
||||
},
|
||||
"Clear": function (a) {
|
||||
var i = 0, fn;
|
||||
fn = memoize(function (x) {
|
||||
if (++i < 2) fn(x);
|
||||
});
|
||||
a.throws(function () {
|
||||
fn("foo");
|
||||
}, "CIRCULAR_INVOCATION");
|
||||
|
||||
i = 0;
|
||||
fn = memoize(function (x, y) {
|
||||
if (++i < 2) fn(x, y);
|
||||
});
|
||||
a.throws(function () {
|
||||
fn("foo", "bar");
|
||||
}, "CIRCULAR_INVOCATION");
|
||||
}
|
||||
};
|
66
node_modules/memoizee/test/normalizers/get.js
generated
vendored
Normal file
66
node_modules/memoizee/test/normalizers/get.js
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var aFrom = require("es5-ext/array/from")
|
||||
, memoize = require("../..");
|
||||
|
||||
module.exports = function () {
|
||||
return {
|
||||
"": function (a) {
|
||||
var i = 0
|
||||
, fn = function () {
|
||||
++i;
|
||||
return arguments;
|
||||
}
|
||||
, r;
|
||||
|
||||
fn = memoize(fn, { length: false });
|
||||
return {
|
||||
"No args": function () {
|
||||
i = 0;
|
||||
a.deep(aFrom(r = fn()), [], "First");
|
||||
a(fn(), r, "Second");
|
||||
a(fn(), r, "Third");
|
||||
a(i, 1, "Called once");
|
||||
},
|
||||
"Some Args": function () {
|
||||
var x = {};
|
||||
i = 0;
|
||||
a.deep(aFrom(r = fn(x, 8)), [x, 8], "First");
|
||||
a(fn(x, 8), r, "Second");
|
||||
a(fn(x, 8), r, "Third");
|
||||
a(i, 1, "Called once");
|
||||
},
|
||||
"Many args": function () {
|
||||
var x = {};
|
||||
i = 0;
|
||||
a.deep(aFrom(r = fn(x, 8, 23, 98)), [x, 8, 23, 98], "First");
|
||||
a(fn(x, 8, 23, 98), r, "Second");
|
||||
a(fn(x, 8, 23, 98), r, "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: false });
|
||||
a(mfn(3, x, 1), 4, "Init");
|
||||
a(mfn(4, x, 1), 6, "Init #2");
|
||||
mfn.delete(4, x, 1);
|
||||
a(mfn(3, x, 1), 4, "Cached");
|
||||
mfn(3, x, 1);
|
||||
a(i, 2, "Pre clear");
|
||||
mfn.delete(3, x, 1);
|
||||
a(i, 2, "After clear");
|
||||
a(mfn(3, x, 1), 6, "Reinit");
|
||||
a(i, 3, "Reinit count");
|
||||
a(mfn(3, x, 1), 6, "Reinit Cached");
|
||||
a(i, 3, "Reinit count");
|
||||
}
|
||||
};
|
||||
};
|
28
node_modules/memoizee/test/normalizers/primitive.js
generated
vendored
Normal file
28
node_modules/memoizee/test/normalizers/primitive.js
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
/* eslint id-length: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../..")
|
||||
, join = Array.prototype.join;
|
||||
|
||||
module.exports = function (a) {
|
||||
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");
|
||||
a(i, 1, "Called once");
|
||||
a(mfn(y, "bar"), "foo|bar", "#3");
|
||||
a(i, 2, "Called twice");
|
||||
a(mfn(y, "bar"), "foo|bar", "#4");
|
||||
a(i, 2, "Called twice #2");
|
||||
};
|
56
node_modules/memoizee/test/plain.js
generated
vendored
Normal file
56
node_modules/memoizee/test/plain.js
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
/* 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";
|
||||
}
|
||||
};
|
||||
mfn = t(fn, { primitive: true });
|
||||
a(typeof mfn, "function", "Returns");
|
||||
a(mfn.__memoized__, true, "Marked");
|
||||
a(t(mfn), mfn, "Do not memoize memoized");
|
||||
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";
|
||||
}
|
||||
};
|
||||
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"
|
||||
);
|
||||
a(mfn(y, "bar", "zeta"), "foobarzeta", "#3");
|
||||
a(i, 2, "Called twice");
|
||||
}
|
||||
};
|
||||
};
|
14
node_modules/memoizee/test/profile.js
generated
vendored
Normal file
14
node_modules/memoizee/test/profile.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
/* eslint no-empty-function: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var memoize = require("../plain");
|
||||
|
||||
module.exports = function (t, a) {
|
||||
memoize(function () {})();
|
||||
memoize(function () {}, { profileName: "test" })();
|
||||
a(typeof t.statistics, "object", "Access to statistics");
|
||||
a(Object.keys(t.statistics).length, 2, "Statistics collected including named function");
|
||||
a(typeof t.log, "function", "Access to log function");
|
||||
a(typeof t.log(), "string", "Log outputs string");
|
||||
};
|
50
node_modules/memoizee/test/weak-plain.js
generated
vendored
Normal file
50
node_modules/memoizee/test/weak-plain.js
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
require("../ext/dispose");
|
||||
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);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
a(memoized(obj, 3, 7), 10);
|
||||
a(memoized(obj, 5, 8), 13);
|
||||
a(memoized(obj, 12, 4), 16);
|
||||
a.deep(value, [], "Pre");
|
||||
a(memoized(obj, 5, 8), 13);
|
||||
memoized.deleteRef(obj, 5, 8);
|
||||
a.deep(value, [], "Pre");
|
||||
memoized.deleteRef(obj, 5, 8);
|
||||
a.deep(value, [13], "#1");
|
||||
value = [];
|
||||
memoized.deleteRef(obj, 12, 4);
|
||||
a.deep(value, [16], "#2");
|
||||
|
||||
value = [];
|
||||
memoized(obj, 77, 11);
|
||||
|
||||
x = {};
|
||||
y = {};
|
||||
z = {};
|
||||
memoized = t(function (arg) {
|
||||
return ++count;
|
||||
});
|
||||
a(memoized(x), 1);
|
||||
a(memoized(y), 2);
|
||||
a(memoized(x), 1);
|
||||
a(memoized(z), 3);
|
||||
a(count, 3);
|
||||
};
|
62
node_modules/memoizee/test/weak.js
generated
vendored
Normal file
62
node_modules/memoizee/test/weak.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
a(memoized(obj, 3, 7), 10);
|
||||
a(memoized(obj, 5, 8), 13);
|
||||
a(memoized(obj, 12, 4), 16);
|
||||
a.deep(value, [], "Pre");
|
||||
a(memoized(obj, 5, 8), 13);
|
||||
memoized.deleteRef(obj, 5, 8);
|
||||
a.deep(value, [], "Pre");
|
||||
memoized.deleteRef(obj, 5, 8);
|
||||
a.deep(value, [13], "#1");
|
||||
value = [];
|
||||
memoized.deleteRef(obj, 12, 4);
|
||||
a.deep(value, [16], "#2");
|
||||
|
||||
value = [];
|
||||
memoized(obj, 77, 11);
|
||||
|
||||
x = {};
|
||||
y = {};
|
||||
z = {};
|
||||
memoized = t(function (arg) {
|
||||
return ++count;
|
||||
});
|
||||
a(memoized(x), 1);
|
||||
a(memoized(y), 2);
|
||||
a(memoized(x), 1);
|
||||
a(memoized(z), 3);
|
||||
a(count, 3);
|
||||
|
||||
count = 0;
|
||||
memoized = t(
|
||||
function (arg) {
|
||||
return ++count;
|
||||
},
|
||||
{ maxAge: 1 }
|
||||
);
|
||||
|
||||
memoized(obj);
|
||||
setTimeout(function () {
|
||||
memoized(obj);
|
||||
a(count, 2);
|
||||
d();
|
||||
}, 100);
|
||||
};
|
Reference in New Issue
Block a user