mirror of
https://github.com/BreizhHardware/memoizee.git
synced 2026-01-18 16:37:21 +01:00
style: Prettify
This commit is contained in:
89
README.md
89
README.md
@@ -13,19 +13,19 @@ Memoization is best technique to save on memory or CPU cycles when we deal with
|
||||
|
||||
### Features
|
||||
|
||||
* Works with any type of function arguments – **no serialization is needed**
|
||||
* Works with [**any length of function arguments**](#arguments-length). Length can be set as fixed or dynamic.
|
||||
* One of the [**fastest**](#benchmarks) available solutions.
|
||||
* Support for [**promises**](#promise-returning-functions) and [**asynchronous functions**](#nodejs-callback-style-functions)
|
||||
* [**Primitive mode**](#primitive-mode) which assures fast performance when arguments are convertible to strings.
|
||||
* [**WeakMap based mode**](#weakmap-based-configurations) for garbage collection friendly configuration
|
||||
* Can be configured [**for methods**](#memoizing-methods) (when `this` counts in)
|
||||
* Cache [**can be cleared manually**](#manual-clean-up) or [**after specified timeout**](#expire-cache-after-given-period-of-time)
|
||||
* Cache size can be **[limited on LRU basis](#limiting-cache-size)**
|
||||
* Optionally [**accepts resolvers**](#argument-resolvers) that normalize function arguments before passing them to underlying function.
|
||||
* Optional [**reference counter mode**](#reference-counter), that allows more sophisticated cache management
|
||||
* [**Profile tool**](#profiling--statistics) that provides valuable usage statistics
|
||||
* Covered by [**over 500 unit tests**](#tests)
|
||||
- Works with any type of function arguments – **no serialization is needed**
|
||||
- Works with [**any length of function arguments**](#arguments-length). Length can be set as fixed or dynamic.
|
||||
- One of the [**fastest**](#benchmarks) available solutions.
|
||||
- Support for [**promises**](#promise-returning-functions) and [**asynchronous functions**](#nodejs-callback-style-functions)
|
||||
- [**Primitive mode**](#primitive-mode) which assures fast performance when arguments are convertible to strings.
|
||||
- [**WeakMap based mode**](#weakmap-based-configurations) for garbage collection friendly configuration
|
||||
- Can be configured [**for methods**](#memoizing-methods) (when `this` counts in)
|
||||
- Cache [**can be cleared manually**](#manual-clean-up) or [**after specified timeout**](#expire-cache-after-given-period-of-time)
|
||||
- Cache size can be **[limited on LRU basis](#limiting-cache-size)**
|
||||
- Optionally [**accepts resolvers**](#argument-resolvers) that normalize function arguments before passing them to underlying function.
|
||||
- Optional [**reference counter mode**](#reference-counter), that allows more sophisticated cache management
|
||||
- [**Profile tool**](#profiling--statistics) that provides valuable usage statistics
|
||||
- Covered by [**over 500 unit tests**](#tests)
|
||||
|
||||
### Installation
|
||||
|
||||
@@ -46,9 +46,7 @@ To port it to Browser or any other (non CJS) environment, use your favorite CJS
|
||||
```javascript
|
||||
var memoize = require("memoizee");
|
||||
|
||||
var fn = function(one, two, three) {
|
||||
/* ... */
|
||||
};
|
||||
var fn = function (one, two, three) { /* ... */ };
|
||||
|
||||
memoized = memoize(fn);
|
||||
|
||||
@@ -56,7 +54,7 @@ memoized("foo", 3, "bar");
|
||||
memoized("foo", 3, "bar"); // Cache hit
|
||||
```
|
||||
|
||||
__Note__: Invocations that throw exceptions are not cached.
|
||||
**Note**: Invocations that throw exceptions are not cached.
|
||||
|
||||
### Configuration
|
||||
|
||||
@@ -76,7 +74,7 @@ memoized("foo", 3, {}); // Third argument is ignored (but passed to underlying f
|
||||
memoized("foo", 3, 13); // Cache hit
|
||||
```
|
||||
|
||||
__Note:__ [Parameters predefined with default values (ES2015+ feature)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters) are not reflected in function's `length`, therefore if you want to memoize them as well, you need to tweak `length` setting accordingly
|
||||
**Note:** [Parameters predefined with default values (ES2015+ feature)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters) are not reflected in function's `length`, therefore if you want to memoize them as well, you need to tweak `length` setting accordingly
|
||||
|
||||
Dynamic _length_ behavior can be forced by setting _length_ to `false`, that means memoize will work with any number of arguments.
|
||||
|
||||
@@ -108,8 +106,8 @@ memoized("/path/one"); // Cache hit
|
||||
|
||||
By default cache id for given call is resolved either by:
|
||||
|
||||
* Direct Comparison of values passed in arguments as they are. In such case two different objects, even if their characteristics is exactly same (e.g. `var a = { foo: 'bar' }, b = { foo: 'bar' }`) will be treated as two different values.
|
||||
* Comparison of stringified values of given arguments (`primitive` mode), which serves well, when arguments are expected to be primitive values, or objects that stringify naturally do unique values (e.g. arrays)
|
||||
- Direct Comparison of values passed in arguments as they are. In such case two different objects, even if their characteristics is exactly same (e.g. `var a = { foo: 'bar' }, b = { foo: 'bar' }`) will be treated as two different values.
|
||||
- Comparison of stringified values of given arguments (`primitive` mode), which serves well, when arguments are expected to be primitive values, or objects that stringify naturally do unique values (e.g. arrays)
|
||||
|
||||
Still above two methods do not serve all cases, e.g. if we want to memoize function where arguments are hash objects which we do not want to compare by instance but by its content.
|
||||
|
||||
@@ -130,7 +128,7 @@ var mfn = memoize(
|
||||
normalizer: function (args) {
|
||||
// args is arguments object as accessible in memoized function
|
||||
return JSON.stringify(args[0]);
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -157,7 +155,7 @@ var mfn = memoize(
|
||||
normalizer: function (args) {
|
||||
// args is arguments object as accessible in memoized function
|
||||
return JSON.stringify(deepSortedEntries(args[0]));
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -174,14 +172,7 @@ memoized = memoize(fn, { length: 2, resolvers: [String, Boolean] });
|
||||
|
||||
memoized(12, [1, 2, 3].length);
|
||||
memoized("12", true); // Cache hit
|
||||
memoized(
|
||||
{
|
||||
toString: function() {
|
||||
return "12";
|
||||
}
|
||||
},
|
||||
{}
|
||||
); // Cache hit
|
||||
memoized({ toString: function () { return "12"; } }, {}); // Cache hit
|
||||
```
|
||||
|
||||
**Note. If your arguments are collections (arrays or hashes) that you want to memoize by content (not by self objects), you need to cast them to strings**, for it's best to just use [primitive mode](#primitive-mode). Arrays have standard string representation and work with primitive mode out of a box, for hashes you need to define `toString` method, that will produce unique string descriptions, or rely on `JSON.stringify`.
|
||||
@@ -199,9 +190,7 @@ the result is immediately removed from memoize cache, and not kept as further re
|
||||
|
||||
```javascript
|
||||
var afn = function (a, b) {
|
||||
return new Promise(function(res) {
|
||||
res(a + b);
|
||||
});
|
||||
return new Promise(function (res) { res(a + b); });
|
||||
};
|
||||
memoized = memoize(afn, { promise: true });
|
||||
|
||||
@@ -220,12 +209,12 @@ memoized = memoize(afn, { promise: "done:finally" });
|
||||
|
||||
Supported modes
|
||||
|
||||
* `then` _(default)_. Values are resolved purely by passing callbacks to `promise.then`. **Side effect is that eventual unhandled rejection on given promise
|
||||
- `then` _(default)_. Values are resolved purely by passing callbacks to `promise.then`. **Side effect is that eventual unhandled rejection on given promise
|
||||
come with no logged warning!**, and that to avoid implied error swallowing both states are resolved tick after callbacks were invoked
|
||||
|
||||
* `done` Values are resolved purely by passing callback to `done` method. **Side effect is that eventual unhandled rejection on given promise come with no logged warning!**.
|
||||
- `done` Values are resolved purely by passing callback to `done` method. **Side effect is that eventual unhandled rejection on given promise come with no logged warning!**.
|
||||
|
||||
* `done:finally` The only method that may work with no side-effects assuming that promise implementaion does not throw unconditionally
|
||||
- `done:finally` The only method that may work with no side-effects assuming that promise implementaion does not throw unconditionally
|
||||
if no _onFailure_ callback was passed to `done`, and promise error was handled by other consumer (this is not commonly implemented _done_ behavior). Otherwise side-effect is that exception is thrown on promise rejection (highly not recommended)
|
||||
|
||||
##### Node.js callback style functions
|
||||
@@ -235,9 +224,7 @@ Operations that result with an error are not cached.
|
||||
|
||||
```javascript
|
||||
afn = function (a, b, cb) {
|
||||
setTimeout(function() {
|
||||
cb(null, a + b);
|
||||
}, 200);
|
||||
setTimeout(function () { cb(null, a + b); }, 200);
|
||||
};
|
||||
memoized = memoize(afn, { async: true });
|
||||
|
||||
@@ -283,7 +270,7 @@ Object.defineProperties(
|
||||
// ... method logic
|
||||
},
|
||||
{ someOption: true }
|
||||
)
|
||||
),
|
||||
})
|
||||
);
|
||||
```
|
||||
@@ -298,9 +285,7 @@ It can be combined with other options mentioned across documentation. However du
|
||||
```javascript
|
||||
var memoize = require("memoizee/weak");
|
||||
|
||||
var memoized = memoize(function(obj) {
|
||||
return Object.keys(obj);
|
||||
});
|
||||
var memoized = memoize(function (obj) { return Object.keys(obj); });
|
||||
|
||||
var obj = { foo: true, bar: false };
|
||||
memoized(obj);
|
||||
@@ -422,11 +407,7 @@ memoized("bar", 7); // Re-executed, Cache cleared for 'lorem', 11
|
||||
You can register a callback to be called on each value removed from the cache:
|
||||
|
||||
```javascript
|
||||
memoized = memoize(fn, {
|
||||
dispose: function(value) {
|
||||
/*…*/
|
||||
}
|
||||
});
|
||||
memoized = memoize(fn, { dispose: function (value) { /*…*/ } });
|
||||
|
||||
var foo3 = memoized("foo", 3);
|
||||
var bar7 = memoized("bar", 7);
|
||||
@@ -494,10 +475,10 @@ Memoize statistics:
|
||||
------------------------------------------------------------
|
||||
```
|
||||
|
||||
* _Init_ – Initial hits
|
||||
* _Cache_ – Cache hits
|
||||
* _%Cache_ – What's the percentage of cache hits (of all function calls)
|
||||
* _Source location_ – Where in the source code given memoization was initialized
|
||||
- _Init_ – Initial hits
|
||||
- _Cache_ – Cache hits
|
||||
- _%Cache_ – What's the percentage of cache hits (of all function calls)
|
||||
- _Source location_ – Where in the source code given memoization was initialized
|
||||
|
||||
### Tests
|
||||
|
||||
@@ -525,8 +506,8 @@ To report a security vulnerability, please use the [Tidelift security contact](h
|
||||
|
||||
### Contributors
|
||||
|
||||
* [@puzrin](https://github.com/puzrin) (Vitaly Puzrin)
|
||||
* Proposal and help with coining right _pre-fetch_ logic for [_maxAge_](https://github.com/medikoo/memoize#expire-cache-after-given-period-of-time) variant
|
||||
- [@puzrin](https://github.com/puzrin) (Vitaly Puzrin)
|
||||
- Proposal and help with coining right _pre-fetch_ logic for [_maxAge_](https://github.com/medikoo/memoize#expire-cache-after-given-period-of-time) variant
|
||||
|
||||
[nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/memoizee/branches/master/shields_badge.svg
|
||||
[nix-build-url]: https://semaphoreci.com/medikoo-org/memoizee
|
||||
|
||||
@@ -31,9 +31,7 @@ var now = Date.now
|
||||
, lruObj;
|
||||
|
||||
getFib = function (memoize, opts) {
|
||||
var fib = memoize(function (x) {
|
||||
return x < 2 ? 1 : fib(x - 1) + fib(x - 2);
|
||||
}, opts);
|
||||
var fib = memoize(function (x) { return x < 2 ? 1 : fib(x - 1) + fib(x - 2); }, opts);
|
||||
return fib;
|
||||
};
|
||||
|
||||
@@ -134,7 +132,5 @@ forEach(
|
||||
console.log(currentIndex + 1 + ":", pad.call(value, " ", 5) + "ms ", name);
|
||||
},
|
||||
null,
|
||||
function (a, b) {
|
||||
return this[a] - this[b];
|
||||
}
|
||||
function (a, b) { return this[a] - this[b]; }
|
||||
);
|
||||
|
||||
@@ -16,7 +16,7 @@ module.exports = {
|
||||
"type-empty": [2, "never"],
|
||||
"type-enum": [
|
||||
2, "always",
|
||||
["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"]
|
||||
]
|
||||
}
|
||||
["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"],
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ require("../lib/registered-extensions").async = function (tbi, conf) {
|
||||
currentCallback = last;
|
||||
args = slice.call(args, 0, -1);
|
||||
}
|
||||
return base.apply(currentContext = this, currentArgs = args);
|
||||
return base.apply((currentContext = this), (currentArgs = args));
|
||||
}, base);
|
||||
try { mixin(conf.memoized, base); }
|
||||
catch (ignore) {}
|
||||
|
||||
@@ -5,29 +5,23 @@
|
||||
var callable = require("es5-ext/object/valid-callable")
|
||||
, forEach = require("es5-ext/object/for-each")
|
||||
, extensions = require("../lib/registered-extensions")
|
||||
|
||||
, apply = Function.prototype.apply;
|
||||
|
||||
extensions.dispose = function (dispose, conf, options) {
|
||||
var del;
|
||||
callable(dispose);
|
||||
if ((options.async && extensions.async) || (options.promise && extensions.promise)) {
|
||||
conf.on("deleteasync", del = function (id, resultArray) {
|
||||
apply.call(dispose, null, resultArray);
|
||||
});
|
||||
conf.on(
|
||||
"deleteasync",
|
||||
(del = function (id, resultArray) { apply.call(dispose, null, resultArray); })
|
||||
);
|
||||
conf.on("clearasync", function (cache) {
|
||||
forEach(cache, function (result, id) {
|
||||
del(id, result);
|
||||
});
|
||||
forEach(cache, function (result, id) { del(id, result); });
|
||||
});
|
||||
return;
|
||||
}
|
||||
conf.on("delete", del = function (id, result) {
|
||||
dispose(result);
|
||||
});
|
||||
conf.on("delete", (del = function (id, result) { dispose(result); }));
|
||||
conf.on("clear", function (cache) {
|
||||
forEach(cache, function (result, id) {
|
||||
del(id, result);
|
||||
});
|
||||
forEach(cache, function (result, id) { del(id, result); });
|
||||
});
|
||||
};
|
||||
|
||||
13
ext/max.js
13
ext/max.js
@@ -13,14 +13,19 @@ extensions.max = function (max, conf, options) {
|
||||
if (!max) return;
|
||||
|
||||
queue = lruQueue(max);
|
||||
postfix = (options.async && extensions.async) || (options.promise && extensions.promise)
|
||||
? "async" : "";
|
||||
postfix =
|
||||
(options.async && extensions.async) || (options.promise && extensions.promise)
|
||||
? "async"
|
||||
: "";
|
||||
|
||||
conf.on("set" + postfix, hit = function (id) {
|
||||
conf.on(
|
||||
"set" + postfix,
|
||||
(hit = function (id) {
|
||||
id = queue.hit(id);
|
||||
if (id === undefined) return;
|
||||
conf.delete(id);
|
||||
});
|
||||
})
|
||||
);
|
||||
conf.on("get" + postfix, hit);
|
||||
conf.on("delete" + postfix, queue.delete);
|
||||
conf.on("clear" + postfix, queue.clear);
|
||||
|
||||
@@ -4,28 +4,22 @@
|
||||
|
||||
var d = require("d")
|
||||
, extensions = require("../lib/registered-extensions")
|
||||
|
||||
, create = Object.create, defineProperties = Object.defineProperties;
|
||||
, create = Object.create
|
||||
, defineProperties = Object.defineProperties;
|
||||
|
||||
extensions.refCounter = function (ignore, conf, options) {
|
||||
var cache, postfix;
|
||||
|
||||
cache = create(null);
|
||||
postfix = (options.async && extensions.async) || (options.promise && extensions.promise)
|
||||
? "async" : "";
|
||||
postfix =
|
||||
(options.async && extensions.async) || (options.promise && extensions.promise)
|
||||
? "async"
|
||||
: "";
|
||||
|
||||
conf.on("set" + postfix, function (id, length) {
|
||||
cache[id] = length || 1;
|
||||
});
|
||||
conf.on("get" + postfix, function (id) {
|
||||
++cache[id];
|
||||
});
|
||||
conf.on("delete" + postfix, function (id) {
|
||||
delete cache[id];
|
||||
});
|
||||
conf.on("clear" + postfix, function () {
|
||||
cache = {};
|
||||
});
|
||||
conf.on("set" + postfix, function (id, length) { cache[id] = length || 1; });
|
||||
conf.on("get" + postfix, function (id) { ++cache[id]; });
|
||||
conf.on("delete" + postfix, function (id) { delete cache[id]; });
|
||||
conf.on("clear" + postfix, function () { cache = {}; });
|
||||
|
||||
defineProperties(conf.memoized, {
|
||||
deleteRef: d(function () {
|
||||
@@ -43,6 +37,6 @@ extensions.refCounter = function (ignore, conf, options) {
|
||||
if (id === null) return 0;
|
||||
if (!cache[id]) return 0;
|
||||
return cache[id];
|
||||
})
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -136,7 +136,7 @@ module.exports = function (original, length, options) {
|
||||
return on.call(this, type, listener);
|
||||
},
|
||||
emit: emit,
|
||||
updateEnv: function () { original = conf.original; }
|
||||
updateEnv: function () { original = conf.original; },
|
||||
};
|
||||
if (get) {
|
||||
extDel = defineLength(function (arg) {
|
||||
@@ -176,7 +176,7 @@ module.exports = function (original, length, options) {
|
||||
delete: d(extDel),
|
||||
clear: d(conf.clear),
|
||||
_get: d(extGet),
|
||||
_has: d(extHas)
|
||||
_has: d(extHas),
|
||||
});
|
||||
return conf;
|
||||
};
|
||||
|
||||
@@ -16,9 +16,7 @@ module.exports = function (memoize) {
|
||||
options = normalizeOpts(options);
|
||||
if (length === undefined) {
|
||||
length = resolveLength(
|
||||
options.length,
|
||||
fn.length,
|
||||
options.async && extensions.async
|
||||
options.length, fn.length, options.async && extensions.async
|
||||
);
|
||||
}
|
||||
options.normalizer = options.getNormalizer(length);
|
||||
|
||||
@@ -7,15 +7,13 @@ var toArray = require("es5-ext/array/to-array")
|
||||
var slice = Array.prototype.slice, resolveArgs;
|
||||
|
||||
resolveArgs = function (args) {
|
||||
return this.map(function (resolve, i) {
|
||||
return resolve ? resolve(args[i]) : args[i];
|
||||
}).concat(slice.call(args, this.length));
|
||||
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 (resolve) {
|
||||
if (isValue(resolve)) callable(resolve);
|
||||
});
|
||||
resolvers.forEach(function (resolve) { if (isValue(resolve)) callable(resolve); });
|
||||
return resolveArgs.bind(resolvers);
|
||||
};
|
||||
|
||||
@@ -58,7 +58,7 @@ module.exports = function (memoize) {
|
||||
delete: d(function (obj) {
|
||||
if (resolve) obj = resolve(arguments)[0];
|
||||
return map.delete(obj);
|
||||
})
|
||||
}),
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ module.exports = function (memoize) {
|
||||
);
|
||||
}
|
||||
}
|
||||
map.set(obj, memoizer = memoize(partial.call(fn, obj), options));
|
||||
map.set(obj, (memoizer = memoize(partial.call(fn, obj), options)));
|
||||
}
|
||||
return memoizer.apply(this, slice.call(args, 1));
|
||||
}, length),
|
||||
@@ -99,7 +99,7 @@ module.exports = function (memoize) {
|
||||
if (!memoizer) return;
|
||||
memoizer.delete.apply(this, slice.call(args, 1));
|
||||
}, length)
|
||||
)
|
||||
),
|
||||
}
|
||||
);
|
||||
if (!options.refCounter) return memoized;
|
||||
@@ -127,7 +127,7 @@ module.exports = function (memoize) {
|
||||
if (!memoizer) return 0;
|
||||
return memoizer.getRefCount.apply(this, slice.call(args, 1));
|
||||
}, length)
|
||||
)
|
||||
),
|
||||
});
|
||||
return memoized;
|
||||
};
|
||||
|
||||
@@ -24,6 +24,6 @@ module.exports = function () {
|
||||
clear: function () {
|
||||
argsMap = [];
|
||||
cache = [];
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -66,6 +66,6 @@ module.exports = function (length) {
|
||||
clear: function () {
|
||||
map = [[], []];
|
||||
cache = create(null);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
module.exports = function (length) {
|
||||
if (!length) {
|
||||
return function () {
|
||||
return "";
|
||||
};
|
||||
return function () { return ""; };
|
||||
}
|
||||
return function (args) {
|
||||
var id = String(args[0]), i = 0, currentLength = length;
|
||||
|
||||
@@ -85,6 +85,6 @@ module.exports = function () {
|
||||
clear: function () {
|
||||
map = [];
|
||||
cache = create(null);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module.exports = function (args) {
|
||||
var id, i, length = args.length;
|
||||
if (!length) return "\u0002";
|
||||
id = String(args[i = 0]);
|
||||
id = String(args[(i = 0)]);
|
||||
while (--length) id += "\u0001" + args[++i];
|
||||
return id;
|
||||
};
|
||||
|
||||
10
profile.js
10
profile.js
@@ -9,17 +9,19 @@ var partial = require("es5-ext/function/#/partial")
|
||||
, d = require("d")
|
||||
, memoize = require("./plain");
|
||||
|
||||
var max = Math.max, stats = exports.statistics = {};
|
||||
var max = Math.max, stats = (exports.statistics = {});
|
||||
|
||||
Object.defineProperty(
|
||||
memoize,
|
||||
"__profiler__",
|
||||
memoize, "__profiler__",
|
||||
d(function (conf) {
|
||||
var id, source, data, stack;
|
||||
stack = new Error().stack;
|
||||
if (
|
||||
!stack ||
|
||||
!stack.split("\n").slice(3).some(function (line) {
|
||||
!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;
|
||||
|
||||
2
tea.yaml
2
tea.yaml
@@ -2,5 +2,5 @@
|
||||
---
|
||||
version: 1.0.0
|
||||
codeOwners:
|
||||
- '0x641A74E8f6b1f59ffadc28b220A316c79a65D87e'
|
||||
- "0x641A74E8f6b1f59ffadc28b220A316c79a65D87e"
|
||||
quorum: 1
|
||||
|
||||
@@ -25,40 +25,35 @@ module.exports = function () {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Result #1");
|
||||
}),
|
||||
u,
|
||||
"Initial"
|
||||
u, "Initial"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Result #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
u, "Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 13], "Result B #1");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
u, "Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
u, "Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 13], "Result B #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
u, "Initial #3"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
@@ -70,16 +65,14 @@ module.exports = function () {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
u, "Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
u, "Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
@@ -93,16 +86,14 @@ module.exports = function () {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
u, "Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
++invoked;
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
u, "Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
@@ -129,36 +120,31 @@ module.exports = function () {
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #1");
|
||||
}),
|
||||
u,
|
||||
"Initial"
|
||||
u, "Initial"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
u, "Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result B #1");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
u, "Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #3");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
u, "Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result B #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
u, "Initial #3"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
@@ -168,15 +154,13 @@ module.exports = function () {
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
u, "Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
u, "Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
@@ -184,7 +168,7 @@ module.exports = function () {
|
||||
d();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
"Primitive": {
|
||||
"Success": function (a, d) {
|
||||
@@ -200,39 +184,28 @@ 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"
|
||||
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"
|
||||
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"
|
||||
u, "Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Result #3");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
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"
|
||||
u, "Initial #3"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
@@ -242,15 +215,13 @@ module.exports = function () {
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
u, "Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
u, "Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
@@ -262,15 +233,13 @@ module.exports = function () {
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [null, 10], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
u, "Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [null, 13], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
u, "Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
@@ -296,36 +265,31 @@ module.exports = function () {
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #1");
|
||||
}),
|
||||
u,
|
||||
"Initial"
|
||||
u, "Initial"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
u, "Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result B #1");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
u, "Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result #3");
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
u, "Initial #2"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Result B #2");
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
u, "Initial #3"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
@@ -335,15 +299,13 @@ module.exports = function () {
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Again: Result");
|
||||
}),
|
||||
u,
|
||||
"Again: Initial"
|
||||
u, "Again: Initial"
|
||||
);
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep([err, res], [e, undefined], "Again B: Result");
|
||||
}),
|
||||
u,
|
||||
"Again B: Initial"
|
||||
u, "Again B: Initial"
|
||||
);
|
||||
|
||||
nextTick(function () {
|
||||
@@ -354,34 +316,25 @@ module.exports = function () {
|
||||
},
|
||||
"Primitive null arg case": function (a, d) {
|
||||
var x = {}
|
||||
, mfn = memoize(
|
||||
function f(id, cb) {
|
||||
cb(null, x);
|
||||
},
|
||||
{
|
||||
, mfn = memoize(function f(id, cb) { cb(null, x); }, {
|
||||
async: true,
|
||||
primitive: 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);
|
||||
});
|
||||
nextTick(function () { cb(null, x); });
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { async: true });
|
||||
mfn(1, function (err, i) {
|
||||
a(i, 1, "First");
|
||||
});
|
||||
mfn(1, function (err, i) { a(i, 1, "First"); });
|
||||
mfn.clear();
|
||||
mfn(2, function (err, i) {
|
||||
a(i, 2, "Second");
|
||||
@@ -391,23 +344,17 @@ module.exports = function () {
|
||||
"Sync Clear: Primitive": function (a, d) {
|
||||
var mfn, fn;
|
||||
fn = function (x, cb) {
|
||||
nextTick(function () {
|
||||
cb(null, x);
|
||||
});
|
||||
nextTick(function () { cb(null, x); });
|
||||
};
|
||||
mfn = memoize(fn, { async: true, primitive: true });
|
||||
|
||||
mfn(2, function (err, i) {
|
||||
a(i, 2, "First");
|
||||
});
|
||||
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");
|
||||
});
|
||||
}
|
||||
mfn(2, function (err, i) { a(i, 2, "Third"); });
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ module.exports = function () {
|
||||
x = {};
|
||||
invoked = false;
|
||||
mfn = memoize(function () { return x; }, {
|
||||
dispose: function (val) { invoked = val; }
|
||||
dispose: function (val) { invoked = val; },
|
||||
});
|
||||
|
||||
mfn.delete();
|
||||
@@ -47,7 +47,7 @@ module.exports = function () {
|
||||
fn = function (x, y) { return x + y; };
|
||||
mfn = memoize(fn, {
|
||||
refCounter: true,
|
||||
dispose: function (val) { value.push(val); }
|
||||
dispose: function (val) { value.push(val); },
|
||||
});
|
||||
|
||||
mfn(3, 7);
|
||||
@@ -128,7 +128,7 @@ module.exports = function () {
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
Primitive: {
|
||||
"Sync": function (a) {
|
||||
@@ -156,7 +156,7 @@ module.exports = function () {
|
||||
fn = function (x, y) { return x + y; };
|
||||
mfn = memoize(fn, {
|
||||
refCounter: true,
|
||||
dispose: function (val) { value.push(val); }
|
||||
dispose: function (val) { value.push(val); },
|
||||
});
|
||||
|
||||
mfn(3, 7);
|
||||
@@ -237,7 +237,7 @@ module.exports = function () {
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -169,7 +169,7 @@ module.exports = function () {
|
||||
});
|
||||
}, 100);
|
||||
}, 20);
|
||||
}
|
||||
},
|
||||
},
|
||||
Primitive: {
|
||||
Sync: function (a, d) {
|
||||
@@ -324,7 +324,7 @@ module.exports = function () {
|
||||
});
|
||||
}, 500);
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
},
|
||||
Refetch: {
|
||||
Default: function (a, d) {
|
||||
@@ -450,10 +450,10 @@ module.exports = function () {
|
||||
i, 4,
|
||||
"Called: After Refetch: Before"
|
||||
);
|
||||
mfn(3, 7, function (
|
||||
err,
|
||||
result
|
||||
) {
|
||||
mfn(
|
||||
3,
|
||||
7,
|
||||
function (err, result) {
|
||||
a(
|
||||
result, 10,
|
||||
"Result: After Refetch"
|
||||
@@ -462,12 +462,16 @@ module.exports = function () {
|
||||
i, 4,
|
||||
"Called: After Refetch: After"
|
||||
);
|
||||
mfn(5, 8, function (
|
||||
mfn(
|
||||
5,
|
||||
8,
|
||||
function (
|
||||
err,
|
||||
result
|
||||
) {
|
||||
a(
|
||||
result, 13,
|
||||
result,
|
||||
13,
|
||||
"Result: After Refetch B"
|
||||
);
|
||||
a(
|
||||
@@ -558,8 +562,10 @@ module.exports = function () {
|
||||
},
|
||||
250
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
@@ -856,7 +862,7 @@ module.exports = function () {
|
||||
}, 3000);
|
||||
}, 1000);
|
||||
}, 4500);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
312
test/ext/max.js
312
test/ext/max.js
@@ -11,9 +11,7 @@ module.exports = function () {
|
||||
return {
|
||||
Regular: {
|
||||
Sync: function (a) {
|
||||
var mfn,
|
||||
fn,
|
||||
i = 0;
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return x + y;
|
||||
@@ -68,10 +66,7 @@ module.exports = function () {
|
||||
a(i, 11, "Called D #5");
|
||||
},
|
||||
Async: function (a, d) {
|
||||
var mfn,
|
||||
fn,
|
||||
u = {},
|
||||
i = 0;
|
||||
var mfn, fn, u = {}, i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
++i;
|
||||
@@ -105,17 +100,14 @@ module.exports = function () {
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep(
|
||||
[err, res],
|
||||
[null, 13],
|
||||
"Result B #2"
|
||||
[err, res], [null, 13], "Result B #2"
|
||||
);
|
||||
a(i, 2, "Called B #2");
|
||||
|
||||
a(
|
||||
mfn(12, 4, function (err, res) {
|
||||
a.deep(
|
||||
[err, res],
|
||||
[null, 16],
|
||||
[err, res], [null, 16],
|
||||
"Result C #1"
|
||||
);
|
||||
a(i, 3, "Called C #1");
|
||||
@@ -123,14 +115,16 @@ module.exports = function () {
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep(
|
||||
[err, res],
|
||||
[null, 10],
|
||||
[err, res], [null, 10],
|
||||
"Result #4"
|
||||
);
|
||||
a(i, 3, "Called #4");
|
||||
|
||||
a(
|
||||
mfn(5, 8, function (
|
||||
mfn(
|
||||
5,
|
||||
8,
|
||||
function (
|
||||
err,
|
||||
res
|
||||
) {
|
||||
@@ -140,8 +134,7 @@ module.exports = function () {
|
||||
"Result B #3"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
3,
|
||||
i, 3,
|
||||
"Called B #3"
|
||||
);
|
||||
|
||||
@@ -156,11 +149,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
88
|
||||
88,
|
||||
],
|
||||
"Result D #1"
|
||||
);
|
||||
@@ -181,11 +174,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
13
|
||||
13,
|
||||
],
|
||||
"Result B #4"
|
||||
);
|
||||
@@ -206,11 +199,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
16
|
||||
16,
|
||||
],
|
||||
"Result C #2"
|
||||
);
|
||||
@@ -231,11 +224,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
10
|
||||
10,
|
||||
],
|
||||
"Result #5"
|
||||
);
|
||||
@@ -256,11 +249,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
88
|
||||
88,
|
||||
],
|
||||
"Result D #2"
|
||||
);
|
||||
@@ -281,11 +274,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
16
|
||||
16,
|
||||
],
|
||||
"Result C #3"
|
||||
);
|
||||
@@ -306,11 +299,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
13
|
||||
13,
|
||||
],
|
||||
"Result B #5"
|
||||
);
|
||||
@@ -331,11 +324,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
88
|
||||
88,
|
||||
],
|
||||
"Result D #3"
|
||||
);
|
||||
@@ -360,11 +353,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
88
|
||||
88,
|
||||
],
|
||||
"Result D #4"
|
||||
);
|
||||
@@ -386,11 +379,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
13
|
||||
13,
|
||||
],
|
||||
"Result B #6"
|
||||
);
|
||||
@@ -411,11 +404,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
88
|
||||
88,
|
||||
],
|
||||
"Result D #5"
|
||||
);
|
||||
@@ -481,48 +474,37 @@ module.exports = function () {
|
||||
u,
|
||||
"Initial D #1"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial B #3"
|
||||
}
|
||||
),
|
||||
u, "Initial B #3"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial #4"
|
||||
u, "Initial #4"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial C #1"
|
||||
u, "Initial C #1"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial B #2"
|
||||
u, "Initial B #2"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
u, "Initial #3"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial B #1"
|
||||
u, "Initial B #1"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
u, "Initial #2"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial #1"
|
||||
u, "Initial #1"
|
||||
);
|
||||
},
|
||||
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);
|
||||
});
|
||||
return new Promise(function (res) { res(x + y); });
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true, max: 3 });
|
||||
@@ -572,18 +554,17 @@ module.exports = function () {
|
||||
delay(function (res) {
|
||||
// [12, 4], [3, 7], [5, 8]
|
||||
a(
|
||||
res,
|
||||
13,
|
||||
res, 13,
|
||||
"Result B #3"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
3,
|
||||
i, 3,
|
||||
"Called B #3"
|
||||
);
|
||||
|
||||
mfn(77, 11).done(
|
||||
delay(function (
|
||||
delay(
|
||||
function (
|
||||
res
|
||||
) {
|
||||
// [3, 7], [5, 8], [77, 11]
|
||||
@@ -599,8 +580,7 @@ module.exports = function () {
|
||||
);
|
||||
|
||||
mfn(
|
||||
5,
|
||||
8
|
||||
5, 8
|
||||
).done(
|
||||
delay(
|
||||
function (
|
||||
@@ -826,31 +806,30 @@ module.exports = function () {
|
||||
}
|
||||
)
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
},
|
||||
},
|
||||
Primitive: {
|
||||
Sync: function (a) {
|
||||
var mfn,
|
||||
fn,
|
||||
i = 0;
|
||||
var mfn, fn, i = 0;
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
return x + y;
|
||||
@@ -905,10 +884,7 @@ module.exports = function () {
|
||||
a(i, 11, "Called D #5");
|
||||
},
|
||||
Async: function (a, d) {
|
||||
var mfn,
|
||||
fn,
|
||||
u = {},
|
||||
i = 0;
|
||||
var mfn, fn, u = {}, i = 0;
|
||||
fn = function (x, y, cb) {
|
||||
nextTick(function () {
|
||||
++i;
|
||||
@@ -942,17 +918,14 @@ module.exports = function () {
|
||||
a(
|
||||
mfn(5, 8, function (err, res) {
|
||||
a.deep(
|
||||
[err, res],
|
||||
[null, 13],
|
||||
"Result B #2"
|
||||
[err, res], [null, 13], "Result B #2"
|
||||
);
|
||||
a(i, 2, "Called B #2");
|
||||
|
||||
a(
|
||||
mfn(12, 4, function (err, res) {
|
||||
a.deep(
|
||||
[err, res],
|
||||
[null, 16],
|
||||
[err, res], [null, 16],
|
||||
"Result C #1"
|
||||
);
|
||||
a(i, 3, "Called C #1");
|
||||
@@ -960,14 +933,16 @@ module.exports = function () {
|
||||
a(
|
||||
mfn(3, 7, function (err, res) {
|
||||
a.deep(
|
||||
[err, res],
|
||||
[null, 10],
|
||||
[err, res], [null, 10],
|
||||
"Result #4"
|
||||
);
|
||||
a(i, 3, "Called #4");
|
||||
|
||||
a(
|
||||
mfn(5, 8, function (
|
||||
mfn(
|
||||
5,
|
||||
8,
|
||||
function (
|
||||
err,
|
||||
res
|
||||
) {
|
||||
@@ -977,8 +952,7 @@ module.exports = function () {
|
||||
"Result B #3"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
3,
|
||||
i, 3,
|
||||
"Called B #3"
|
||||
);
|
||||
|
||||
@@ -993,11 +967,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
88
|
||||
88,
|
||||
],
|
||||
"Result D #1"
|
||||
);
|
||||
@@ -1018,11 +992,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
13
|
||||
13,
|
||||
],
|
||||
"Result B #4"
|
||||
);
|
||||
@@ -1043,11 +1017,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
16
|
||||
16,
|
||||
],
|
||||
"Result C #2"
|
||||
);
|
||||
@@ -1068,11 +1042,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
10
|
||||
10,
|
||||
],
|
||||
"Result #5"
|
||||
);
|
||||
@@ -1093,11 +1067,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
88
|
||||
88,
|
||||
],
|
||||
"Result D #2"
|
||||
);
|
||||
@@ -1118,11 +1092,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
16
|
||||
16,
|
||||
],
|
||||
"Result C #3"
|
||||
);
|
||||
@@ -1143,11 +1117,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
13
|
||||
13,
|
||||
],
|
||||
"Result B #5"
|
||||
);
|
||||
@@ -1168,11 +1142,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
88
|
||||
88,
|
||||
],
|
||||
"Result D #3"
|
||||
);
|
||||
@@ -1197,11 +1171,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
88
|
||||
88,
|
||||
],
|
||||
"Result D #4"
|
||||
);
|
||||
@@ -1223,11 +1197,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
13
|
||||
13,
|
||||
],
|
||||
"Result B #6"
|
||||
);
|
||||
@@ -1248,11 +1222,11 @@ module.exports = function () {
|
||||
a.deep(
|
||||
[
|
||||
err,
|
||||
res
|
||||
res,
|
||||
],
|
||||
[
|
||||
null,
|
||||
88
|
||||
88,
|
||||
],
|
||||
"Result D #5"
|
||||
);
|
||||
@@ -1318,48 +1292,37 @@ module.exports = function () {
|
||||
u,
|
||||
"Initial D #1"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial B #3"
|
||||
}
|
||||
),
|
||||
u, "Initial B #3"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial #4"
|
||||
u, "Initial #4"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial C #1"
|
||||
u, "Initial C #1"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial B #2"
|
||||
u, "Initial B #2"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial #3"
|
||||
u, "Initial #3"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial B #1"
|
||||
u, "Initial B #1"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial #2"
|
||||
u, "Initial #2"
|
||||
);
|
||||
}),
|
||||
u,
|
||||
"Initial #1"
|
||||
u, "Initial #1"
|
||||
);
|
||||
},
|
||||
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);
|
||||
});
|
||||
return new Promise(function (res) { res(x + y); });
|
||||
};
|
||||
|
||||
mfn = memoize(fn, { promise: true, primitive: true, max: 3 });
|
||||
@@ -1402,18 +1365,17 @@ module.exports = function () {
|
||||
mfn(5, 8).done(
|
||||
delay(function (res) {
|
||||
a(
|
||||
res,
|
||||
13,
|
||||
res, 13,
|
||||
"Result B #3"
|
||||
);
|
||||
a(
|
||||
i,
|
||||
3,
|
||||
i, 3,
|
||||
"Called B #3"
|
||||
);
|
||||
|
||||
mfn(77, 11).done(
|
||||
delay(function (
|
||||
delay(
|
||||
function (
|
||||
res
|
||||
) {
|
||||
a(
|
||||
@@ -1428,8 +1390,7 @@ module.exports = function () {
|
||||
);
|
||||
|
||||
mfn(
|
||||
5,
|
||||
8
|
||||
5, 8
|
||||
).done(
|
||||
delay(
|
||||
function (
|
||||
@@ -1653,25 +1614,26 @@ module.exports = function () {
|
||||
}
|
||||
)
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -8,9 +8,7 @@ var memoize = require("../..")
|
||||
, Promise = require("plain-promise")
|
||||
, Bluebird = require("bluebird");
|
||||
|
||||
Bluebird.config({
|
||||
cancellation: true
|
||||
});
|
||||
Bluebird.config({ cancellation: true });
|
||||
|
||||
module.exports = function () {
|
||||
return {
|
||||
@@ -114,7 +112,7 @@ module.exports = function () {
|
||||
d();
|
||||
}, 10);
|
||||
}, 10);
|
||||
}
|
||||
},
|
||||
},
|
||||
"Cancellation": {
|
||||
Immediate: function (a, d) {
|
||||
@@ -122,9 +120,7 @@ module.exports = function () {
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
var p = new Bluebird(function (res) {
|
||||
setTimeout(function () {
|
||||
res(x + y);
|
||||
}, 100);
|
||||
setTimeout(function () { res(x + y); }, 100);
|
||||
});
|
||||
p.cancel();
|
||||
return p;
|
||||
@@ -133,30 +129,27 @@ module.exports = function () {
|
||||
mfn = memoize(fn, { promise: true });
|
||||
|
||||
mfn(3, 7).done(a.never, function (err) {
|
||||
a.throws(function () {
|
||||
throw err;
|
||||
}, Bluebird.CancellationError, "Result #1");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
a.throws(
|
||||
function () { throw err; }, Bluebird.CancellationError,
|
||||
"Again B: Result"
|
||||
);
|
||||
});
|
||||
|
||||
setTimeout(function (err) {
|
||||
@@ -170,13 +163,9 @@ module.exports = function () {
|
||||
fn = function (x, y) {
|
||||
++i;
|
||||
var p = new Bluebird(function (res) {
|
||||
setTimeout(function () {
|
||||
res(x + y);
|
||||
}, 100);
|
||||
setTimeout(function () { res(x + y); }, 100);
|
||||
});
|
||||
nextTick(function () {
|
||||
p.cancel();
|
||||
}, 1);
|
||||
nextTick(function () { p.cancel(); }, 1);
|
||||
return p;
|
||||
};
|
||||
|
||||
@@ -198,7 +187,7 @@ module.exports = function () {
|
||||
d();
|
||||
}, 500);
|
||||
}, 500);
|
||||
}
|
||||
},
|
||||
},
|
||||
"Primitive": {
|
||||
"Success": function (a, d) {
|
||||
@@ -286,7 +275,7 @@ module.exports = function () {
|
||||
a.deep(res, x, "Args");
|
||||
d();
|
||||
}, a.never);
|
||||
}
|
||||
},
|
||||
},
|
||||
"Sync Clear": function (a, d) {
|
||||
var mfn, fn;
|
||||
@@ -321,6 +310,6 @@ module.exports = function () {
|
||||
a(res, 2, "Second");
|
||||
d();
|
||||
}, a.never);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -297,6 +297,6 @@ module.exports = function () {
|
||||
}, 10);
|
||||
}, 10);
|
||||
}, 10);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
837
test/index.js
837
test/index.js
File diff suppressed because it is too large
Load Diff
@@ -14,11 +14,7 @@ module.exports = function () {
|
||||
return x;
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
, y = { toString: function () { return "foo"; } };
|
||||
mfn = memoize(fn, { primitive: true });
|
||||
a(mfn(y), y, "#1");
|
||||
a(mfn("foo"), y, "#2");
|
||||
@@ -31,11 +27,7 @@ module.exports = function () {
|
||||
return "foo";
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
, y = { toString: function () { return "foo"; } };
|
||||
mfn = memoize(fn);
|
||||
a(mfn._has(), false);
|
||||
a(mfn(), "foo", "#1");
|
||||
@@ -50,42 +42,24 @@ module.exports = function () {
|
||||
return x + y + z;
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
, 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;
|
||||
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;
|
||||
var fn = function (x) { return x; }, mfn;
|
||||
mfn = memoize(fn);
|
||||
a(mfn._has("foo"), false);
|
||||
mfn("foo");
|
||||
@@ -93,20 +67,12 @@ module.exports = function () {
|
||||
},
|
||||
"Circular": function (a) {
|
||||
var i = 0, fn;
|
||||
fn = memoize(function (x) {
|
||||
if (++i < 2) fn(x);
|
||||
});
|
||||
a.throws(function () {
|
||||
fn("foo");
|
||||
}, "CIRCULAR_INVOCATION");
|
||||
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");
|
||||
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;
|
||||
@@ -120,7 +86,7 @@ module.exports = function () {
|
||||
return {
|
||||
"No args": function (a) {
|
||||
i = 0;
|
||||
a.deep(aFrom(r = fn()), [false, "undefined"], "First");
|
||||
a.deep(aFrom((r = fn())), [false, "undefined"], "First");
|
||||
a(fn(), r, "Second");
|
||||
a(fn(), r, "Third");
|
||||
a(i, 1, "Called once");
|
||||
@@ -133,24 +99,24 @@ module.exports = function () {
|
||||
},
|
||||
{ resolvers: [Boolean] }
|
||||
);
|
||||
a.deep(aFrom(r = fn("elo")), [true], "First");
|
||||
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.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.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");
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -19,13 +19,8 @@ module.exports = function (t, a) {
|
||||
a(this, obj);
|
||||
return x + y;
|
||||
},
|
||||
{
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
}
|
||||
)
|
||||
{ refCounter: true, dispose: function (val) { value.push(val); } }
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -15,12 +15,7 @@ module.exports = function (t, a) {
|
||||
a(arg, obj);
|
||||
return x + y;
|
||||
},
|
||||
{
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
}
|
||||
{ refCounter: true, dispose: function (val) { value.push(val); } }
|
||||
);
|
||||
|
||||
a(memoized(obj, 3, 7), 10);
|
||||
@@ -42,9 +37,7 @@ module.exports = function (t, a) {
|
||||
x = {};
|
||||
y = {};
|
||||
z = {};
|
||||
memoized = t(function (arg) {
|
||||
return ++count;
|
||||
});
|
||||
memoized = t(function (arg) { return ++count; });
|
||||
a(memoized(x), 1);
|
||||
a(memoized(y), 2);
|
||||
a(memoized(x), 1);
|
||||
|
||||
@@ -17,13 +17,8 @@ module.exports = function (t, a) {
|
||||
a(this, obj);
|
||||
return x + y;
|
||||
},
|
||||
{
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
}
|
||||
)
|
||||
{ refCounter: true, dispose: function (val) { value.push(val); } }
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -14,13 +14,8 @@ module.exports = function (t, a) {
|
||||
a(this, obj);
|
||||
return x + y;
|
||||
},
|
||||
{
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
}
|
||||
)
|
||||
{ refCounter: true, dispose: function (val) { value.push(val); } }
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -36,15 +36,13 @@ module.exports = {
|
||||
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;
|
||||
};
|
||||
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");
|
||||
@@ -58,5 +56,5 @@ module.exports = {
|
||||
a(i, 3, "Reinit count");
|
||||
a(mfn(3, x, 1), 6, "Reinit Cached");
|
||||
a(i, 3, "Reinit count");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ module.exports = {
|
||||
return {
|
||||
"No args": function () {
|
||||
i = 0;
|
||||
a.deep(r = fn(), [undefined, undefined, undefined], "First");
|
||||
a.deep((r = fn()), [undefined, undefined, undefined], "First");
|
||||
a(fn(), r, "Second");
|
||||
a(fn(), r, "Third");
|
||||
a(i, 1, "Called once");
|
||||
@@ -25,41 +25,39 @@ module.exports = {
|
||||
"Some Args": function () {
|
||||
var x = {};
|
||||
i = 0;
|
||||
a.deep(r = fn(x, 8), [x, 8, undefined], "First");
|
||||
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.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.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.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;
|
||||
};
|
||||
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");
|
||||
@@ -94,5 +92,5 @@ module.exports = {
|
||||
fn(1, x, 3);
|
||||
fn(1, x, 4);
|
||||
a(i, 4, "After clear");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -12,11 +12,7 @@ module.exports = {
|
||||
return x + y + z;
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
, y = { toString: function () { return "foo"; } };
|
||||
mfn = memoize(fn, { primitive: true });
|
||||
a(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
|
||||
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
|
||||
@@ -29,42 +25,22 @@ module.exports = {
|
||||
return x + y + z;
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
, 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");
|
||||
},
|
||||
"Clear": function (a) {
|
||||
var i = 0, fn;
|
||||
fn = memoize(function (x) {
|
||||
if (++i < 2) fn(x);
|
||||
});
|
||||
a.throws(function () {
|
||||
fn("foo");
|
||||
}, "CIRCULAR_INVOCATION");
|
||||
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");
|
||||
}
|
||||
fn = memoize(function (x, y) { if (++i < 2) fn(x, y); });
|
||||
a.throws(function () { fn("foo", "bar"); }, "CIRCULAR_INVOCATION");
|
||||
},
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ module.exports = function () {
|
||||
return {
|
||||
"No args": function () {
|
||||
i = 0;
|
||||
a.deep(aFrom(r = fn()), [], "First");
|
||||
a.deep(aFrom((r = fn())), [], "First");
|
||||
a(fn(), r, "Second");
|
||||
a(fn(), r, "Third");
|
||||
a(i, 1, "Called once");
|
||||
@@ -27,7 +27,7 @@ module.exports = function () {
|
||||
"Some Args": function () {
|
||||
var x = {};
|
||||
i = 0;
|
||||
a.deep(aFrom(r = fn(x, 8)), [x, 8], "First");
|
||||
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");
|
||||
@@ -35,19 +35,17 @@ module.exports = function () {
|
||||
"Many args": function () {
|
||||
var x = {};
|
||||
i = 0;
|
||||
a.deep(aFrom(r = fn(x, 8, 23, 98)), [x, 8, 23, 98], "First");
|
||||
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;
|
||||
};
|
||||
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");
|
||||
@@ -61,6 +59,6 @@ module.exports = function () {
|
||||
a(i, 3, "Reinit count");
|
||||
a(mfn(3, x, 1), 6, "Reinit Cached");
|
||||
a(i, 3, "Reinit count");
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -11,11 +11,7 @@ module.exports = function (a) {
|
||||
++i;
|
||||
return join.call(arguments, "|");
|
||||
}
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
}
|
||||
, y = { toString: function () { return "foo"; } }
|
||||
, mfn;
|
||||
mfn = memoize(fn, { primitive: true, length: false });
|
||||
a(mfn(y, "bar", "zeta"), "foo|bar|zeta", "#1");
|
||||
|
||||
@@ -11,11 +11,7 @@ module.exports = function (t) {
|
||||
return x;
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
, y = { toString: function () { return "foo"; } };
|
||||
mfn = t(fn, { primitive: true });
|
||||
a(typeof mfn, "function", "Returns");
|
||||
a(mfn.__memoized__, true, "Marked");
|
||||
@@ -31,26 +27,14 @@ module.exports = function (t) {
|
||||
return x + y + z;
|
||||
}
|
||||
, mfn
|
||||
, y = {
|
||||
toString: function () {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
, 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");
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -12,12 +12,7 @@ module.exports = function (t, a) {
|
||||
a(arg, obj);
|
||||
return x + y;
|
||||
},
|
||||
{
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
}
|
||||
{ refCounter: true, dispose: function (val) { value.push(val); } }
|
||||
);
|
||||
|
||||
a(memoized(obj, 3, 7), 10);
|
||||
@@ -39,9 +34,7 @@ module.exports = function (t, a) {
|
||||
x = {};
|
||||
y = {};
|
||||
z = {};
|
||||
memoized = t(function (arg) {
|
||||
return ++count;
|
||||
});
|
||||
memoized = t(function (arg) { return ++count; });
|
||||
a(memoized(x), 1);
|
||||
a(memoized(y), 2);
|
||||
a(memoized(x), 1);
|
||||
|
||||
18
test/weak.js
18
test/weak.js
@@ -9,12 +9,7 @@ module.exports = function (t, a, d) {
|
||||
a(arg, obj);
|
||||
return x + y;
|
||||
},
|
||||
{
|
||||
refCounter: true,
|
||||
dispose: function (val) {
|
||||
value.push(val);
|
||||
}
|
||||
}
|
||||
{ refCounter: true, dispose: function (val) { value.push(val); } }
|
||||
);
|
||||
|
||||
a(memoized(obj, 3, 7), 10);
|
||||
@@ -36,9 +31,7 @@ module.exports = function (t, a, d) {
|
||||
x = {};
|
||||
y = {};
|
||||
z = {};
|
||||
memoized = t(function (arg) {
|
||||
return ++count;
|
||||
});
|
||||
memoized = t(function (arg) { return ++count; });
|
||||
a(memoized(x), 1);
|
||||
a(memoized(y), 2);
|
||||
a(memoized(x), 1);
|
||||
@@ -46,12 +39,7 @@ module.exports = function (t, a, d) {
|
||||
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