From 3aa13c30701a68356084aa62d1ab3b2a3207ee82 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 28 Aug 2017 15:13:36 +0200 Subject: [PATCH] refactor: update after change of linter --- benchmark/fibonacci.js | 36 +- ext/async.js | 39 +- ext/max-age.js | 20 +- ext/promise.js | 57 +- lib/configure-map.js | 46 +- lib/methods.js | 8 +- lib/resolve-resolve.js | 14 +- lib/weak.js | 159 +- normalizers/get-primitive-fixed.js | 12 +- normalizers/get.js | 16 +- package.json | 106 +- plain.js | 10 +- profile.js | 131 +- test/ext/async.js | 356 ++-- test/ext/dispose.js | 181 +- test/ext/max-age.js | 622 +++++-- test/ext/max.js | 1783 +++++++++++++++---- test/ext/promise.js | 21 +- test/ext/ref-counter.js | 208 ++- test/index.js | 2065 +++++++++++++++++------ test/lib/configure-map.js | 83 +- test/lib/methods.js | 28 +- test/lib/resolve-normalize.js | 2 + test/lib/weak.js | 25 +- test/methods-plain.js | 28 +- test/methods.js | 28 +- test/normalizers/get-1.js | 10 +- test/normalizers/get-fixed.js | 11 +- test/normalizers/get-primitive-fixed.js | 49 +- test/normalizers/get.js | 11 +- test/normalizers/primitive.js | 22 +- test/plain.js | 49 +- test/profile.js | 2 + test/weak-plain.js | 25 +- test/weak.js | 34 +- 35 files changed, 4632 insertions(+), 1665 deletions(-) diff --git a/benchmark/fibonacci.js b/benchmark/fibonacci.js index 187205f..3a704e7 100644 --- a/benchmark/fibonacci.js +++ b/benchmark/fibonacci.js @@ -1,3 +1,6 @@ +/* global console */ +/* eslint no-console: 0, id-length: 0 */ + "use strict"; // Simple benchmark for very simple memoization case (fibonacci series) @@ -12,12 +15,20 @@ var forEach = require("es5-ext/object/for-each") , underscore = require("underscore").memoize , lodash = require("lodash").memoize , lruCache = require("lru-cache") - , lruSecondary = require("secondary-cache/lib/lru-cache") + , lruSecondary = require("secondary-cache/lib/lru-cache"); - , now = Date.now - - , time, getFib, lru, memo, total, index = 3000, count = 10, i, lruMax = 1000 - , data = {}, lruObj; +var now = Date.now + , time + , getFib + , lru + , memo + , total + , index = 3000 + , count = 10 + , i + , lruMax = 1000 + , data = {} + , lruObj; getFib = function (memoize, opts) { var fib = memoize(function (x) { @@ -117,8 +128,13 @@ while (i--) { } data["secondary-cache LRU (max: 1000)"] = total; -forEach(data, function (value, name, obj, index) { - console.log(index + 1 + ":", pad.call(value, " ", 5) + "ms ", name); -}, null, function (a, b) { - return this[a] - this[b]; -}); +forEach( + data, + function (value, name, obj, currentIndex) { + console.log(currentIndex + 1 + ":", pad.call(value, " ", 5) + "ms ", name); + }, + null, + function (a, b) { + return this[a] - this[b]; + } +); diff --git a/ext/async.js b/ext/async.js index bbf704b..772e691 100644 --- a/ext/async.js +++ b/ext/async.js @@ -1,3 +1,5 @@ +/* eslint consistent-this: 0, no-shadow:0, no-eq-null: 0, eqeqeq: 0, no-unused-vars: 0 */ + // Support for asynchronous functions "use strict"; @@ -6,16 +8,18 @@ var aFrom = require("es5-ext/array/from") , objectMap = require("es5-ext/object/map") , mixin = require("es5-ext/object/mixin") , defineLength = require("es5-ext/function/_define-length") - , nextTick = require("next-tick") + , nextTick = require("next-tick"); - , slice = Array.prototype.slice - , apply = Function.prototype.apply, create = Object.create - , hasOwnProperty = Object.prototype.hasOwnProperty; +var slice = Array.prototype.slice, apply = Function.prototype.apply, create = Object.create; require("../lib/registered-extensions").async = function (tbi, conf) { - var waiting = create(null), cache = create(null) - , base = conf.memoized, original = conf.original - , currentCallback, currentContext, currentArgs; + var waiting = create(null) + , cache = create(null) + , base = conf.memoized + , original = conf.original + , currentCallback + , currentContext + , currentArgs; // Initial conf.memoized = defineLength(function (arg) { @@ -27,8 +31,8 @@ require("../lib/registered-extensions").async = function (tbi, conf) { return base.apply(currentContext = this, currentArgs = args); }, base); try { - mixin(conf.memoized, base); -} catch (ignore) {} + mixin(conf.memoized, base); + } catch (ignore) {} // From cache (sync) conf.on("get", function (id) { @@ -74,7 +78,7 @@ require("../lib/registered-extensions").async = function (tbi, conf) { if (id == null) { // Shouldn't happen, means async callback was called sync way nextTick(apply.bind(self, this, arguments)); - return; + return undefined; } delete self.id; cb = waiting[id]; @@ -82,7 +86,7 @@ require("../lib/registered-extensions").async = function (tbi, conf) { if (!cb) { // Already processed, // outcome of race condition: asyncFn(1, cb), asyncFn.clear(), asyncFn(1, cb) - return; + return undefined; } args = aFrom(arguments); if (conf.has(id)) { @@ -97,8 +101,8 @@ require("../lib/registered-extensions").async = function (tbi, conf) { result = apply.call(cb, this, args); } else { cb.forEach(function (cb) { - result = apply.call(cb, this, args); -}, this); + result = apply.call(cb, this, args); + }, this); } return result; }; @@ -146,8 +150,11 @@ require("../lib/registered-extensions").async = function (tbi, conf) { conf.on("clear", function () { var oldCache = cache; cache = create(null); - conf.emit("clearasync", objectMap(oldCache, function (data) { - return slice.call(data.args, 1); - })); + conf.emit( + "clearasync", + objectMap(oldCache, function (data) { + return slice.call(data.args, 1); + }) + ); }); }; diff --git a/ext/max-age.js b/ext/max-age.js index bc10e1b..2f9da03 100644 --- a/ext/max-age.js +++ b/ext/max-age.js @@ -1,3 +1,5 @@ +/* eslint consistent-this: 0 */ + // Timeout cached values "use strict"; @@ -7,10 +9,9 @@ var aFrom = require("es5-ext/array/from") , nextTick = require("next-tick") , isPromise = require("is-promise") , timeout = require("timers-ext/valid-timeout") - , extensions = require("../lib/registered-extensions") + , extensions = require("../lib/registered-extensions"); - , noop = Function.prototype - , max = Math.max, min = Math.min, create = Object.create; +var noop = Function.prototype, max = Math.max, min = Math.min, create = Object.create; extensions.maxAge = function (maxAge, conf, options) { var timeouts, postfix, preFetchAge, preFetchTimeouts; @@ -20,11 +21,12 @@ extensions.maxAge = function (maxAge, conf, options) { timeouts = create(null); postfix = (options.async && extensions.async) || (options.promise && extensions.promise) - ? "async" : ""; + ? "async" + : ""; conf.on("set" + postfix, function (id) { timeouts[id] = setTimeout(function () { - conf.delete(id); -}, maxAge); + conf.delete(id); + }, maxAge); if (!preFetchTimeouts) return; if (preFetchTimeouts[id]) { if (preFetchTimeouts[id] !== "nextTick") clearTimeout(preFetchTimeouts[id]); @@ -42,7 +44,7 @@ extensions.maxAge = function (maxAge, conf, options) { }); if (options.preFetch) { - if ((options.preFetch === true) || isNaN(options.preFetch)) { + if (options.preFetch === true || isNaN(options.preFetch)) { preFetchAge = 0.333; } else { preFetchAge = max(min(Number(options.preFetch), 1), 0); @@ -78,8 +80,8 @@ extensions.maxAge = function (maxAge, conf, options) { conf.on("clear" + postfix, function () { forEach(timeouts, function (id) { - clearTimeout(id); -}); + clearTimeout(id); + }); timeouts = {}; if (preFetchTimeouts) { forEach(preFetchTimeouts, function (id) { diff --git a/ext/promise.js b/ext/promise.js index 2deb06d..aa8066d 100644 --- a/ext/promise.js +++ b/ext/promise.js @@ -1,12 +1,14 @@ +/* eslint consistent-this: 0 */ + // Support for functions returning promise "use strict"; var objectMap = require("es5-ext/object/map") , isPromise = require("is-promise") - , nextTick = require("next-tick") + , nextTick = require("next-tick"); - , create = Object.create, hasOwnProperty = Object.prototype.hasOwnProperty; +var create = Object.create; require("../lib/registered-extensions").promise = function (mode, conf) { var waiting = create(null), cache = create(null), promises = create(null); @@ -26,10 +28,12 @@ require("../lib/registered-extensions").promise = function (mode, conf) { var onSuccess = function (result) { var count = waiting[id]; if (isFailed) { - throw new Error("Memoizee error: Promise resolved with both failure and success," + - " this can be result of unordered done & finally resolution.\n" + - "Instead of `promise: true` consider configuring memoization via `promise: 'then'` or " + - "`promise: 'done'"); + throw new Error( + "Memoizee error: Promise resolved with both failure and success," + + " this can be result of unordered done & finally resolution.\n" + + "Instead of `promise: true` consider configuring memoization via " + + "`promise: 'then'` or `promise: 'done'" + ); } if (!count) return; // Deleted from cache before resolved delete waiting[id]; @@ -44,9 +48,9 @@ require("../lib/registered-extensions").promise = function (mode, conf) { conf.delete(id); }; - if ((mode !== "then") && (typeof promise.done === "function")) { + if (mode !== "then" && typeof promise.done === "function") { // Optimal promise resolution - if ((mode !== "done") && (typeof promise.finally === "function")) { + if (mode !== "done" && typeof promise.finally === "function") { // Use 'finally' to not register error handling (still proper behavior is subject to // used implementation, if library throws unconditionally even on handled errors // switch to 'then' mode) @@ -59,12 +63,16 @@ require("../lib/registered-extensions").promise = function (mode, conf) { } } else { // With no `done` it's best we can do. - // Side effect is that it mutes any eventual "Unhandled error" events on returned promise - promise.then(function (result) { - nextTick(onSuccess.bind(this, result)); - }, function () { - nextTick(onFailure); - }); + // Side effect is that it mutes any eventual "Unhandled error" events + // on returned promise + promise.then( + function (result) { + nextTick(onSuccess.bind(this, result)); + }, + function () { + nextTick(onFailure); + } + ); } }); @@ -77,15 +85,15 @@ require("../lib/registered-extensions").promise = function (mode, conf) { } promise = promises[id]; var emit = function () { - conf.emit("getasync", id, args, context); -}; + conf.emit("getasync", id, args, context); + }; if (isPromise(promise)) { if (typeof promise.done === "function") promise.done(emit); else { - promise.then(function () { - nextTick(emit); -}); -} + promise.then(function () { + nextTick(emit); + }); + } } else { emit(); } @@ -110,8 +118,11 @@ require("../lib/registered-extensions").promise = function (mode, conf) { cache = create(null); waiting = create(null); promises = create(null); - conf.emit("clearasync", objectMap(oldCache, function (data) { - return [data]; -})); + conf.emit( + "clearasync", + objectMap(oldCache, function (data) { + return [data]; + }) + ); }); }; diff --git a/lib/configure-map.js b/lib/configure-map.js index bfbccf3..086a2a9 100644 --- a/lib/configure-map.js +++ b/lib/configure-map.js @@ -1,3 +1,5 @@ +/* eslint no-eq-null: 0, eqeqeq: 0, no-unused-vars: 0 */ + "use strict"; var customError = require("es5-ext/error/custom") @@ -5,16 +7,32 @@ var customError = require("es5-ext/error/custom") , d = require("d") , ee = require("event-emitter").methods , resolveResolve = require("./resolve-resolve") - , resolveNormalize = require("./resolve-normalize") + , resolveNormalize = require("./resolve-normalize"); - , apply = Function.prototype.apply, call = Function.prototype.call - , create = Object.create, hasOwnProperty = Object.prototype.hasOwnProperty +var apply = Function.prototype.apply + , call = Function.prototype.call + , create = Object.create , defineProperties = Object.defineProperties - , on = ee.on, emit = ee.emit; + , on = ee.on + , emit = ee.emit; module.exports = function (original, length, options) { - var cache = create(null), conf, memLength, get, set, del, clear, extDel, - extGet, extHas, normalizer, getListeners, setListeners, deleteListeners, memoized, resolve; + var cache = create(null) + , conf + , memLength + , get + , set + , del + , clear + , extDel + , extGet + , extHas + , normalizer + , getListeners + , setListeners + , deleteListeners + , memoized + , resolve; if (length !== false) memLength = length; else if (isNaN(original.length)) memLength = 1; else memLength = original.length; @@ -59,8 +77,8 @@ module.exports = function (original, length, options) { if (getListeners) conf.emit("get", "data", arguments, this); return cache.data; } - if (!arguments.length) result = call.call(original, this); - else result = apply.call(original, this, arguments); + if (arguments.length) result = apply.call(original, this, arguments); + else result = call.call(original, this); if (hasOwnProperty.call(cache, "data")) { throw customError("Circular invocation", "CIRCULAR_INVOCATION"); } @@ -97,8 +115,8 @@ module.exports = function (original, length, options) { return String(args[0]); }, has: function (id) { - return hasOwnProperty.call(cache, id); -}, + return hasOwnProperty.call(cache, id); + }, delete: function (id) { var result; if (!hasOwnProperty.call(cache, id)) return; @@ -121,8 +139,8 @@ module.exports = function (original, length, options) { }, emit: emit, updateEnv: function () { - original = conf.original; -} + original = conf.original; + } }; if (get) { extDel = defineLength(function (arg) { @@ -134,8 +152,8 @@ module.exports = function (original, length, options) { }, memLength); } else if (length === 0) { extDel = function () { - return conf.delete("data"); -}; + return conf.delete("data"); + }; } else { extDel = function (arg) { if (resolve) arg = resolve(arguments)[0]; diff --git a/lib/methods.js b/lib/methods.js index 3d01443..779b699 100644 --- a/lib/methods.js +++ b/lib/methods.js @@ -9,13 +9,17 @@ var forEach = require("es5-ext/object/for-each") module.exports = function (memoize) { return function (props) { - forEach(props, function (desc, name) { + forEach(props, function (desc) { var fn = callable(desc.value), length; desc.value = function (options) { if (options.getNormalizer) { options = normalizeOpts(options); if (length === undefined) { - length = resolveLength(options.length, fn.length, options.async && extensions.async); + length = resolveLength( + options.length, + fn.length, + options.async && extensions.async + ); } options.normalizer = options.getNormalizer(length); delete options.getNormalizer; diff --git a/lib/resolve-resolve.js b/lib/resolve-resolve.js index 76586c2..578eb37 100644 --- a/lib/resolve-resolve.js +++ b/lib/resolve-resolve.js @@ -1,21 +1,21 @@ "use strict"; var toArray = require("es5-ext/array/to-array") - , callable = require("es5-ext/object/valid-callable") + , isValue = require("es5-ext/object/is-value") + , callable = require("es5-ext/object/valid-callable"); - , slice = Array.prototype.slice - , resolveArgs; +var slice = Array.prototype.slice, resolveArgs; resolveArgs = function (args) { - return this.map(function (r, i) { - return r ? r(args[i]) : args[i]; + return this.map(function (resolve, i) { + return resolve ? resolve(args[i]) : args[i]; }).concat(slice.call(args, this.length)); }; module.exports = function (resolvers) { resolvers = toArray(resolvers); - resolvers.forEach(function (r) { - if (r != null) callable(r); + resolvers.forEach(function (resolve) { + if (isValue(resolve)) callable(resolve); }); return resolveArgs.bind(resolvers); }; diff --git a/lib/weak.js b/lib/weak.js index 64dfe4a..35b7655 100644 --- a/lib/weak.js +++ b/lib/weak.js @@ -11,13 +11,12 @@ var customError = require("es5-ext/error/custom") , resolveLength = require("./resolve-length") , extensions = require("./registered-extensions") , resolveResolve = require("./resolve-resolve") - , resolveNormalize = require("./resolve-normalize") + , resolveNormalize = require("./resolve-normalize"); - , slice = Array.prototype.slice, defineProperties = Object.defineProperties - , hasOwnProperty = Object.prototype.hasOwnProperty; +var slice = Array.prototype.slice, defineProperties = Object.defineProperties; module.exports = function (memoize) { - return function (fn/*, options*/) { + return function (fn /*, options*/) { var map, length, options = normalizeOpts(arguments[1]), memoized, resolve, normalizer; callable(fn); @@ -32,80 +31,104 @@ module.exports = function (memoize) { if (options.resolvers) resolve = resolveResolve(options.resolvers); if (options.normalizer) normalizer = resolveNormalize(options.normalizer); - if ((length === 1) && !normalizer && !options.async && !options.dispose && !options.maxAge && - !options.max && !options.refCounter) { - return defineProperties(function (obj) { - var result, args = arguments; - if (resolve) args = resolve(args); - obj = args[0]; - if (map.has(obj)) return map.get(obj); - result = fn.apply(this, args); - if (map.has(obj)) throw customError("Circular invocation", "CIRCULAR_INVOCATION"); - map.set(obj, result); - return result; - }, { - __memoized__: d(true), - delete: d(function (obj) { - if (resolve) obj = resolve(arguments)[0]; - return map.delete(obj); - }) - }); - } - memoized = defineProperties(defineLength(function (obj) { - var memoizer, args = arguments; - if (resolve) { - args = resolve(args); - obj = args[0]; - } - memoizer = map.get(obj); - if (!memoizer) { - if (normalizer) { - options = copy(options); - options.normalizer = copy(normalizer); - options.normalizer.get = partial.call(options.normalizer.get, obj); - options.normalizer.set = partial.call(options.normalizer.set, obj); - if (options.normalizer.delete) { - options.normalizer.delete = partial.call(options.normalizer.delete, obj); + if ( + length === 1 && + !normalizer && + !options.async && + !options.dispose && + !options.maxAge && + !options.max && + !options.refCounter + ) { + return defineProperties( + function (obj) { + var result, args = arguments; + if (resolve) args = resolve(args); + obj = args[0]; + if (map.has(obj)) return map.get(obj); + result = fn.apply(this, args); + if (map.has(obj)) { + throw customError("Circular invocation", "CIRCULAR_INVOCATION"); } + map.set(obj, result); + return result; + }, + { + __memoized__: d(true), + delete: d(function (obj) { + if (resolve) obj = resolve(arguments)[0]; + return map.delete(obj); + }) } - map.set(obj, memoizer = memoize(partial.call(fn, obj), options)); - } - return memoizer.apply(this, slice.call(args, 1)); - }, length), { - __memoized__: d(true), - delete: d(defineLength(function (obj) { + ); + } + memoized = defineProperties( + defineLength(function (obj) { var memoizer, args = arguments; if (resolve) { args = resolve(args); obj = args[0]; } memoizer = map.get(obj); - if (!memoizer) return; - memoizer.delete.apply(this, slice.call(args, 1)); - }, length)) - }); + if (!memoizer) { + if (normalizer) { + options = copy(options); + options.normalizer = copy(normalizer); + options.normalizer.get = partial.call(options.normalizer.get, obj); + options.normalizer.set = partial.call(options.normalizer.set, obj); + if (options.normalizer.delete) { + options.normalizer.delete = partial.call( + options.normalizer.delete, + obj + ); + } + } + map.set(obj, memoizer = memoize(partial.call(fn, obj), options)); + } + return memoizer.apply(this, slice.call(args, 1)); + }, length), + { + __memoized__: d(true), + delete: d( + defineLength(function (obj) { + var memoizer, args = arguments; + if (resolve) { + args = resolve(args); + obj = args[0]; + } + memoizer = map.get(obj); + if (!memoizer) return; + memoizer.delete.apply(this, slice.call(args, 1)); + }, length) + ) + } + ); if (!options.refCounter) return memoized; defineProperties(memoized, { - deleteRef: d(defineLength(function (obj) { - var memoizer, args = arguments; - if (resolve) { - args = resolve(args); - obj = args[0]; - } - memoizer = map.get(obj); - if (!memoizer) return null; - return memoizer.deleteRef.apply(this, slice.call(args, 1)); - }, length)), - getRefCount: d(defineLength(function (obj) { - var memoizer, args = arguments; - if (resolve) { - args = resolve(args); - obj = args[0]; - } - memoizer = map.get(obj); - if (!memoizer) return 0; - return memoizer.getRefCount.apply(this, slice.call(args, 1)); - }, length)) + deleteRef: d( + defineLength(function (obj) { + var memoizer, args = arguments; + if (resolve) { + args = resolve(args); + obj = args[0]; + } + memoizer = map.get(obj); + if (!memoizer) return null; + return memoizer.deleteRef.apply(this, slice.call(args, 1)); + }, length) + ), + getRefCount: d( + defineLength(function (obj) { + var memoizer, args = arguments; + if (resolve) { + args = resolve(args); + obj = args[0]; + } + memoizer = map.get(obj); + if (!memoizer) return 0; + return memoizer.getRefCount.apply(this, slice.call(args, 1)); + }, length) + ) }); return memoized; }; diff --git a/normalizers/get-primitive-fixed.js b/normalizers/get-primitive-fixed.js index 464eed2..baedcc8 100644 --- a/normalizers/get-primitive-fixed.js +++ b/normalizers/get-primitive-fixed.js @@ -3,14 +3,14 @@ module.exports = function (length) { if (!length) { return function () { - return ""; -}; + return ""; + }; } return function (args) { - var id = String(args[0]), i = 0, l = length; - while (--l) { - id += "\u0001" + args[++i]; -} + var id = String(args[0]), i = 0, currentLength = length; + while (--currentLength) { + id += "\u0001" + args[++i]; + } return id; }; }; diff --git a/normalizers/get.js b/normalizers/get.js index ac39337..c5bb317 100644 --- a/normalizers/get.js +++ b/normalizers/get.js @@ -1,7 +1,10 @@ +/* eslint max-statements: 0 */ + "use strict"; -var indexOf = require("es5-ext/array/#/e-index-of") - , create = Object.create; +var indexOf = require("es5-ext/array/#/e-index-of"); + +var create = Object.create; module.exports = function () { var lastId = 0, map = [], cache = create(null); @@ -10,7 +13,7 @@ module.exports = function () { var index = 0, set = map, i, length = args.length; if (length === 0) return set[length] || null; if ((set = set[length])) { - while (index < (length - 1)) { + while (index < length - 1) { i = indexOf.call(set[0], args[index]); if (i === -1) return null; set = set[1][i]; @@ -31,7 +34,7 @@ module.exports = function () { set[length] = [[], []]; } set = set[length]; - while (index < (length - 1)) { + while (index < length - 1) { i = indexOf.call(set[0], args[index]); if (i === -1) { i = set[0].push(args[index]) - 1; @@ -50,12 +53,11 @@ module.exports = function () { return lastId; }, delete: function (id) { - var index = 0, set = map, i, args = cache[id], length = args.length - , path = []; + var index = 0, set = map, i, args = cache[id], length = args.length, path = []; if (length === 0) { delete set[length]; } else if ((set = set[length])) { - while (index < (length - 1)) { + while (index < length - 1) { i = indexOf.call(set[0], args[index]); if (i === -1) { return; diff --git a/package.json b/package.json index e2684b0..33581c9 100644 --- a/package.json +++ b/package.json @@ -1,53 +1,57 @@ { - "name": "memoizee", - "version": "0.4.6", - "description": "Memoize/cache function results", - "author": "Mariusz Nowak (http://www.medikoo.com/)", - "keywords": [ - "memoize", - "memoizer", - "cache", - "memoization", - "memo", - "memcached", - "hashing.", - "storage", - "caching", - "memory", - "gc", - "weak", - "garbage", - "collector", - "async" - ], - "repository": { - "type": "git", - "url": "git://github.com/medikoo/memoizee.git" - }, - "dependencies": { - "d": "1", - "es5-ext": "^0.10.13", - "es6-weak-map": "^2.0.1", - "event-emitter": "^0.3.4", - "is-promise": "^2.1", - "lru-queue": "0.1", - "next-tick": "1", - "timers-ext": "0.1" - }, - "devDependencies": { - "eslint": "^4.2.0", - "eslint-config-medikoo-es5": "^1.4.1", - "plain-promise": "^0.1.1", - "tad": "^0.2.7" - }, - "eslintConfig": { - "extends": "medikoo-es5", - "root": true - }, - "scripts": { - "lint": "eslint --ignore-path=.gitignore .", - "lint-medikoo": "xlint --linter=node_modules/xlint-jslint-medikoo/index.js", - "test": "tad" - }, - "license": "MIT" + "name": "memoizee", + "version": "0.4.6", + "description": "Memoize/cache function results", + "author": "Mariusz Nowak (http://www.medikoo.com/)", + "keywords": [ + "memoize", + "memoizer", + "cache", + "memoization", + "memo", + "memcached", + "hashing.", + "storage", + "caching", + "memory", + "gc", + "weak", + "garbage", + "collector", + "async" + ], + "repository": { + "type": "git", + "url": "git://github.com/medikoo/memoizee.git" + }, + "dependencies": { + "d": "1", + "es5-ext": "^0.10.13", + "es6-weak-map": "^2.0.1", + "event-emitter": "^0.3.4", + "is-promise": "^2.1", + "lru-queue": "0.1", + "next-tick": "1", + "timers-ext": "0.1" + }, + "devDependencies": { + "eslint": "^4.2.0", + "eslint-config-medikoo-es5": "^1.4.1", + "plain-promise": "^0.1.1", + "tad": "^0.2.7" + }, + "eslintConfig": { + "extends": "medikoo-es5", + "root": true, + "globals": { + "setTimeout": true, + "clearTimeout": true + } + }, + "scripts": { + "lint": "eslint --ignore-path=.gitignore .", + "lint-medikoo": "xlint --linter=node_modules/xlint-jslint-medikoo/index.js", + "test": "tad" + }, + "license": "MIT" } diff --git a/plain.js b/plain.js index 2cb82f6..e270902 100644 --- a/plain.js +++ b/plain.js @@ -4,11 +4,9 @@ var callable = require("es5-ext/object/valid-callable") , forEach = require("es5-ext/object/for-each") , extensions = require("./lib/registered-extensions") , configure = require("./lib/configure-map") - , resolveLength = require("./lib/resolve-length") + , resolveLength = require("./lib/resolve-length"); - , hasOwnProperty = Object.prototype.hasOwnProperty; - -module.exports = function self (fn/*, options */) { +module.exports = function self (fn /*, options */) { var options, length, conf; callable(fn); @@ -28,8 +26,8 @@ module.exports = function self (fn/*, options */) { conf = configure(fn, length, options); // Bind eventual extensions - forEach(extensions, function (fn, name) { - if (options[name]) fn(options[name], conf, options); + forEach(extensions, function (extFn, name) { + if (options[name]) extFn(options[name], conf, options); }); if (self.__profiler__) self.__profiler__(conf); diff --git a/profile.js b/profile.js index 9d5318a..3ac66da 100644 --- a/profile.js +++ b/profile.js @@ -2,40 +2,46 @@ "use strict"; -var partial = require("es5-ext/function/#/partial") - , forEach = require("es5-ext/object/for-each") - , pad = require("es5-ext/string/#/pad") - , compact = require("es5-ext/array/#/compact") - , d = require("d") - , memoize = require("./plain") +var partial = require("es5-ext/function/#/partial") + , forEach = require("es5-ext/object/for-each") + , pad = require("es5-ext/string/#/pad") + , compact = require("es5-ext/array/#/compact") + , d = require("d") + , memoize = require("./plain"); - , max = Math.max - , stats = exports.statistics = {}; +var max = Math.max, stats = exports.statistics = {}; -Object.defineProperty(memoize, "__profiler__", d(function (conf) { - var id, source, data, stack; - stack = (new Error()).stack; - if (!stack || !stack.split("\n").slice(3).some(function (line) { - if ((line.indexOf("/memoizee/") === -1) && - (line.indexOf(" (native)") === -1)) { - source = line.replace(/\n/g, "\\n").trim(); - return true; - } - })) { - source = "unknown"; - } - id = compact.call([conf.profileName, source]).join(", "); +Object.defineProperty( + memoize, + "__profiler__", + d(function (conf) { + var id, source, data, stack; + stack = new Error().stack; + if ( + !stack || + !stack.split("\n").slice(3).some(function (line) { + if (line.indexOf("/memoizee/") === -1 && line.indexOf(" (native)") === -1) { + source = line.replace(/\n/g, "\\n").trim(); + return true; + } + return false; + }) + ) { + source = "unknown"; + } + id = compact.call([conf.profileName, source]).join(", "); - if (!stats[id]) stats[id] = { initial: 0, cached: 0 }; - data = stats[id]; + if (!stats[id]) stats[id] = { initial: 0, cached: 0 }; + data = stats[id]; - conf.on("set", function () { - ++data.initial; -}); - conf.on("get", function () { - ++data.cached; -}); -})); + conf.on("set", function () { + ++data.initial; + }); + conf.on("get", function () { + ++data.cached; + }); + }) +); exports.log = function () { var initial, cached, ordered, ipad, cpad, ppad, toPrc, log; @@ -43,41 +49,62 @@ exports.log = function () { initial = cached = 0; ordered = []; - toPrc = function (initial, cached) { - if (!initial && !cached) { + toPrc = function (initialCount, cachedCount) { + if (!initialCount && !cachedCount) { return "0.00"; } - return ((cached / (initial + cached)) * 100).toFixed(2); + return (cachedCount / (initialCount + cachedCount) * 100).toFixed(2); }; log = "------------------------------------------------------------\n"; log += "Memoize statistics:\n\n"; - forEach(stats, function (data, name) { - initial += data.initial; - cached += data.cached; - ordered.push([name, data]); - }, null, function (a, b) { - return (this[b].initial + this[b].cached) - - (this[a].initial + this[a].cached); - }); + forEach( + stats, + function (data, name) { + initial += data.initial; + cached += data.cached; + ordered.push([name, data]); + }, + null, + function (nameA, nameB) { + return ( + this[nameB].initial + + this[nameB].cached - + (this[nameA].initial + this[nameA].cached) + ); + } + ); - ipad = partial.call(pad, " ", - max(String(initial).length, "Init".length)); + ipad = partial.call(pad, " ", max(String(initial).length, "Init".length)); cpad = partial.call(pad, " ", max(String(cached).length, "Cache".length)); ppad = partial.call(pad, " ", "%Cache".length); - log += ipad.call("Init") + " " + - cpad.call("Cache") + " " + - ppad.call("%Cache") + " Source location\n"; - log += ipad.call(initial) + " " + - cpad.call(cached) + " " + - ppad.call(toPrc(initial, cached)) + " (all)\n"; + log += + ipad.call("Init") + + " " + + cpad.call("Cache") + + " " + + ppad.call("%Cache") + + " Source location\n"; + log += + ipad.call(initial) + + " " + + cpad.call(cached) + + " " + + ppad.call(toPrc(initial, cached)) + + " (all)\n"; ordered.forEach(function (data) { var name = data[0]; data = data[1]; - log += ipad.call(data.initial) + " " + - cpad.call(data.cached) + " " + - ppad.call(toPrc(data.initial, data.cached)) + " " + name + "\n"; + log += + ipad.call(data.initial) + + " " + + cpad.call(data.cached) + + " " + + ppad.call(toPrc(data.initial, data.cached)) + + " " + + name + + "\n"; }); log += "------------------------------------------------------------\n"; return log; diff --git a/test/ext/async.js b/test/ext/async.js index 90dd05f..1382c89 100644 --- a/test/ext/async.js +++ b/test/ext/async.js @@ -1,3 +1,5 @@ +/* eslint id-length: 0, func-names: 0, handle-callback-err: 0, max-lines: 0 */ + "use strict"; var memoize = require("../..") @@ -18,39 +20,67 @@ module.exports = function () { mfn = memoize(fn, { async: true }); - a(mfn(3, 7, function (err, res) { - ++invoked; - a.deep([err, res], [null, 10], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - ++invoked; - a.deep([err, res], [null, 10], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - ++invoked; - a.deep([err, res], [null, 13], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - ++invoked; - a.deep([err, res], [null, 10], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - ++invoked; - a.deep([err, res], [null, 13], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + ++invoked; + a.deep([err, res], [null, 10], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + ++invoked; + a.deep([err, res], [null, 10], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + ++invoked; + a.deep([err, res], [null, 13], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + ++invoked; + a.deep([err, res], [null, 10], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + ++invoked; + a.deep([err, res], [null, 13], "Result B #2"); + }), + u, + "Initial #3" + ); nextTick(function () { a(i, 2, "Init Called"); a(invoked, 5, "Cb Called"); - a(mfn(3, 7, function (err, res) { - ++invoked; - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - ++invoked; - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + ++invoked; + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + ++invoked; + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 2, "Init Called #2"); @@ -58,14 +88,22 @@ module.exports = function () { mfn.delete(3, 7); - a(mfn(3, 7, function (err, res) { - ++invoked; - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - ++invoked; - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + ++invoked; + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + ++invoked; + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 3, "Init After delete"); @@ -87,31 +125,59 @@ module.exports = function () { mfn = memoize(fn, { async: true, dispose: a.never }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [e, undefined], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [e, undefined], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [e, undefined], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [e, undefined], "Result B #2"); + }), + u, + "Initial #3" + ); nextTick(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [e, undefined], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [e, undefined], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 4, "Again Called #2"); @@ -133,43 +199,79 @@ module.exports = function () { mfn = memoize(fn, { async: true, primitive: true }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #2"); + }), + u, + "Initial #3" + ); nextTick(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 2, "Again Called #2"); mfn.delete(3, 7); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 3, "Call After delete"); @@ -190,31 +292,59 @@ module.exports = function () { mfn = memoize(fn, { async: true, primitive: true }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [e, undefined], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [e, undefined], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [e, undefined], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [e, undefined], "Result B #2"); + }), + u, + "Initial #3" + ); nextTick(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [e, undefined], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [e, undefined], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 4, "Again Called #2"); @@ -223,12 +353,16 @@ module.exports = function () { }); }, "Primitive null arg case": function (a, d) { - var x = {}, mfn = memoize(function f (id, cb) { - cb(null, x); -}, { - async: true, - primitive: true - }); + var x = {} + , mfn = memoize( + function f (id, cb) { + cb(null, x); + }, + { + async: true, + primitive: true + } + ); mfn(null, function (err, res) { a.deep([err, res], [null, x], "Args"); diff --git a/test/ext/dispose.js b/test/ext/dispose.js index 62dd293..adf3a05 100644 --- a/test/ext/dispose.js +++ b/test/ext/dispose.js @@ -1,3 +1,5 @@ +/* eslint id-length: 0, max-lines: 0, max-statements: 0 */ + "use strict"; var memoize = require("../..") @@ -10,13 +12,14 @@ module.exports = function () { Regular: { "Sync": function (a) { var mfn, fn, value = [], x, invoked; - fn = function (x, y) { - return x + y; -}; - mfn = memoize(fn, { dispose: function (val) { - value.push(val); -} }); - + fn = function (arg1, arg2) { + return arg1 + arg2; + }; + mfn = memoize(fn, { + dispose: function (val) { + value.push(val); + } + }); mfn(3, 7); mfn(5, 8); mfn(12, 4); @@ -34,12 +37,16 @@ module.exports = function () { x = {}; invoked = false; - mfn = memoize(function () { - return x; -}, - { dispose: function (val) { - invoked = val; -} }); + mfn = memoize( + function () { + return x; + }, + { + dispose: function (val) { + invoked = val; + } + } + ); mfn.delete(); a(invoked, false, "No args: Post invalid delete"); @@ -51,12 +58,14 @@ module.exports = function () { "Ref counter": function (a) { var mfn, fn, value = []; fn = function (x, y) { - return x + y; -}; - mfn = memoize(fn, { refCounter: true, + return x + y; + }; + mfn = memoize(fn, { + refCounter: true, dispose: function (val) { - value.push(val); -} }); + value.push(val); + } + }); mfn(3, 7); mfn(5, 8); @@ -80,15 +89,17 @@ module.exports = function () { var mfn, fn, u = {}, value = []; fn = function (x, y, cb) { nextTick(function () { - cb(null, x + y); -}); + cb(null, x + y); + }); return u; }; - mfn = memoize(fn, { async: true, + mfn = memoize(fn, { + async: true, dispose: function (val) { - value.push(val); -} }); + value.push(val); + } + }); mfn(3, 7, function () { mfn(5, 8, function () { @@ -114,32 +125,38 @@ module.exports = function () { var mfn, fn, value = []; fn = function (x, y) { return new Promise(function (res) { - res(x + y); -}); + res(x + y); + }); }; - mfn = memoize(fn, { promise: true, + mfn = memoize(fn, { + promise: true, dispose: function (val) { - value.push(val); -} }); + value.push(val); + } + }); mfn(3, 7).done(function () { mfn(5, 8).done(function () { - mfn(12, 4).done(delay(function () { - a.deep(value, [], "Pre"); - mfn.delete(5, 8); - a.deep(value, [13], "#1"); - value = []; - mfn.delete(12, 4); - a.deep(value, [16], "#2"); + mfn(12, 4).done( + delay(function () { + a.deep(value, [], "Pre"); + mfn.delete(5, 8); + a.deep(value, [13], "#1"); + value = []; + mfn.delete(12, 4); + a.deep(value, [16], "#2"); - value = []; - mfn(77, 11).done(delay(function () { - mfn.clear(); - a.deep(value, [10, 88], "Clear all"); - d(); - })); - })); + value = []; + mfn(77, 11).done( + delay(function () { + mfn.clear(); + a.deep(value, [10, 88], "Clear all"); + d(); + }) + ); + }) + ); }); }); } @@ -148,11 +165,13 @@ module.exports = function () { "Sync": function (a) { var mfn, fn, value = []; fn = function (x, y) { - return x + y; -}; - mfn = memoize(fn, { dispose: function (val) { - value.push(val); -} }); + return x + y; + }; + mfn = memoize(fn, { + dispose: function (val) { + value.push(val); + } + }); mfn(3, 7); mfn(5, 8); @@ -172,12 +191,14 @@ module.exports = function () { "Ref counter": function (a) { var mfn, fn, value = []; fn = function (x, y) { - return x + y; -}; - mfn = memoize(fn, { refCounter: true, + return x + y; + }; + mfn = memoize(fn, { + refCounter: true, dispose: function (val) { - value.push(val); -} }); + value.push(val); + } + }); mfn(3, 7); mfn(5, 8); @@ -201,15 +222,17 @@ module.exports = function () { var mfn, fn, u = {}, value = []; fn = function (x, y, cb) { nextTick(function () { - cb(null, x + y); -}); + cb(null, x + y); + }); return u; }; - mfn = memoize(fn, { async: true, + mfn = memoize(fn, { + async: true, dispose: function (val) { - value.push(val); -} }); + value.push(val); + } + }); mfn(3, 7, function () { mfn(5, 8, function () { @@ -235,32 +258,38 @@ module.exports = function () { var mfn, fn, value = []; fn = function (x, y) { return new Promise(function (res) { - res(x + y); -}); + res(x + y); + }); }; - mfn = memoize(fn, { promise: true, + mfn = memoize(fn, { + promise: true, dispose: function (val) { - value.push(val); -} }); + value.push(val); + } + }); mfn(3, 7).done(function () { mfn(5, 8).done(function () { - mfn(12, 4).done(delay(function () { - a.deep(value, [], "Pre"); - mfn.delete(5, 8); - a.deep(value, [13], "#1"); - value = []; - mfn.delete(12, 4); - a.deep(value, [16], "#2"); + mfn(12, 4).done( + delay(function () { + a.deep(value, [], "Pre"); + mfn.delete(5, 8); + a.deep(value, [13], "#1"); + value = []; + mfn.delete(12, 4); + a.deep(value, [16], "#2"); - value = []; - mfn(77, 11).done(delay(function () { - mfn.clear(); - a.deep(value, [10, 88], "Clear all"); - d(); - })); - })); + value = []; + mfn(77, 11).done( + delay(function () { + mfn.clear(); + a.deep(value, [10, 88], "Clear all"); + d(); + }) + ); + }) + ); }); }); } diff --git a/test/ext/max-age.js b/test/ext/max-age.js index c4379ee..d8aba47 100644 --- a/test/ext/max-age.js +++ b/test/ext/max-age.js @@ -1,3 +1,6 @@ +/* eslint max-lines: 0, id-length: 0, func-names: 0, handle-callback-err: 0, max-lines: 0, +no-unused-vars: 0, max-nested-callbacks: 0, no-shadow: 0, max-len: 0 */ + "use strict"; var memoize = require("../..") @@ -12,7 +15,9 @@ module.exports = function () { return { Regular: { Sync: function (a, d) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y) { ++i; return x + y; @@ -56,7 +61,9 @@ module.exports = function () { }, 20); }, Promise: function (a, d) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y) { return new Promise(function (res) { ++i; @@ -110,7 +117,10 @@ module.exports = function () { }, 20); }, Async: function (a, d) { - var mfn, fn, u = {}, i = 0; + var mfn, + fn, + u = {}, + i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -121,41 +131,77 @@ module.exports = function () { mfn = memoize(fn, { async: true, maxAge: 100 }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #2"); + }), + u, + "Initial #3" + ); setTimeout(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); setTimeout(function () { a(i, 2, "Again Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 4, "Call After clear"); @@ -167,7 +213,9 @@ module.exports = function () { }, Primitive: { Sync: function (a, d) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y) { ++i; return x + y; @@ -206,7 +254,10 @@ module.exports = function () { }, 20); }, Async: function (a, d) { - var mfn, fn, u = {}, i = 0; + var mfn, + fn, + u = {}, + i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -217,41 +268,77 @@ module.exports = function () { mfn = memoize(fn, { async: true, primitive: true, maxAge: 100 }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #2"); + }), + u, + "Initial #3" + ); setTimeout(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); setTimeout(function () { a(i, 2, "Again Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 4, "Call After clear"); @@ -261,7 +348,9 @@ module.exports = function () { }, 20); }, Promise: function (a, d) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y, cb) { return new Promise(function (res) { ++i; @@ -317,7 +406,9 @@ module.exports = function () { }, Refetch: { Default: function (a, d) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y) { ++i; return x + y; @@ -372,17 +463,18 @@ module.exports = function () { d(); }, 200); }, 200); - }, 200); }, 300); }, Async: function (a, d) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y, cb) { ++i; setTimeout(function () { - cb(null, x + y); -}, 0); + cb(null, x + y); + }, 0); }; mfn = memoize(fn, { maxAge: 600, preFetch: true, async: true }); @@ -416,42 +508,142 @@ module.exports = function () { a(result, 13, "Result: Wait After B"); a(i, 3, "Called: Wait After B"); mfn(3, 7, function (err, result) { - a(result, 10, "Result: Wait After #2"); + a( + result, + 10, + "Result: Wait After #2" + ); a(i, 4, "Called: Wait After #2"); mfn(5, 8, function (err, result) { - a(result, 13, "Result: Wait After B #2"); - a(i, 4, "Called: Wait After B #2"); + a( + result, + 13, + "Result: Wait After B #2" + ); + a( + i, + 4, + "Called: Wait After B #2" + ); setTimeout(function () { - a(i, 4, "Called: After Refetch: Before"); - mfn(3, 7, function (err, result) { - a(result, 10, "Result: After Refetch"); - a(i, 4, "Called: After Refetch: After"); - mfn(5, 8, function (err, result) { - a(result, 13, "Result: After Refetch B"); - a(i, 4, "Called: After Refetch B: After"); - setTimeout(function () { - mfn(3, 7, function (err, result) { - a(result, 10, "Result: After Refetch #2"); - a(i, 4, "Called: After Refetch #2"); - mfn(5, 8, function (err, result) { - a(result, 13, "Result: After Refetch #2 B"); - a(i, 5, "Called: After Refetch #2 B"); - mfn(3, 7, function (err, result) { - a(result, 10, "Result: After Refetch #3"); - a(i, 6, "Called: After Refetch #3"); - mfn(5, 8, function (err, result) { - a(result, 13, "Result: After Refetch #3 B"); - a(i, 6, "Called: After Refetch #3 B"); - d(); - }); - }); - }); - }); - }, 200); + a( + i, + 4, + "Called: After Refetch: Before" + ); + mfn(3, 7, function ( + err, + result + ) { + a( + result, + 10, + "Result: After Refetch" + ); + a( + i, + 4, + "Called: After Refetch: After" + ); + mfn(5, 8, function ( + err, + result + ) { + a( + result, + 13, + "Result: After Refetch B" + ); + a( + i, + 4, + "Called: After Refetch B: After" + ); + setTimeout( + function () { + mfn( + 3, + 7, + function ( + err, + result + ) { + a( + result, + 10, + "Result: After Refetch #2" + ); + a( + i, + 4, + "Called: After Refetch #2" + ); + mfn( + 5, + 8, + function ( + err, + result + ) { + a( + result, + 13, + "Result: After Refetch #2 B" + ); + a( + i, + 5, + "Called: After Refetch #2 B" + ); + mfn( + 3, + 7, + function ( + err, + result + ) { + a( + result, + 10, + "Result: After Refetch #3" + ); + a( + i, + 6, + "Called: After Refetch #3" + ); + mfn( + 5, + 8, + function ( + err, + result + ) { + a( + result, + 13, + "Result: After Refetch #3 B" + ); + a( + i, + 6, + "Called: After Refetch #3 B" + ); + d(); + } + ); + } + ); + } + ); + } + ); + }, + 200 + ); }); }); }, 200); - }); }); }); @@ -465,15 +657,16 @@ module.exports = function () { }); }); }); - }, Promise: function (a, d) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y) { ++i; return new Promise(function (res) { - res(x + y); -}); + res(x + y); + }); }; mfn = memoize(fn, { maxAge: 600, preFetch: true, promise: true }); @@ -500,53 +693,186 @@ module.exports = function () { a(result, 13, "Result: Wait B"); a(i, 2, "Called: Wait B"); setTimeout(function () { - mfn(3, 7).done(delay(function (result) { - a(result, 10, "Result: Wait After"); - a(i, 3, "Called: Wait After"); - mfn(5, 8).done(delay(function (result) { - a(result, 13, "Result: Wait After B"); - a(i, 4, "Called: Wait After B"); - mfn(3, 7).done(delay(function (result) { - a(result, 10, "Result: Wait After #2"); - a(i, 4, "Called: Wait After #2"); - mfn(5, 8).done(function (result) { - a(result, 13, "Result: Wait After B #2"); - a(i, 4, "Called: Wait After B #2"); - setTimeout(function () { - a(i, 4, "Called: After Refetch: Before"); - mfn(3, 7).done(function (result) { - a(result, 10, "Result: After Refetch"); - a(i, 4, "Called: After Refetch: After"); - mfn(5, 8).done(function (result) { - a(result, 13, "Result: After Refetch B"); - a(i, 4, "Called: After Refetch B: After"); - setTimeout(function () { - mfn(3, 7).done(delay(function (result) { - a(result, 10, "Result: After Refetch #2"); - a(i, 5, "Called: After Refetch #2"); - mfn(5, 8).done(delay(function (result) { - a(result, 13, "Result: After Refetch #2 B"); - a(i, 6, "Called: After Refetch #2 B"); - mfn(3, 7).done(function (result) { - a(result, 10, "Result: After Refetch #3"); - a(i, 6, "Called: After Refetch #3"); - mfn(5, 8).done(function (result) { - a(result, 13, "Result: After Refetch #3 B"); - a(i, 6, "Called: After Refetch #3 B"); - d(); - }); - }); - }, 0)); - }, 0)); - }, 200); + mfn(3, 7).done( + delay(function (result) { + a(result, 10, "Result: Wait After"); + a(i, 3, "Called: Wait After"); + mfn(5, 8).done( + delay(function (result) { + a( + result, + 13, + "Result: Wait After B" + ); + a(i, 4, "Called: Wait After B"); + mfn(3, 7).done( + delay(function (result) { + a( + result, + 10, + "Result: Wait After #2" + ); + a( + i, + 4, + "Called: Wait After #2" + ); + mfn(5, 8).done(function ( + result + ) { + a( + result, + 13, + "Result: Wait After B #2" + ); + a( + i, + 4, + "Called: Wait After B #2" + ); + setTimeout( + function () { + a( + i, + 4, + "Called: After Refetch: Before" + ); + mfn( + 3, + 7 + ).done( + function ( + result + ) { + a( + result, + 10, + "Result: After Refetch" + ); + a( + i, + 4, + "Called: After Refetch: After" + ); + mfn( + 5, + 8 + ).done( + function ( + result + ) { + a( + result, + 13, + "Result: After Refetch B" + ); + a( + i, + 4, + "Called: After Refetch B: After" + ); + setTimeout( + function () { + mfn( + 3, + 7 + ).done( + delay( + function ( + result + ) { + a( + result, + 10, + "Result: After Refetch #2" + ); + a( + i, + 5, + "Called: After Refetch #2" + ); + mfn( + 5, + 8 + ).done( + delay( + function ( + result + ) { + a( + result, + 13, + "Result: After Refetch #2 B" + ); + a( + i, + 6, + "Called: After Refetch #2 B" + ); + mfn( + 3, + 7 + ).done( + function ( + result + ) { + a( + result, + 10, + "Result: After Refetch #3" + ); + a( + i, + 6, + "Called: After Refetch #3" + ); + mfn( + 5, + 8 + ).done( + function ( + result + ) { + a( + result, + 13, + "Result: After Refetch #3 B" + ); + a( + i, + 6, + "Called: After Refetch #3 B" + ); + d(); + } + ); + } + ); + }, + 0 + ) + ); + }, + 0 + ) + ); + }, + 200 + ); + } + ); + } + ); + }, + 200 + ); }); - }); - }, 200); - - }); - })); - }, 0)); - }, 0)); + }) + ); + }, 0) + ); + }, 0) + ); }, 200); }); }); @@ -556,10 +882,11 @@ module.exports = function () { }); }); }); - }, Custom: function (a, d) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y) { ++i; return x + y; @@ -613,7 +940,6 @@ module.exports = function () { d(); }, 200); }, 300); - }, 100); }, 450); } diff --git a/test/ext/max.js b/test/ext/max.js index 1e28e50..c9d9cd1 100644 --- a/test/ext/max.js +++ b/test/ext/max.js @@ -1,3 +1,5 @@ +/* eslint id-length: 0, max-lines: 0, max-statements: 0, max-nested-callbacks: 0, no-shadow: 0, max-len: 0 */ + "use strict"; var memoize = require("../..") @@ -9,7 +11,9 @@ 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; @@ -64,7 +68,10 @@ 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; @@ -75,232 +82,775 @@ module.exports = function () { mfn = memoize(fn, { async: true, max: 3 }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - a(i, 1, "Called #1"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + a(i, 1, "Called #1"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - a(i, 1, "Called #2"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + a(i, 1, "Called #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - a(i, 2, "Called B #1"); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + a(i, 2, "Called B #1"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - a(i, 2, "Called #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + a(i, 2, "Called #3"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - a(i, 2, "Called B #2"); + a( + mfn(5, 8, function (err, res) { + a.deep( + [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], "Result C #1"); - a(i, 3, "Called C #1"); + a( + mfn(12, 4, function (err, res) { + a.deep( + [err, res], + [null, 16], + "Result C #1" + ); + a(i, 3, "Called C #1"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #4"); - a(i, 3, "Called #4"); + a( + mfn(3, 7, function (err, res) { + a.deep( + [err, res], + [null, 10], + "Result #4" + ); + a(i, 3, "Called #4"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #3"); - a(i, 3, "Called B #3"); + a( + mfn(5, 8, function ( + err, + res + ) { + a.deep( + [err, res], + [null, 13], + "Result B #3" + ); + a( + i, + 3, + "Called B #3" + ); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], "Result D #1"); - a(i, 4, "Called D #1"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #1" + ); + a( + i, + 4, + "Called D #1" + ); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #4"); - a(i, 4, "Called B #4"); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 13 + ], + "Result B #4" + ); + a( + i, + 4, + "Called B #4" + ); - a(mfn(12, 4, function (err, res) { - a.deep([err, res], [null, 16], "Result C #2"); - a(i, 5, "Called C #2"); + a( + mfn( + 12, + 4, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 16 + ], + "Result C #2" + ); + a( + i, + 5, + "Called C #2" + ); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #5"); - a(i, 6, "Called #5"); + a( + mfn( + 3, + 7, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 10 + ], + "Result #5" + ); + a( + i, + 6, + "Called #5" + ); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], - "Result D #2"); - a(i, 7, "Called D #2"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #2" + ); + a( + i, + 7, + "Called D #2" + ); - a(mfn(12, 4, function (err, res) { - a.deep([err, res], [null, 16], - "Result C #3"); - a(i, 7, "Called C #3"); + a( + mfn( + 12, + 4, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 16 + ], + "Result C #3" + ); + a( + i, + 7, + "Called C #3" + ); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], - "Result B #5"); - a(i, 8, "Called B #5"); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 13 + ], + "Result B #5" + ); + a( + i, + 8, + "Called B #5" + ); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], - "Result D #3"); - a(i, 8, "Called D #3"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #3" + ); + a( + i, + 8, + "Called D #3" + ); - mfn.delete(77, 11); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], - "Result D #4"); - a(i, 9, "Called D #4"); + mfn.delete( + 77, + 11 + ); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #4" + ); + a( + i, + 9, + "Called D #4" + ); - mfn.clear(); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], - "Result B #6"); - a(i, 10, "Called B #6"); + mfn.clear(); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 13 + ], + "Result B #6" + ); + a( + i, + 10, + "Called B #6" + ); - a(mfn(77, 11, - function (err, res) { - a.deep([err, res], [null, 88], - "Result D #5"); - a(i, 11, "Called D #5"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #5" + ); + a( + i, + 11, + "Called D #5" + ); - d(); - }), u, "Initial D #5"); - }), u, "Initial B #6"); - }), u, "Initial D #4"); - }), u, "Initial D #3"); - }), u, "Initial B #5"); - }), u, "Initial C #3"); - }), u, "Initial D #2"); - }), u, "Initial #5"); - }), u, "Initial C #2"); - }), u, "Initial B #4"); - }), u, "Initial D #1"); - }), u, "Initial B #3"); - }), u, "Initial #4"); - }), u, "Initial C #1"); - }), u, "Initial B #2"); - }), u, "Initial #3"); - }), u, "Initial B #1"); - }), u, "Initial #2"); - }), u, "Initial #1"); + d(); + } + ), + u, + "Initial D #5" + ); + } + ), + u, + "Initial B #6" + ); + } + ), + u, + "Initial D #4" + ); + } + ), + u, + "Initial D #3" + ); + } + ), + u, + "Initial B #5" + ); + } + ), + u, + "Initial C #3" + ); + } + ), + u, + "Initial D #2" + ); + } + ), + u, + "Initial #5" + ); + } + ), + u, + "Initial C #2" + ); + } + ), + u, + "Initial B #4" + ); + } + ), + u, + "Initial D #1" + ); + }), + u, + "Initial B #3" + ); + }), + u, + "Initial #4" + ); + }), + u, + "Initial C #1" + ); + }), + u, + "Initial B #2" + ); + }), + u, + "Initial #3" + ); + }), + u, + "Initial B #1" + ); + }), + u, + "Initial #2" + ); + }), + 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); -}); + res(x + y); + }); }; mfn = memoize(fn, { promise: true, max: 3 }); - mfn(3, 7).done(delay(function (res) { // [3,7] - a(res, 10, "Result #1"); - a(i, 1, "Called #1"); + mfn(3, 7).done( + delay(function (res) { + // [3,7] + a(res, 10, "Result #1"); + a(i, 1, "Called #1"); - mfn(3, 7).done(delay(function (res) { - a(res, 10, "Result #2"); - a(i, 1, "Called #2"); + mfn(3, 7).done( + delay(function (res) { + a(res, 10, "Result #2"); + a(i, 1, "Called #2"); - mfn(5, 8).done(delay(function (res) { // [3,7], [5,8] - a(res, 13, "Result B #1"); - a(i, 2, "Called B #1"); + mfn(5, 8).done( + delay(function (res) { + // [3,7], [5,8] + a(res, 13, "Result B #1"); + a(i, 2, "Called B #1"); - mfn(3, 7).done(delay(function (res) { // [5,8], [3, 7] - a(res, 10, "Result #3"); - a(i, 2, "Called #3"); + mfn(3, 7).done( + delay(function (res) { + // [5,8], [3, 7] + a(res, 10, "Result #3"); + a(i, 2, "Called #3"); - mfn(5, 8).done(delay(function (res) { // [3,7], [5,8] - a(res, 13, "Result B #2"); - a(i, 2, "Called B #2"); + mfn(5, 8).done( + delay(function (res) { + // [3,7], [5,8] + a(res, 13, "Result B #2"); + a(i, 2, "Called B #2"); - mfn(12, 4).done(delay(function (res) { // [3,7], [5,8], [12, 4] - a(res, 16, "Result C #1"); - a(i, 3, "Called C #1"); + mfn(12, 4).done( + delay(function (res) { + // [3,7], [5,8], [12, 4] + a(res, 16, "Result C #1"); + a(i, 3, "Called C #1"); - mfn(3, 7).done(delay(function (res) { // [5,8], [12, 4], [3, 7] - a(res, 10, "Result #4"); - a(i, 3, "Called #4"); + mfn(3, 7).done( + delay(function (res) { + // [5,8], [12, 4], [3, 7] + a(res, 10, "Result #4"); + a(i, 3, "Called #4"); - mfn(5, 8).done(delay(function (res) { // [12, 4], [3, 7], [5, 8] - a(res, 13, "Result B #3"); - a(i, 3, "Called B #3"); + mfn(5, 8).done( + delay(function (res) { + // [12, 4], [3, 7], [5, 8] + a( + res, + 13, + "Result B #3" + ); + a( + i, + 3, + "Called B #3" + ); - mfn(77, 11).done(delay(function (res) { // [3, 7], [5, 8], [77, 11] - a(res, 88, "Result D #1"); - a(i, 4, "Called D #1"); + mfn(77, 11).done( + delay(function ( + res + ) { + // [3, 7], [5, 8], [77, 11] + a( + res, + 88, + "Result D #1" + ); + a( + i, + 4, + "Called D #1" + ); - mfn(5, 8).done(delay(function (res) { // [3, 7], [77, 11], [5, 8] - a(res, 13, "Result B #4"); - a(i, 4, "Called B #4"); + mfn( + 5, + 8 + ).done( + delay( + function ( + res + ) { + // [3, 7], [77, 11], [5, 8] + a( + res, + 13, + "Result B #4" + ); + a( + i, + 4, + "Called B #4" + ); - mfn(12, 4).done(delay(function (res) { // [77, 11], [5, 8], [12, 4] - a(res, 16, "Result C #2"); - a(i, 5, "Called C #2"); + mfn( + 12, + 4 + ).done( + delay( + function ( + res + ) { + // [77, 11], [5, 8], [12, 4] + a( + res, + 16, + "Result C #2" + ); + a( + i, + 5, + "Called C #2" + ); - mfn(3, 7).done(delay(function (res) { - a(res, 10, "Result #5"); - a(i, 6, "Called #5"); + mfn( + 3, + 7 + ).done( + delay( + function ( + res + ) { + a( + res, + 10, + "Result #5" + ); + a( + i, + 6, + "Called #5" + ); - mfn(77, 11).done(delay(function (res) { - a(res, 88, - "Result D #2"); - a(i, 7, "Called D #2"); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #2" + ); + a( + i, + 7, + "Called D #2" + ); - mfn(12, 4).done(delay(function (res) { - a(res, 16, - "Result C #3"); - a(i, 7, "Called C #3"); + mfn( + 12, + 4 + ).done( + delay( + function ( + res + ) { + a( + res, + 16, + "Result C #3" + ); + a( + i, + 7, + "Called C #3" + ); - mfn(5, 8).done(delay(function (res) { - a(res, 13, - "Result B #5"); - a(i, 8, "Called B #5"); + mfn( + 5, + 8 + ).done( + delay( + function ( + res + ) { + a( + res, + 13, + "Result B #5" + ); + a( + i, + 8, + "Called B #5" + ); - mfn(77, 11).done(delay(function (res) { - a(res, 88, - "Result D #3"); - a(i, 8, "Called D #3"); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #3" + ); + a( + i, + 8, + "Called D #3" + ); - mfn.delete(77, 11); - mfn(77, 11).done(delay(function (res) { - a(res, 88, - "Result D #4"); - a(i, 9, "Called D #4"); + mfn.delete( + 77, + 11 + ); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #4" + ); + a( + i, + 9, + "Called D #4" + ); - mfn.clear(); - mfn(5, 8).done(delay(function (res) { - a(res, 13, "Result B #6"); - a(i, 10, "Called B #6"); + mfn.clear(); + mfn( + 5, + 8 + ).done( + delay( + function ( + res + ) { + a( + res, + 13, + "Result B #6" + ); + a( + i, + 10, + "Called B #6" + ); - mfn(77, 11).done(delay(function (res) { - a(res, 88, "Result D #5"); - a(i, 11, "Called D #5"); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #5" + ); + a( + i, + 11, + "Called D #5" + ); - d(); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); + d(); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + }) + ); + }) + ); + }) + ); + }) + ); + }) + ); + }) + ); + }) + ); + }) + ); + }) + ); } }, Primitive: { Sync: function (a) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y) { ++i; return x + y; @@ -355,7 +905,10 @@ 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; @@ -366,222 +919,758 @@ module.exports = function () { mfn = memoize(fn, { async: true, primitive: true, max: 3 }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - a(i, 1, "Called #1"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + a(i, 1, "Called #1"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - a(i, 1, "Called #2"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + a(i, 1, "Called #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - a(i, 2, "Called B #1"); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + a(i, 2, "Called B #1"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - a(i, 2, "Called #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + a(i, 2, "Called #3"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - a(i, 2, "Called B #2"); + a( + mfn(5, 8, function (err, res) { + a.deep( + [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], "Result C #1"); - a(i, 3, "Called C #1"); + a( + mfn(12, 4, function (err, res) { + a.deep( + [err, res], + [null, 16], + "Result C #1" + ); + a(i, 3, "Called C #1"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #4"); - a(i, 3, "Called #4"); + a( + mfn(3, 7, function (err, res) { + a.deep( + [err, res], + [null, 10], + "Result #4" + ); + a(i, 3, "Called #4"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #3"); - a(i, 3, "Called B #3"); + a( + mfn(5, 8, function ( + err, + res + ) { + a.deep( + [err, res], + [null, 13], + "Result B #3" + ); + a( + i, + 3, + "Called B #3" + ); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], "Result D #1"); - a(i, 4, "Called D #1"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #1" + ); + a( + i, + 4, + "Called D #1" + ); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #4"); - a(i, 4, "Called B #4"); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 13 + ], + "Result B #4" + ); + a( + i, + 4, + "Called B #4" + ); - a(mfn(12, 4, function (err, res) { - a.deep([err, res], [null, 16], "Result C #2"); - a(i, 5, "Called C #2"); + a( + mfn( + 12, + 4, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 16 + ], + "Result C #2" + ); + a( + i, + 5, + "Called C #2" + ); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #5"); - a(i, 6, "Called #5"); + a( + mfn( + 3, + 7, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 10 + ], + "Result #5" + ); + a( + i, + 6, + "Called #5" + ); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], - "Result D #2"); - a(i, 7, "Called D #2"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #2" + ); + a( + i, + 7, + "Called D #2" + ); - a(mfn(12, 4, function (err, res) { - a.deep([err, res], [null, 16], - "Result C #3"); - a(i, 7, "Called C #3"); + a( + mfn( + 12, + 4, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 16 + ], + "Result C #3" + ); + a( + i, + 7, + "Called C #3" + ); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], - "Result B #5"); - a(i, 8, "Called B #5"); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 13 + ], + "Result B #5" + ); + a( + i, + 8, + "Called B #5" + ); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], - "Result D #3"); - a(i, 8, "Called D #3"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #3" + ); + a( + i, + 8, + "Called D #3" + ); - mfn.delete(77, 11); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], - "Result D #4"); - a(i, 9, "Called D #4"); + mfn.delete( + 77, + 11 + ); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #4" + ); + a( + i, + 9, + "Called D #4" + ); - mfn.clear(); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], - "Result B #6"); - a(i, 10, "Called B #6"); + mfn.clear(); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 13 + ], + "Result B #6" + ); + a( + i, + 10, + "Called B #6" + ); - a(mfn(77, 11, - function (err, res) { - a.deep([err, res], [null, 88], - "Result D #5"); - a(i, 11, "Called D #5"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #5" + ); + a( + i, + 11, + "Called D #5" + ); - d(); - }), u, "Initial D #5"); - }), u, "Initial B #6"); - }), u, "Initial D #4"); - }), u, "Initial D #3"); - }), u, "Initial B #5"); - }), u, "Initial C #3"); - }), u, "Initial D #2"); - }), u, "Initial #5"); - }), u, "Initial C #2"); - }), u, "Initial B #4"); - }), u, "Initial D #1"); - }), u, "Initial B #3"); - }), u, "Initial #4"); - }), u, "Initial C #1"); - }), u, "Initial B #2"); - }), u, "Initial #3"); - }), u, "Initial B #1"); - }), u, "Initial #2"); - }), u, "Initial #1"); + d(); + } + ), + u, + "Initial D #5" + ); + } + ), + u, + "Initial B #6" + ); + } + ), + u, + "Initial D #4" + ); + } + ), + u, + "Initial D #3" + ); + } + ), + u, + "Initial B #5" + ); + } + ), + u, + "Initial C #3" + ); + } + ), + u, + "Initial D #2" + ); + } + ), + u, + "Initial #5" + ); + } + ), + u, + "Initial C #2" + ); + } + ), + u, + "Initial B #4" + ); + } + ), + u, + "Initial D #1" + ); + }), + u, + "Initial B #3" + ); + }), + u, + "Initial #4" + ); + }), + u, + "Initial C #1" + ); + }), + u, + "Initial B #2" + ); + }), + u, + "Initial #3" + ); + }), + u, + "Initial B #1" + ); + }), + u, + "Initial #2" + ); + }), + 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); -}); + res(x + y); + }); }; mfn = memoize(fn, { promise: true, primitive: true, max: 3 }); - mfn(3, 7).done(delay(function (res) { - a(res, 10, "Result #1"); - a(i, 1, "Called #1"); + mfn(3, 7).done( + delay(function (res) { + a(res, 10, "Result #1"); + a(i, 1, "Called #1"); - mfn(3, 7).done(delay(function (res) { - a(res, 10, "Result #2"); - a(i, 1, "Called #2"); + mfn(3, 7).done( + delay(function (res) { + a(res, 10, "Result #2"); + a(i, 1, "Called #2"); - mfn(5, 8).done(delay(function (res) { - a(res, 13, "Result B #1"); - a(i, 2, "Called B #1"); + mfn(5, 8).done( + delay(function (res) { + a(res, 13, "Result B #1"); + a(i, 2, "Called B #1"); - mfn(3, 7).done(delay(function (res) { - a(res, 10, "Result #3"); - a(i, 2, "Called #3"); + mfn(3, 7).done( + delay(function (res) { + a(res, 10, "Result #3"); + a(i, 2, "Called #3"); - mfn(5, 8).done(delay(function (res) { - a(res, 13, "Result B #2"); - a(i, 2, "Called B #2"); + mfn(5, 8).done( + delay(function (res) { + a(res, 13, "Result B #2"); + a(i, 2, "Called B #2"); - mfn(12, 4).done(delay(function (res) { - a(res, 16, "Result C #1"); - a(i, 3, "Called C #1"); + mfn(12, 4).done( + delay(function (res) { + a(res, 16, "Result C #1"); + a(i, 3, "Called C #1"); - mfn(3, 7).done(delay(function (res) { - a(res, 10, "Result #4"); - a(i, 3, "Called #4"); + mfn(3, 7).done( + delay(function (res) { + a(res, 10, "Result #4"); + a(i, 3, "Called #4"); - mfn(5, 8).done(delay(function (res) { - a(res, 13, "Result B #3"); - a(i, 3, "Called B #3"); + mfn(5, 8).done( + delay(function (res) { + a( + res, + 13, + "Result B #3" + ); + a( + i, + 3, + "Called B #3" + ); - mfn(77, 11).done(delay(function (res) { - a(res, 88, "Result D #1"); - a(i, 4, "Called D #1"); + mfn(77, 11).done( + delay(function ( + res + ) { + a( + res, + 88, + "Result D #1" + ); + a( + i, + 4, + "Called D #1" + ); - mfn(5, 8).done(delay(function (res) { - a(res, 13, "Result B #4"); - a(i, 4, "Called B #4"); + mfn( + 5, + 8 + ).done( + delay( + function ( + res + ) { + a( + res, + 13, + "Result B #4" + ); + a( + i, + 4, + "Called B #4" + ); - mfn(12, 4).done(delay(function (res) { - a(res, 16, "Result C #2"); - a(i, 5, "Called C #2"); + mfn( + 12, + 4 + ).done( + delay( + function ( + res + ) { + a( + res, + 16, + "Result C #2" + ); + a( + i, + 5, + "Called C #2" + ); - mfn(3, 7).done(delay(function (res) { - a(res, 10, "Result #5"); - a(i, 6, "Called #5"); + mfn( + 3, + 7 + ).done( + delay( + function ( + res + ) { + a( + res, + 10, + "Result #5" + ); + a( + i, + 6, + "Called #5" + ); - mfn(77, 11).done(delay(function (res) { - a(res, 88, "Result D #2"); - a(i, 7, "Called D #2"); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #2" + ); + a( + i, + 7, + "Called D #2" + ); - mfn(12, 4).done(delay(function (res) { - a(res, 16, "Result C #3"); - a(i, 7, "Called C #3"); + mfn( + 12, + 4 + ).done( + delay( + function ( + res + ) { + a( + res, + 16, + "Result C #3" + ); + a( + i, + 7, + "Called C #3" + ); - mfn(5, 8).done(delay(function (res) { - a(res, 13, "Result B #5"); - a(i, 8, "Called B #5"); + mfn( + 5, + 8 + ).done( + delay( + function ( + res + ) { + a( + res, + 13, + "Result B #5" + ); + a( + i, + 8, + "Called B #5" + ); - mfn(77, 11).done(delay(function (res) { - a(res, 88, "Result D #3"); - a(i, 8, "Called D #3"); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #3" + ); + a( + i, + 8, + "Called D #3" + ); - mfn.delete(77, 11); - mfn(77, 11).done(delay(function (res) { - a(res, 88, "Result D #4"); - a(i, 9, "Called D #4"); + mfn.delete( + 77, + 11 + ); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #4" + ); + a( + i, + 9, + "Called D #4" + ); - mfn.clear(); - mfn(5, 8).done(delay(function (res) { - a(res, 13, "Result B #6"); - a(i, 10, "Called B #6"); + mfn.clear(); + mfn( + 5, + 8 + ).done( + delay( + function ( + res + ) { + a( + res, + 13, + "Result B #6" + ); + a( + i, + 10, + "Called B #6" + ); - mfn(77, 11).done(delay(function (res) { - a(res, 88, "Result D #5"); - a(i, 11, "Called D #5"); + mfn( + 77, + 11 + ).done( + delay( + function ( + res + ) { + a( + res, + 88, + "Result D #5" + ); + a( + i, + 11, + "Called D #5" + ); - d(); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); - })); + d(); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + } + ) + ); + }) + ); + }) + ); + }) + ); + }) + ); + }) + ); + }) + ); + }) + ); + }) + ); + }) + ); } } }; diff --git a/test/ext/promise.js b/test/ext/promise.js index 48f1024..7edba87 100644 --- a/test/ext/promise.js +++ b/test/ext/promise.js @@ -1,3 +1,5 @@ +/* eslint id-length: 0, handle-callback-err: 0, no-undef: 0, no-unused-vars: 0, func-names: 0 */ + "use strict"; var memoize = require("../..") @@ -219,14 +221,17 @@ module.exports = function () { }, "Primitive null arg case": function (a, d) { var mfn, x = {}; - mfn = memoize(function f (id) { - return new Promise(function (res) { - res(x); -}); - }, { - promise: true, - primitive: true - }); + mfn = memoize( + function f (id) { + return new Promise(function (res) { + res(x); + }); + }, + { + promise: true, + primitive: true + } + ); mfn(null).done(function (res) { a.deep(res, x, "Args"); diff --git a/test/ext/ref-counter.js b/test/ext/ref-counter.js index b183549..0b8f67b 100644 --- a/test/ext/ref-counter.js +++ b/test/ext/ref-counter.js @@ -1,3 +1,5 @@ +/* eslint max-lines: 0, id-length: 0, no-undef: 0 */ + "use strict"; var memoize = require("../..") @@ -7,9 +9,12 @@ var memoize = require("../..") module.exports = function () { return { "Regular": function (a) { - var i = 0, fn = function (x, y, z) { - ++i; return x + y + z; -}, mfn; + var i = 0 + , fn = function (x, y, z) { + ++i; + return x + y + z; + } + , mfn; mfn = memoize(fn, { refCounter: true }); a(mfn.deleteRef(3, 5, 7), null, "Delete before"); a(mfn(3, 5, 7), 15, "Initial"); @@ -42,31 +47,59 @@ module.exports = function () { a(mfn.deleteRef(3, 7), null, "Delete ref before"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #2"); + }), + u, + "Initial #3" + ); nextTick(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 2, "Again Called #2"); @@ -76,12 +109,20 @@ module.exports = function () { a(mfn.deleteRef(3, 7), false, "Delete ref #3"); a(mfn.deleteRef(3, 7), true, "Delete ref Final"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 3, "Call After delete"); @@ -95,8 +136,8 @@ module.exports = function () { fn = function (x, y) { ++i; return new Promise(function (res) { - res(x + y); -}); + res(x + y); + }); }; mfn = memoize(fn, { promise: true, refCounter: true }); @@ -152,9 +193,12 @@ module.exports = function () { }, 10); }, "Primitive": function (a) { - var i = 0, fn = function (x, y, z) { - ++i; return x + y + z; -}, mfn; + var i = 0 + , fn = function (x, y, z) { + ++i; + return x + y + z; + } + , mfn; mfn = memoize(fn, { primitive: true, refCounter: true }); a(mfn.deleteRef(3, 5, 7), null, "Delete before"); a(mfn(3, 5, 7), 15, "Initial"); @@ -187,31 +231,59 @@ module.exports = function () { a(mfn.deleteRef(3, 7), null, "Delete ref before"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #2"); + }), + u, + "Initial #3" + ); nextTick(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 2, "Again Called #2"); @@ -221,12 +293,20 @@ module.exports = function () { a(mfn.deleteRef(3, 7), false, "Delete ref #3"); a(mfn.deleteRef(3, 7), true, "Delete ref Final"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 3, "Call After delete"); @@ -240,8 +320,8 @@ module.exports = function () { fn = function (x, y) { ++i; return new Promise(function (res) { - res(x + y); -}); + res(x + y); + }); }; mfn = memoize(fn, { promise: true, primitive: true, refCounter: true }); diff --git a/test/index.js b/test/index.js index ee63a12..c33ab8e 100644 --- a/test/index.js +++ b/test/index.js @@ -1,16 +1,20 @@ +/* eslint max-lines: 0, max-statements: 0, id-length: 0, no-shadow: 0, max-nested-callbacks: 0, max-len: 0 */ + "use strict"; var aFrom = require("es5-ext/array/from") - , nextTick = require("next-tick") + , nextTick = require("next-tick"); - , join = Array.prototype.join; +var join = Array.prototype.join; module.exports = function (t, a) { return { "0": function () { - var i = 0, fn = function () { - ++i; return 3; -}; + var i = 0, + fn = function () { + ++i; + return 3; + }; fn = t(fn); a(fn(), 3, "First"); @@ -19,9 +23,11 @@ module.exports = function (t, a) { a(i, 1, "Called once"); }, "1": function () { - var i = 0, fn = function (x) { - ++i; return x; -}; + var i = 0, + fn = function (x) { + ++i; + return x; + }; fn = t(fn); return { @@ -51,9 +57,12 @@ module.exports = function (t, a) { }; }, "3": function () { - var i = 0, fn = function (x, y, z) { - ++i; return [x, y, z]; -}, r; + var i = 0, + fn = function (x, y, z) { + ++i; + return [x, y, z]; + }, + r; fn = t(fn); return { @@ -97,12 +106,17 @@ module.exports = function (t, a) { }; }, "Normalizer function": function () { - var i = 0, fn = function () { - ++i; return join.call(arguments, "|"); -}, mfn; - mfn = t(fn, { normalizer: function (args) { - return Boolean(args[0]); -} }); + var i = 0, + fn = function () { + ++i; + return join.call(arguments, "|"); + }, + mfn; + mfn = t(fn, { + normalizer: function (args) { + return Boolean(args[0]); + } + }); a(mfn(false, "raz"), "false|raz", "#1"); a(mfn(0, "dwa"), "false|raz", "#2"); a(i, 1, "Called once"); @@ -112,9 +126,12 @@ module.exports = function (t, a) { a(i, 2, "Called twice #2"); }, "Dynamic": function () { - var i = 0, fn = function () { - ++i; return arguments; -}, r; + var i = 0, + fn = function () { + ++i; + return arguments; + }, + r; fn = t(fn, { length: false }); return { @@ -144,11 +161,16 @@ module.exports = function (t, a) { }; }, "Resolvers": function () { - var i = 0, fn, r; - fn = t(function () { - ++i; return arguments; -}, - { length: 3, resolvers: [Boolean, String] }); + var i = 0, + fn, + r; + fn = t( + function () { + ++i; + return arguments; + }, + { length: 3, resolvers: [Boolean, String] } + ); return { "No args": function () { i = 0; @@ -160,15 +182,13 @@ module.exports = function (t, a) { "Some Args": function () { 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.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"); } @@ -178,7 +198,10 @@ module.exports = function (t, a) { }, "Clear Cache": { Specific: function () { - var i = 0, fn, mfn, x = {}; + var i = 0, + fn, + mfn, + x = {}; fn = function (a, b, c) { if (c === 3) { @@ -209,7 +232,9 @@ module.exports = function (t, a) { a(i, 1, "Proper no arguments clear"); }, All: function () { - var i = 0, fn, x = {}; + var i = 0, + fn, + x = {}; fn = function () { ++i; @@ -232,62 +257,88 @@ module.exports = function (t, a) { }, "Primitive": { "No args": function (a) { - var i = 0, fn = function () { - ++i; return arguments[0]; -}, mfn; + var i = 0, + fn = function () { + ++i; + return arguments[0]; + }, + mfn; mfn = t(fn, { primitive: true }); a(mfn("ble"), "ble", "#1"); a(mfn({}), "ble", "#2"); a(i, 1, "Called once"); }, "One arg": function (a) { - var i = 0, fn = function (x) { - ++i; return x; -}, mfn - , y = { toString: function () { - return "foo"; -} }; + var i = 0, + fn = function (x) { + ++i; + return x; + }, + mfn, + y = { + toString: function () { + return "foo"; + } + }; mfn = t(fn, { primitive: true }); a(mfn(y), y, "#1"); a(mfn("foo"), y, "#2"); a(i, 1, "Called once"); }, "Many args": function (a) { - var i = 0, fn = function (x, y, z) { - ++i; return x + y + z; -}, mfn - , y = { toString: function () { - return "foo"; -} }; + var i = 0, + fn = function (x, y, z) { + ++i; + return x + y + z; + }, + mfn, + y = { + toString: function () { + return "foo"; + } + }; mfn = t(fn, { primitive: true }); a(mfn(y, "bar", "zeta"), "foobarzeta", "#1"); a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2"); a(i, 1, "Called once"); }, "Clear cache": function (a) { - var i = 0, fn = function (x, y, z) { - ++i; return x + y + z; -}, mfn - , y = { toString: function () { - return "foo"; -} }; + var i = 0, + fn = function (x, y, z) { + ++i; + return x + y + z; + }, + mfn, + y = { + toString: function () { + return "foo"; + } + }; mfn = t(fn, { primitive: true }); a(mfn(y, "bar", "zeta"), "foobarzeta", "#1"); a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2"); a(i, 1, "Called once"); - mfn.delete("foo", { toString: function () { - return "bar"; -} }, - "zeta"); + mfn.delete( + "foo", + { + toString: function () { + return "bar"; + } + }, + "zeta" + ); a(mfn(y, "bar", "zeta"), "foobarzeta", "#3"); a(i, 2, "Called twice"); } }, "Reference counter": { Regular: function (a) { - var i = 0, fn = function (x, y, z) { - ++i; return x + y + z; -}, mfn; + var i = 0, + fn = function (x, y, z) { + ++i; + return x + y + z; + }, + mfn; mfn = t(fn, { refCounter: true }); a(mfn.deleteRef(3, 5, 7), null, "Clear before"); a(mfn(3, 5, 7), 15, "Initial"); @@ -307,9 +358,12 @@ module.exports = function (t, a) { a(i, 2, "Cached again"); }, Primitive: function (a) { - var i = 0, fn = function (x, y, z) { - ++i; return x + y + z; -}, mfn; + var i = 0, + fn = function (x, y, z) { + ++i; + return x + y + z; + }, + mfn; mfn = t(fn, { primitive: true, refCounter: true }); a(mfn.deleteRef(3, 5, 7), null, "Clear before"); a(mfn(3, 5, 7), 15, "Initial"); @@ -332,7 +386,11 @@ module.exports = function (t, a) { "Async": { Regular: { "Success": function (a, d) { - var mfn, fn, u = {}, i = 0, invoked = 0; + var mfn, + fn, + u = {}, + i = 0, + invoked = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -343,39 +401,67 @@ module.exports = function (t, a) { mfn = t(fn, { async: true }); - a(mfn(3, 7, function (err, res) { - ++invoked; - a.deep([err, res], [null, 10], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - ++invoked; - a.deep([err, res], [null, 10], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - ++invoked; - a.deep([err, res], [null, 13], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - ++invoked; - a.deep([err, res], [null, 10], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - ++invoked; - a.deep([err, res], [null, 13], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + ++invoked; + a.deep([err, res], [null, 10], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + ++invoked; + a.deep([err, res], [null, 10], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + ++invoked; + a.deep([err, res], [null, 13], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + ++invoked; + a.deep([err, res], [null, 10], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + ++invoked; + a.deep([err, res], [null, 13], "Result B #2"); + }), + u, + "Initial #3" + ); nextTick(function () { a(i, 2, "Init Called"); a(invoked, 5, "Cb Called"); - a(mfn(3, 7, function (err, res) { - ++invoked; - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - ++invoked; - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + ++invoked; + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + ++invoked; + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 2, "Init Called #2"); @@ -383,14 +469,22 @@ module.exports = function (t, a) { mfn.delete(3, 7); - a(mfn(3, 7, function (err, res) { - ++invoked; - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - ++invoked; - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + ++invoked; + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + ++invoked; + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 3, "Init After clear"); @@ -401,7 +495,10 @@ module.exports = function (t, a) { }); }, "Reference counter": function (a, d) { - var mfn, fn, u = {}, i = 0; + var mfn, + fn, + u = {}, + i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -414,31 +511,59 @@ module.exports = function (t, a) { a(mfn.deleteRef(3, 7), null, "Clear ref before"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #2"); + }), + u, + "Initial #3" + ); nextTick(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 2, "Again Called #2"); @@ -448,12 +573,20 @@ module.exports = function (t, a) { a(mfn.deleteRef(3, 7), false, "Clear ref #3"); a(mfn.deleteRef(3, 7), true, "Clear ref Final"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 3, "Call After clear"); @@ -463,7 +596,11 @@ module.exports = function (t, a) { }); }, "Error": function (a, d) { - var mfn, fn, u = {}, i = 0, e = new Error("Test"); + var mfn, + fn, + u = {}, + i = 0, + e = new Error("Test"); fn = function (x, y, cb) { nextTick(function () { ++i; @@ -474,31 +611,59 @@ module.exports = function (t, a) { mfn = t(fn, { async: true }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [e, undefined], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [e, undefined], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [e, undefined], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [e, undefined], "Result B #2"); + }), + u, + "Initial #3" + ); nextTick(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [e, undefined], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [e, undefined], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 4, "Again Called #2"); @@ -509,7 +674,10 @@ module.exports = function (t, a) { }, Primitive: { "Success": function (a, d) { - var mfn, fn, u = {}, i = 0; + var mfn, + fn, + u = {}, + i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -520,43 +688,79 @@ module.exports = function (t, a) { mfn = t(fn, { async: true, primitive: true }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #2"); + }), + u, + "Initial #3" + ); nextTick(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 2, "Again Called #2"); mfn.delete(3, 7); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 3, "Call After clear"); @@ -566,7 +770,10 @@ module.exports = function (t, a) { }); }, "Reference counter": function (a, d) { - var mfn, fn, u = {}, i = 0; + var mfn, + fn, + u = {}, + i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -579,31 +786,59 @@ module.exports = function (t, a) { a(mfn.deleteRef(3, 7), null, "Clear ref before"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #2"); + }), + u, + "Initial #3" + ); nextTick(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 2, "Again Called #2"); @@ -613,12 +848,20 @@ module.exports = function (t, a) { a(mfn.deleteRef(3, 7), false, "Clear ref #3"); a(mfn.deleteRef(3, 7), true, "Clear ref Final"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 3, "Call After clear"); @@ -628,7 +871,11 @@ module.exports = function (t, a) { }); }, "Error": function (a, d) { - var mfn, fn, u = {}, i = 0, e = new Error("Test"); + var mfn, + fn, + u = {}, + i = 0, + e = new Error("Test"); fn = function (x, y, cb) { nextTick(function () { ++i; @@ -639,31 +886,59 @@ module.exports = function (t, a) { mfn = t(fn, { async: true, primitive: true }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [e, undefined], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [e, undefined], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [e, undefined], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [e, undefined], "Result B #2"); + }), + u, + "Initial #3" + ); nextTick(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [e, undefined], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [e, undefined], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [e, undefined], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [e, undefined], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 4, "Again Called #2"); @@ -676,7 +951,9 @@ module.exports = function (t, a) { "MaxAge": { Regular: { Sync: function (a, d) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y) { ++i; return x + y; @@ -715,7 +992,10 @@ module.exports = function (t, a) { }, 20); }, Async: function (a, d) { - var mfn, fn, u = {}, i = 0; + var mfn, + fn, + u = {}, + i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -726,41 +1006,77 @@ module.exports = function (t, a) { mfn = t(fn, { async: true, maxAge: 100 }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #2"); + }), + u, + "Initial #3" + ); setTimeout(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); setTimeout(function () { a(i, 2, "Again Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 4, "Call After clear"); @@ -772,7 +1088,9 @@ module.exports = function (t, a) { }, Primitive: { Sync: function (a, d) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y) { ++i; return x + y; @@ -811,7 +1129,10 @@ module.exports = function (t, a) { }, 20); }, Async: function (a, d) { - var mfn, fn, u = {}, i = 0; + var mfn, + fn, + u = {}, + i = 0; fn = function (x, y, cb) { nextTick(function () { ++i; @@ -822,41 +1143,77 @@ module.exports = function (t, a) { mfn = t(fn, { async: true, primitive: true, maxAge: 100 }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - }), u, "Initial"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - }), u, "Initial #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - }), u, "Initial #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - }), u, "Initial #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + }), + u, + "Initial" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + }), + u, + "Initial #2" + ); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + }), + u, + "Initial #2" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #2"); + }), + u, + "Initial #3" + ); setTimeout(function () { a(i, 2, "Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); setTimeout(function () { a(i, 2, "Again Called #2"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Again: Result"); - }), u, "Again: Initial"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Again B: Result"); - }), u, "Again B: Initial"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Again: Result"); + }), + u, + "Again: Initial" + ); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Again B: Result"); + }), + u, + "Again B: Initial" + ); nextTick(function () { a(i, 4, "Call After clear"); @@ -870,7 +1227,9 @@ module.exports = function (t, a) { "Max": { Regular: { Sync: function (a) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y) { ++i; return x + y; @@ -925,7 +1284,10 @@ module.exports = function (t, a) { 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; @@ -936,117 +1298,447 @@ module.exports = function (t, a) { mfn = t(fn, { async: true, max: 3 }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - a(i, 1, "Called #1"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + a(i, 1, "Called #1"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - a(i, 1, "Called #2"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + a(i, 1, "Called #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - a(i, 2, "Called B #1"); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + a(i, 2, "Called B #1"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - a(i, 2, "Called #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + a(i, 2, "Called #3"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - a(i, 2, "Called B #2"); + a( + mfn(5, 8, function (err, res) { + a.deep( + [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], "Result C #1"); - a(i, 3, "Called C #1"); + a( + mfn(12, 4, function (err, res) { + a.deep( + [err, res], + [null, 16], + "Result C #1" + ); + a(i, 3, "Called C #1"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #4"); - a(i, 3, "Called #4"); + a( + mfn(3, 7, function ( + err, + res + ) { + a.deep( + [err, res], + [null, 10], + "Result #4" + ); + a(i, 3, "Called #4"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #3"); - a(i, 3, "Called B #3"); + a( + mfn(5, 8, function ( + err, + res + ) { + a.deep( + [err, res], + [null, 13], + "Result B #3" + ); + a( + i, + 3, + "Called B #3" + ); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], "Result D #1"); - a(i, 4, "Called D #1"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #1" + ); + a( + i, + 4, + "Called D #1" + ); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #4"); - a(i, 4, "Called B #4"); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 13 + ], + "Result B #4" + ); + a( + i, + 4, + "Called B #4" + ); - a(mfn(12, 4, function (err, res) { - a.deep([err, res], [null, 16], "Result C #2"); - a(i, 5, "Called C #2"); + a( + mfn( + 12, + 4, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 16 + ], + "Result C #2" + ); + a( + i, + 5, + "Called C #2" + ); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #5"); - a(i, 6, "Called #5"); + a( + mfn( + 3, + 7, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 10 + ], + "Result #5" + ); + a( + i, + 6, + "Called #5" + ); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], - "Result D #2"); - a(i, 7, "Called D #2"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #2" + ); + a( + i, + 7, + "Called D #2" + ); - a(mfn(12, 4, function (err, res) { - a.deep([err, res], [null, 16], - "Result C #3"); - a(i, 7, "Called C #3"); + a( + mfn( + 12, + 4, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 16 + ], + "Result C #3" + ); + a( + i, + 7, + "Called C #3" + ); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], - "Result B #5"); - a(i, 8, "Called B #5"); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 13 + ], + "Result B #5" + ); + a( + i, + 8, + "Called B #5" + ); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], - "Result D #3"); - a(i, 8, "Called D #3"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #3" + ); + a( + i, + 8, + "Called D #3" + ); - mfn.delete(77, 11); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], - "Result D #4"); - a(i, 9, "Called D #4"); + mfn.delete( + 77, + 11 + ); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #4" + ); + a( + i, + 9, + "Called D #4" + ); - mfn.clear(); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], - "Result B #6"); - a(i, 10, "Called B #6"); + mfn.clear(); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 13 + ], + "Result B #6" + ); + a( + i, + 10, + "Called B #6" + ); - a(mfn(77, 11, - function (err, res) { - a.deep([err, res], [null, 88], - "Result D #5"); - a(i, 11, "Called D #5"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #5" + ); + a( + i, + 11, + "Called D #5" + ); - d(); - }), u, "Initial D #5"); - }), u, "Initial B #6"); - }), u, "Initial D #4"); - }), u, "Initial D #3"); - }), u, "Initial B #5"); - }), u, "Initial C #3"); - }), u, "Initial D #2"); - }), u, "Initial #5"); - }), u, "Initial C #2"); - }), u, "Initial B #4"); - }), u, "Initial D #1"); - }), u, "Initial B #3"); - }), u, "Initial #4"); - }), u, "Initial C #1"); - }), u, "Initial B #2"); - }), u, "Initial #3"); - }), u, "Initial B #1"); - }), u, "Initial #2"); - }), u, "Initial #1"); + d(); + } + ), + u, + "Initial D #5" + ); + } + ), + u, + "Initial B #6" + ); + } + ), + u, + "Initial D #4" + ); + } + ), + u, + "Initial D #3" + ); + } + ), + u, + "Initial B #5" + ); + } + ), + u, + "Initial C #3" + ); + } + ), + u, + "Initial D #2" + ); + } + ), + u, + "Initial #5" + ); + } + ), + u, + "Initial C #2" + ); + } + ), + u, + "Initial B #4" + ); + } + ), + u, + "Initial D #1" + ); + }), + u, + "Initial B #3" + ); + }), + u, + "Initial #4" + ); + }), + u, + "Initial C #1" + ); + }), + u, + "Initial B #2" + ); + }), + u, + "Initial #3" + ); + }), + u, + "Initial B #1" + ); + }), + u, + "Initial #2" + ); + }), + u, + "Initial #1" + ); } }, Primitive: { Sync: function (a) { - var mfn, fn, i = 0; + var mfn, + fn, + i = 0; fn = function (x, y) { ++i; return x + y; @@ -1101,7 +1793,10 @@ module.exports = function (t, a) { 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; @@ -1112,125 +1807,459 @@ module.exports = function (t, a) { mfn = t(fn, { async: true, primitive: true, max: 3 }); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #1"); - a(i, 1, "Called #1"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #1"); + a(i, 1, "Called #1"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #2"); - a(i, 1, "Called #2"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #2"); + a(i, 1, "Called #2"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #1"); - a(i, 2, "Called B #1"); + a( + mfn(5, 8, function (err, res) { + a.deep([err, res], [null, 13], "Result B #1"); + a(i, 2, "Called B #1"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #3"); - a(i, 2, "Called #3"); + a( + mfn(3, 7, function (err, res) { + a.deep([err, res], [null, 10], "Result #3"); + a(i, 2, "Called #3"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #2"); - a(i, 2, "Called B #2"); + a( + mfn(5, 8, function (err, res) { + a.deep( + [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], "Result C #1"); - a(i, 3, "Called C #1"); + a( + mfn(12, 4, function (err, res) { + a.deep( + [err, res], + [null, 16], + "Result C #1" + ); + a(i, 3, "Called C #1"); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #4"); - a(i, 3, "Called #4"); + a( + mfn(3, 7, function ( + err, + res + ) { + a.deep( + [err, res], + [null, 10], + "Result #4" + ); + a(i, 3, "Called #4"); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #3"); - a(i, 3, "Called B #3"); + a( + mfn(5, 8, function ( + err, + res + ) { + a.deep( + [err, res], + [null, 13], + "Result B #3" + ); + a( + i, + 3, + "Called B #3" + ); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], "Result D #1"); - a(i, 4, "Called D #1"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #1" + ); + a( + i, + 4, + "Called D #1" + ); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], "Result B #4"); - a(i, 4, "Called B #4"); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 13 + ], + "Result B #4" + ); + a( + i, + 4, + "Called B #4" + ); - a(mfn(12, 4, function (err, res) { - a.deep([err, res], [null, 16], "Result C #2"); - a(i, 5, "Called C #2"); + a( + mfn( + 12, + 4, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 16 + ], + "Result C #2" + ); + a( + i, + 5, + "Called C #2" + ); - a(mfn(3, 7, function (err, res) { - a.deep([err, res], [null, 10], "Result #5"); - a(i, 6, "Called #5"); + a( + mfn( + 3, + 7, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 10 + ], + "Result #5" + ); + a( + i, + 6, + "Called #5" + ); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], - "Result D #2"); - a(i, 7, "Called D #2"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #2" + ); + a( + i, + 7, + "Called D #2" + ); - a(mfn(12, 4, function (err, res) { - a.deep([err, res], [null, 16], - "Result C #3"); - a(i, 7, "Called C #3"); + a( + mfn( + 12, + 4, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 16 + ], + "Result C #3" + ); + a( + i, + 7, + "Called C #3" + ); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], - "Result B #5"); - a(i, 8, "Called B #5"); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 13 + ], + "Result B #5" + ); + a( + i, + 8, + "Called B #5" + ); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], - "Result D #3"); - a(i, 8, "Called D #3"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #3" + ); + a( + i, + 8, + "Called D #3" + ); - mfn.delete(77, 11); - a(mfn(77, 11, function (err, res) { - a.deep([err, res], [null, 88], - "Result D #4"); - a(i, 9, "Called D #4"); + mfn.delete( + 77, + 11 + ); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #4" + ); + a( + i, + 9, + "Called D #4" + ); - mfn.clear(); - a(mfn(5, 8, function (err, res) { - a.deep([err, res], [null, 13], - "Result B #6"); - a(i, 10, "Called B #6"); + mfn.clear(); + a( + mfn( + 5, + 8, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 13 + ], + "Result B #6" + ); + a( + i, + 10, + "Called B #6" + ); - a(mfn(77, 11, - function (err, res) { - a.deep([err, res], [null, 88], - "Result D #5"); - a(i, 11, "Called D #5"); + a( + mfn( + 77, + 11, + function ( + err, + res + ) { + a.deep( + [ + err, + res + ], + [ + null, + 88 + ], + "Result D #5" + ); + a( + i, + 11, + "Called D #5" + ); - d(); - }), u, "Initial D #5"); - }), u, "Initial B #6"); - }), u, "Initial D #4"); - }), u, "Initial D #3"); - }), u, "Initial B #5"); - }), u, "Initial C #3"); - }), u, "Initial D #2"); - }), u, "Initial #5"); - }), u, "Initial C #2"); - }), u, "Initial B #4"); - }), u, "Initial D #1"); - }), u, "Initial B #3"); - }), u, "Initial #4"); - }), u, "Initial C #1"); - }), u, "Initial B #2"); - }), u, "Initial #3"); - }), u, "Initial B #1"); - }), u, "Initial #2"); - }), u, "Initial #1"); + d(); + } + ), + u, + "Initial D #5" + ); + } + ), + u, + "Initial B #6" + ); + } + ), + u, + "Initial D #4" + ); + } + ), + u, + "Initial D #3" + ); + } + ), + u, + "Initial B #5" + ); + } + ), + u, + "Initial C #3" + ); + } + ), + u, + "Initial D #2" + ); + } + ), + u, + "Initial #5" + ); + } + ), + u, + "Initial C #2" + ); + } + ), + u, + "Initial B #4" + ); + } + ), + u, + "Initial D #1" + ); + }), + u, + "Initial B #3" + ); + }), + u, + "Initial #4" + ); + }), + u, + "Initial C #1" + ); + }), + u, + "Initial B #2" + ); + }), + u, + "Initial #3" + ); + }), + u, + "Initial B #1" + ); + }), + u, + "Initial #2" + ); + }), + u, + "Initial #1" + ); } } }, "Dispose": { Regular: { "Sync": function (a) { - var mfn, fn, value = [], x, invoked; + var mfn, + fn, + value = [], + x, + invoked; fn = function (x, y) { - return x + y; -}; - mfn = t(fn, { dispose: function (val) { - value.push(val); -} }); + return x + y; + }; + mfn = t(fn, { + dispose: function (val) { + value.push(val); + } + }); mfn(3, 7); mfn(5, 8); @@ -1249,12 +2278,16 @@ module.exports = function (t, a) { x = {}; invoked = false; - mfn = t(function () { - return x; -}, - { dispose: function (val) { - invoked = val; -} }); + mfn = t( + function () { + return x; + }, + { + dispose: function (val) { + invoked = val; + } + } + ); mfn.delete(); a(invoked, false, "No args: Post invalid clear"); @@ -1264,14 +2297,18 @@ module.exports = function (t, a) { a(invoked, x, "No args: Pre clear"); }, "Ref counter": function (a) { - var mfn, fn, value = []; + var mfn, + fn, + value = []; fn = function (x, y) { - return x + y; -}; - mfn = t(fn, { refCounter: true, + return x + y; + }; + mfn = t(fn, { + refCounter: true, dispose: function (val) { - value.push(val); -} }); + value.push(val); + } + }); mfn(3, 7); mfn(5, 8); @@ -1292,18 +2329,23 @@ module.exports = function (t, a) { a.deep(value, [10, 88], "Clear all"); }, "Async": function (a, d) { - var mfn, fn, u = {}, value = []; + var mfn, + fn, + u = {}, + value = []; fn = function (x, y, cb) { nextTick(function () { - cb(null, x + y); -}); + cb(null, x + y); + }); return u; }; - mfn = t(fn, { async: true, + mfn = t(fn, { + async: true, dispose: function (val) { - value.push(val); -} }); + value.push(val); + } + }); mfn(3, 7, function () { mfn(5, 8, function () { @@ -1328,13 +2370,17 @@ module.exports = function (t, a) { }, Primitive: { "Sync": function (a) { - var mfn, fn, value = []; + var mfn, + fn, + value = []; fn = function (x, y) { - return x + y; -}; - mfn = t(fn, { dispose: function (val) { - value.push(val); -} }); + return x + y; + }; + mfn = t(fn, { + dispose: function (val) { + value.push(val); + } + }); mfn(3, 7); mfn(5, 8); @@ -1352,14 +2398,18 @@ module.exports = function (t, a) { a.deep(value, [10, 88], "Clear all"); }, "Ref counter": function (a) { - var mfn, fn, value = []; + var mfn, + fn, + value = []; fn = function (x, y) { - return x + y; -}; - mfn = t(fn, { refCounter: true, + return x + y; + }; + mfn = t(fn, { + refCounter: true, dispose: function (val) { - value.push(val); -} }); + value.push(val); + } + }); mfn(3, 7); mfn(5, 8); @@ -1380,18 +2430,23 @@ module.exports = function (t, a) { a.deep(value, [10, 88], "Clear all"); }, "Async": function (a, d) { - var mfn, fn, u = {}, value = []; + var mfn, + fn, + u = {}, + value = []; fn = function (x, y, cb) { nextTick(function () { - cb(null, x + y); -}); + cb(null, x + y); + }); return u; }; - mfn = t(fn, { async: true, + mfn = t(fn, { + async: true, dispose: function (val) { - value.push(val); -} }); + value.push(val); + } + }); mfn(3, 7, function () { mfn(5, 8, function () { diff --git a/test/lib/configure-map.js b/test/lib/configure-map.js index 85c64a3..689816e 100644 --- a/test/lib/configure-map.js +++ b/test/lib/configure-map.js @@ -1,3 +1,5 @@ +/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */ + "use strict"; var aFrom = require("es5-ext/array/from") @@ -6,39 +8,55 @@ var aFrom = require("es5-ext/array/from") module.exports = function () { return { "One arg": function (a) { - var i = 0, fn = function (x) { - ++i; return x; -}, mfn - , y = { toString: function () { - return "foo"; -} }; + var i = 0 + , fn = function (x) { + ++i; + return x; + } + , mfn + , y = { + toString: function () { + return "foo"; + } + }; mfn = memoize(fn, { primitive: true }); a(mfn(y), y, "#1"); a(mfn("foo"), y, "#2"); a(i, 1, "Called once"); }, "Clear cache": function (a) { - var i = 0, fn = function (x, y, z) { - ++i; return x + y + z; -}, mfn - , y = { toString: function () { - return "foo"; -} }; + var i = 0 + , fn = function (x, y, z) { + ++i; + return x + y + z; + } + , mfn + , y = { + toString: function () { + return "foo"; + } + }; mfn = memoize(fn, { primitive: true }); a(mfn(y, "bar", "zeta"), "foobarzeta", "#1"); a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2"); a(i, 1, "Called once"); - mfn.delete("foo", { toString: function () { - return "bar"; -} }, - "zeta"); + mfn.delete( + "foo", + { + toString: function () { + return "bar"; + } + }, + "zeta" + ); a(mfn(y, "bar", "zeta"), "foobarzeta", "#3"); a(i, 2, "Called twice"); }, "_get": function (a) { var fn = function (x) { - return x; -}, mfn; + return x; + } + , mfn; mfn = memoize(fn); a(mfn._get("foo"), undefined); mfn("foo"); @@ -46,8 +64,9 @@ module.exports = function () { }, "_has": function (a) { var fn = function (x) { - return x; -}, mfn; + return x; + } + , mfn; mfn = memoize(fn); a(mfn._has("foo"), false); mfn("foo"); @@ -72,10 +91,13 @@ module.exports = function () { }, "Resolvers": function () { var i = 0, fn, r; - fn = memoize(function () { - ++i; return arguments; -}, - { length: 3, resolvers: [Boolean, String] }); + fn = memoize( + function () { + ++i; + return arguments; + }, + { length: 3, resolvers: [Boolean, String] } + ); return { "No args": function (a) { i = 0; @@ -85,9 +107,13 @@ module.exports = function () { a(i, 1, "Called once"); }, "One arg": function (a) { - var fn = memoize(function (elo) { - ++i; return arguments; -}, { resolvers: [Boolean] }); + var fn = memoize( + function (elo) { + ++i; + return arguments; + }, + { resolvers: [Boolean] } + ); a.deep(aFrom(r = fn("elo")), [true], "First"); }, "Some Args": function (a) { @@ -99,8 +125,7 @@ module.exports = function () { a(i, 1, "Called once"); return { Other: function (a) { - a.deep(aFrom(r = fn(1, 34, x, 34)), - [true, "34", x, 34], "Second"); + a.deep(aFrom(r = fn(1, 34, x, 34)), [true, "34", x, 34], "Second"); a(fn(1, 34, x, 89), r, "Third"); a(i, 2, "Called once"); } diff --git a/test/lib/methods.js b/test/lib/methods.js index 883a61a..11d9ae5 100644 --- a/test/lib/methods.js +++ b/test/lib/methods.js @@ -1,3 +1,5 @@ +/* eslint id-length: 0 */ + "use strict"; var d = require("d") @@ -9,15 +11,23 @@ require("../ext/ref-counter"); module.exports = function (t, a) { var value = [], obj = {}; t = t(memoize); - Object.defineProperties(obj, t({ - someFn: d(function (x, y) { - a(this, obj); return x + y; -}, - { refCounter: true, - dispose: function (val) { - value.push(val); -} }) - })); + Object.defineProperties( + obj, + t({ + someFn: d( + function (x, y) { + a(this, obj); + return x + y; + }, + { + refCounter: true, + dispose: function (val) { + value.push(val); + } + } + ) + }) + ); obj = Object.create(obj); obj.someFn(3, 7); diff --git a/test/lib/resolve-normalize.js b/test/lib/resolve-normalize.js index 6dae67c..1a0058a 100644 --- a/test/lib/resolve-normalize.js +++ b/test/lib/resolve-normalize.js @@ -1,3 +1,5 @@ +/* eslint no-empty-function: 0 */ + "use strict"; module.exports = function (t, a) { diff --git a/test/lib/weak.js b/test/lib/weak.js index 400c750..a84acad 100644 --- a/test/lib/weak.js +++ b/test/lib/weak.js @@ -1,3 +1,5 @@ +/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */ + "use strict"; var memoize = require("../.."); @@ -8,13 +10,18 @@ require("../ext/ref-counter"); module.exports = function (t, a) { var value = [], obj = {}, memoized, count = 0, x, y, z; t = t(memoize); - memoized = t(function (arg, x, y) { - a(arg, obj); return x + y; -}, - { refCounter: true, -dispose: function (val) { - value.push(val); -} }); + memoized = t( + function (arg, x, y) { + a(arg, obj); + return x + y; + }, + { + refCounter: true, + dispose: function (val) { + value.push(val); + } + } + ); a(memoized(obj, 3, 7), 10); a(memoized(obj, 5, 8), 13); @@ -36,8 +43,8 @@ dispose: function (val) { y = {}; z = {}; memoized = t(function (arg) { - return ++count; -}); + return ++count; + }); a(memoized(x), 1); a(memoized(y), 2); a(memoized(x), 1); diff --git a/test/methods-plain.js b/test/methods-plain.js index a2e146e..a7f375c 100644 --- a/test/methods-plain.js +++ b/test/methods-plain.js @@ -1,3 +1,5 @@ +/* eslint id-length: 0 */ + "use strict"; var d = require("d"); @@ -7,15 +9,23 @@ require("../ext/ref-counter"); module.exports = function (t, a) { var value = [], obj = {}; - Object.defineProperties(obj, t({ - someFn: d(function (x, y) { - a(this, obj); return x + y; -}, - { refCounter: true, - dispose: function (val) { - value.push(val); -} }) - })); + Object.defineProperties( + obj, + t({ + someFn: d( + function (x, y) { + a(this, obj); + return x + y; + }, + { + refCounter: true, + dispose: function (val) { + value.push(val); + } + } + ) + }) + ); obj = Object.create(obj); obj.someFn(3, 7); diff --git a/test/methods.js b/test/methods.js index bf81ed4..acfd941 100644 --- a/test/methods.js +++ b/test/methods.js @@ -1,18 +1,28 @@ +/* eslint id-length: 0 */ + "use strict"; var d = require("d"); module.exports = function (t, a) { var value = [], obj = {}; - Object.defineProperties(obj, t({ - someFn: d(function (x, y) { - a(this, obj); return x + y; -}, - { refCounter: true, - dispose: function (val) { - value.push(val); -} }) - })); + Object.defineProperties( + obj, + t({ + someFn: d( + function (x, y) { + a(this, obj); + return x + y; + }, + { + refCounter: true, + dispose: function (val) { + value.push(val); + } + } + ) + }) + ); obj = Object.create(obj); obj.someFn(3, 7); diff --git a/test/normalizers/get-1.js b/test/normalizers/get-1.js index f930aed..e33efc3 100644 --- a/test/normalizers/get-1.js +++ b/test/normalizers/get-1.js @@ -1,12 +1,16 @@ +/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */ + "use strict"; var memoize = require("../.."); module.exports = { "": function (t, a) { - var i = 0, fn = function (x) { - ++i; return x; -}; + var i = 0 + , fn = function (x) { + ++i; + return x; + }; fn = memoize(fn); return { diff --git a/test/normalizers/get-fixed.js b/test/normalizers/get-fixed.js index 2b7353a..f26e17e 100644 --- a/test/normalizers/get-fixed.js +++ b/test/normalizers/get-fixed.js @@ -1,12 +1,17 @@ +/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */ + "use strict"; var memoize = require("../.."); module.exports = { "": function (a) { - var i = 0, fn = function (x, y, z) { - ++i; return [x, y, z]; -}, r; + var i = 0 + , fn = function (x, y, z) { + ++i; + return [x, y, z]; + } + , r; fn = memoize(fn); return { diff --git a/test/normalizers/get-primitive-fixed.js b/test/normalizers/get-primitive-fixed.js index cacca2d..e18d9cd 100644 --- a/test/normalizers/get-primitive-fixed.js +++ b/test/normalizers/get-primitive-fixed.js @@ -1,35 +1,52 @@ +/* eslint id-length: 0 */ + "use strict"; var memoize = require("../.."); module.exports = { "": function (a) { - var i = 0, fn = function (x, y, z) { - ++i; return x + y + z; -}, mfn - , y = { toString: function () { - return "foo"; -} }; + var i = 0 + , fn = function (x, y, z) { + ++i; + return x + y + z; + } + , mfn + , y = { + toString: function () { + return "foo"; + } + }; mfn = memoize(fn, { primitive: true }); a(mfn(y, "bar", "zeta"), "foobarzeta", "#1"); a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2"); a(i, 1, "Called once"); }, "Delete": function (a) { - var i = 0, fn = function (x, y, z) { - ++i; return x + y + z; -}, mfn - , y = { toString: function () { - return "foo"; -} }; + var i = 0 + , fn = function (x, y, z) { + ++i; + return x + y + z; + } + , mfn + , y = { + toString: function () { + return "foo"; + } + }; mfn = memoize(fn, { primitive: true }); a(mfn(y, "bar", "zeta"), "foobarzeta", "#1"); a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2"); a(i, 1, "Called once"); - mfn.delete("foo", { toString: function () { - return "bar"; -} }, - "zeta"); + mfn.delete( + "foo", + { + toString: function () { + return "bar"; + } + }, + "zeta" + ); a(mfn(y, "bar", "zeta"), "foobarzeta", "#3"); a(i, 2, "Called twice"); }, diff --git a/test/normalizers/get.js b/test/normalizers/get.js index c7e7eee..e4d512b 100644 --- a/test/normalizers/get.js +++ b/test/normalizers/get.js @@ -1,3 +1,5 @@ +/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */ + "use strict"; var aFrom = require("es5-ext/array/from") @@ -6,9 +8,12 @@ var aFrom = require("es5-ext/array/from") module.exports = function () { return { "": function (a) { - var i = 0, fn = function () { - ++i; return arguments; -}, r; + var i = 0 + , fn = function () { + ++i; + return arguments; + } + , r; fn = memoize(fn, { length: false }); return { diff --git a/test/normalizers/primitive.js b/test/normalizers/primitive.js index 49b667c..2873795 100644 --- a/test/normalizers/primitive.js +++ b/test/normalizers/primitive.js @@ -1,16 +1,22 @@ +/* eslint id-length: 0 */ + "use strict"; var memoize = require("../..") - - , join = Array.prototype.join; + , join = Array.prototype.join; module.exports = function (a) { - var i = 0, fn = function () { - ++i; return join.call(arguments, "|"); -} - , y = { toString: function () { - return "foo"; -} }, mfn; + var i = 0 + , fn = function () { + ++i; + return join.call(arguments, "|"); + } + , y = { + toString: function () { + return "foo"; + } + } + , mfn; mfn = memoize(fn, { primitive: true, length: false }); a(mfn(y, "bar", "zeta"), "foo|bar|zeta", "#1"); a(mfn("foo", "bar", "zeta"), "foo|bar|zeta", "#2"); diff --git a/test/plain.js b/test/plain.js index 43d3b4c..2f35012 100644 --- a/test/plain.js +++ b/test/plain.js @@ -1,14 +1,21 @@ +/* eslint id-length: 0 */ + "use strict"; module.exports = function (t) { return { "": function (a) { - var i = 0, fn = function (x) { - ++i; return x; -}, mfn - , y = { toString: function () { - return "foo"; -} }; + var i = 0 + , fn = function (x) { + ++i; + return x; + } + , mfn + , y = { + toString: function () { + return "foo"; + } + }; mfn = t(fn, { primitive: true }); a(typeof mfn, "function", "Returns"); a(mfn.__memoized__, true, "Marked"); @@ -18,20 +25,30 @@ module.exports = function (t) { a(i, 1, "Called once"); }, "Clear cache": function (a) { - var i = 0, fn = function (x, y, z) { - ++i; return x + y + z; -}, mfn - , y = { toString: function () { - return "foo"; -} }; + var i = 0 + , fn = function (x, y, z) { + ++i; + return x + y + z; + } + , mfn + , y = { + toString: function () { + return "foo"; + } + }; mfn = t(fn, { primitive: true }); a(mfn(y, "bar", "zeta"), "foobarzeta", "#1"); a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2"); a(i, 1, "Called once"); - mfn.delete("foo", { toString: function () { - return "bar"; -} }, - "zeta"); + mfn.delete( + "foo", + { + toString: function () { + return "bar"; + } + }, + "zeta" + ); a(mfn(y, "bar", "zeta"), "foobarzeta", "#3"); a(i, 2, "Called twice"); } diff --git a/test/profile.js b/test/profile.js index 4e248b0..120890a 100644 --- a/test/profile.js +++ b/test/profile.js @@ -1,3 +1,5 @@ +/* eslint no-empty-function: 0 */ + "use strict"; var memoize = require("../plain"); diff --git a/test/weak-plain.js b/test/weak-plain.js index 536b966..460d4c7 100644 --- a/test/weak-plain.js +++ b/test/weak-plain.js @@ -1,3 +1,5 @@ +/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */ + "use strict"; require("../ext/dispose"); @@ -5,13 +7,18 @@ require("../ext/ref-counter"); module.exports = function (t, a) { var value = [], obj = {}, memoized, count = 0, x, y, z; - memoized = t(function (arg, x, y) { - a(arg, obj); return x + y; -}, - { refCounter: true, -dispose: function (val) { - value.push(val); -} }); + memoized = t( + function (arg, x, y) { + a(arg, obj); + return x + y; + }, + { + refCounter: true, + dispose: function (val) { + value.push(val); + } + } + ); a(memoized(obj, 3, 7), 10); a(memoized(obj, 5, 8), 13); @@ -33,8 +40,8 @@ dispose: function (val) { y = {}; z = {}; memoized = t(function (arg) { - return ++count; -}); + return ++count; + }); a(memoized(x), 1); a(memoized(y), 2); a(memoized(x), 1); diff --git a/test/weak.js b/test/weak.js index 29ec04a..9170be7 100644 --- a/test/weak.js +++ b/test/weak.js @@ -1,14 +1,21 @@ +/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */ + "use strict"; module.exports = function (t, a, d) { var value = [], obj = {}, memoized, count = 0, x, y, z; - memoized = t(function (arg, x, y) { - a(arg, obj); return x + y; -}, - { refCounter: true, -dispose: function (val) { - value.push(val); -} }); + memoized = t( + function (arg, x, y) { + a(arg, obj); + return x + y; + }, + { + refCounter: true, + dispose: function (val) { + value.push(val); + } + } + ); a(memoized(obj, 3, 7), 10); a(memoized(obj, 5, 8), 13); @@ -30,8 +37,8 @@ dispose: function (val) { y = {}; z = {}; memoized = t(function (arg) { - return ++count; -}); + return ++count; + }); a(memoized(x), 1); a(memoized(y), 2); a(memoized(x), 1); @@ -39,9 +46,12 @@ dispose: function (val) { a(count, 3); count = 0; - memoized = t(function (arg) { - return ++count; -}, { maxAge: 1 }); + memoized = t( + function (arg) { + return ++count; + }, + { maxAge: 1 } + ); memoized(obj); setTimeout(function () {