Debian Codegraph @

memoizee/test/normalizers/get-1.js

raw
1 /* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
2
3 "use strict";
4
5 var memoize = require("../..");
6
7 module.exports = {
8 "": function (t, a) {
9 var i = 0
10 , fn = function (x) {
11 ++i;
12 return x;
13 };
14
15 fn = memoize(fn);
16 return {
17 "No arg": function () {
18 i = 0;
19 a(fn(), undefined, "First");
20 a(fn(), undefined, "Second");
21 a(fn(), undefined, "Third");
22 a(i, 1, "Called once");
23 },
24 "Arg": function () {
25 var x = {};
26 i = 0;
27 a(fn(x, 8), x, "First");
28 a(fn(x, 4), x, "Second");
29 a(fn(x, 2), x, "Third");
30 a(i, 1, "Called once");
31 },
32 "Other Arg": function () {
33 var x = {};
34 i = 0;
35 a(fn(x, 2), x, "First");
36 a(fn(x, 9), x, "Second");
37 a(fn(x, 3), x, "Third");
38 a(i, 1, "Called once");
39 },
40 };
41 },
42 "Delete": function (a) {
43 var i = 0, fn, mfn, x = {};
44
45 fn = function (a, b, c) { return a + ++i; };
46 mfn = memoize(fn, { length: 1 });
47 a(mfn(3), 4, "Init");
48 a(mfn(4, x, 1), 6, "Init #2");
49 mfn.delete(4);
50 a(mfn(3, x, 1), 4, "Cached");
51 mfn(3, x, 1);
52 a(i, 2, "Pre clear");
53 mfn.delete(3, x, 1);
54 a(i, 2, "After clear");
55 a(mfn(3, x, 1), 6, "Reinit");
56 a(i, 3, "Reinit count");
57 a(mfn(3, x, 1), 6, "Reinit Cached");
58 a(i, 3, "Reinit count");
59 },
60 };