refactor: update up to new lint rules

This commit is contained in:
Mariusz Nowak
2017-08-28 13:51:01 +02:00
parent d9db5f8ee3
commit 9b1d235a34
51 changed files with 751 additions and 508 deletions

View File

@@ -1,4 +1,4 @@
'use strict';
"use strict";
// Simple benchmark for very simple memoization case (fibonacci series)
// To run it, do following in memoizee package path:
@@ -6,13 +6,13 @@
// $ npm install underscore lodash lru-cache secondary-cache
// $ node benchmark/fibonacci.js
var forEach = require('es5-ext/object/for-each')
, pad = require('es5-ext/string/#/pad')
, memoizee = require('..')
, underscore = require('underscore').memoize
, lodash = require('lodash').memoize
, lruCache = require('lru-cache')
, lruSecondary = require('secondary-cache/lib/lru-cache')
var forEach = require("es5-ext/object/for-each")
, pad = require("es5-ext/string/#/pad")
, memoizee = require("..")
, underscore = require("underscore").memoize
, lodash = require("lodash").memoize
, lruCache = require("lru-cache")
, lruSecondary = require("secondary-cache/lib/lru-cache")
, now = Date.now
@@ -21,7 +21,7 @@ var forEach = require('es5-ext/object/for-each')
getFib = function (memoize, opts) {
var fib = memoize(function (x) {
return (x < 2) ? 1 : fib(x - 1) + fib(x - 2);
return x < 2 ? 1 : fib(x - 1) + fib(x - 2);
}, opts);
return fib;
};
@@ -29,7 +29,7 @@ getFib = function (memoize, opts) {
lru = function (x) {
var value = lruObj.get(x);
if (value === undefined) {
value = ((x < 2) ? 1 : lru(x - 1) + lru(x - 2));
value = x < 2 ? 1 : lru(x - 1) + lru(x - 2);
lruObj.set(x, value);
}
return value;
@@ -65,7 +65,7 @@ while (i--) {
memo(index);
total += now() - time;
}
data["Underscore"] = total;
data.Underscore = total;
total = 0;
i = count;
@@ -118,7 +118,7 @@ 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);
console.log(index + 1 + ":", pad.call(value, " ", 5) + "ms ", name);
}, null, function (a, b) {
return this[a] - this[b];
});

View File

@@ -1,18 +1,18 @@
// Support for asynchronous functions
'use strict';
"use strict";
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')
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")
, slice = Array.prototype.slice
, apply = Function.prototype.apply, create = Object.create
, hasOwnProperty = Object.prototype.hasOwnProperty;
require('../lib/registered-extensions').async = function (tbi, conf) {
require("../lib/registered-extensions").async = function (tbi, conf) {
var waiting = create(null), cache = create(null)
, base = conf.memoized, original = conf.original
, currentCallback, currentContext, currentArgs;
@@ -20,22 +20,24 @@ require('../lib/registered-extensions').async = function (tbi, conf) {
// Initial
conf.memoized = defineLength(function (arg) {
var args = arguments, last = args[args.length - 1];
if (typeof last === 'function') {
if (typeof last === "function") {
currentCallback = last;
args = slice.call(args, 0, -1);
}
return base.apply(currentContext = this, currentArgs = args);
}, base);
try { mixin(conf.memoized, base); } catch (ignore) {}
try {
mixin(conf.memoized, base);
} catch (ignore) {}
// From cache (sync)
conf.on('get', function (id) {
conf.on("get", function (id) {
var cb, context, args;
if (!currentCallback) return;
// Unresolved
if (waiting[id]) {
if (typeof waiting[id] === 'function') waiting[id] = [waiting[id], currentCallback];
if (typeof waiting[id] === "function") waiting[id] = [waiting[id], currentCallback];
else waiting[id].push(currentCallback);
currentCallback = null;
return;
@@ -50,7 +52,7 @@ require('../lib/registered-extensions').async = function (tbi, conf) {
var data;
if (hasOwnProperty.call(cache, id)) {
data = cache[id];
conf.emit('getasync', id, args, context);
conf.emit("getasync", id, args, context);
apply.call(cb, data.context, data.args);
} else {
// Purged in a meantime, we shouldn't rely on cached value, recall
@@ -67,7 +69,7 @@ require('../lib/registered-extensions').async = function (tbi, conf) {
var args, cb, origCb, result;
if (!currentCallback) return apply.call(original, this, arguments);
args = aFrom(arguments);
cb = function self(err) {
cb = function self (err) {
var cb, args, id = self.id;
if (id == null) {
// Shouldn't happen, means async callback was called sync way
@@ -88,13 +90,15 @@ require('../lib/registered-extensions').async = function (tbi, conf) {
conf.delete(id);
} else {
cache[id] = { context: this, args: args };
conf.emit('setasync', id, (typeof cb === 'function') ? 1 : cb.length);
conf.emit("setasync", id, typeof cb === "function" ? 1 : cb.length);
}
}
if (typeof cb === 'function') {
if (typeof cb === "function") {
result = apply.call(cb, this, args);
} else {
cb.forEach(function (cb) { result = apply.call(cb, this, args); }, this);
cb.forEach(function (cb) {
result = apply.call(cb, this, args);
}, this);
}
return result;
};
@@ -108,14 +112,14 @@ require('../lib/registered-extensions').async = function (tbi, conf) {
};
// After not from cache call
conf.on('set', function (id) {
conf.on("set", function (id) {
if (!currentCallback) {
conf.delete(id);
return;
}
if (waiting[id]) {
// Race condition: asyncFn(1, cb), asyncFn.clear(), asyncFn(1, cb)
if (typeof waiting[id] === 'function') waiting[id] = [waiting[id], currentCallback.cb];
if (typeof waiting[id] === "function") waiting[id] = [waiting[id], currentCallback.cb];
else waiting[id].push(currentCallback.cb);
} else {
waiting[id] = currentCallback.cb;
@@ -126,7 +130,7 @@ require('../lib/registered-extensions').async = function (tbi, conf) {
});
// On delete
conf.on('delete', function (id) {
conf.on("delete", function (id) {
var result;
// If false, we don't have value yet, so we assume that intention is not
// to memoize this call. After value is obtained we don't cache it but
@@ -135,14 +139,14 @@ require('../lib/registered-extensions').async = function (tbi, conf) {
if (!cache[id]) return;
result = cache[id];
delete cache[id];
conf.emit('deleteasync', id, slice.call(result.args, 1));
conf.emit("deleteasync", id, slice.call(result.args, 1));
});
// On clear
conf.on('clear', function () {
conf.on("clear", function () {
var oldCache = cache;
cache = create(null);
conf.emit('clearasync', objectMap(oldCache, function (data) {
conf.emit("clearasync", objectMap(oldCache, function (data) {
return slice.call(data.args, 1);
}));
});

View File

@@ -1,10 +1,10 @@
// Call dispose callback on each cache purge
'use strict';
"use strict";
var callable = require('es5-ext/object/valid-callable')
, forEach = require('es5-ext/object/for-each')
, extensions = require('../lib/registered-extensions')
var callable = require("es5-ext/object/valid-callable")
, forEach = require("es5-ext/object/for-each")
, extensions = require("../lib/registered-extensions")
, apply = Function.prototype.apply;
@@ -12,16 +12,22 @@ extensions.dispose = function (dispose, conf, options) {
var del;
callable(dispose);
if ((options.async && extensions.async) || (options.promise && extensions.promise)) {
conf.on('deleteasync', del = function (id, resultArray) {
conf.on("deleteasync", del = function (id, resultArray) {
apply.call(dispose, null, resultArray);
});
conf.on('clearasync', function (cache) {
forEach(cache, function (result, id) { del(id, result); });
conf.on("clearasync", function (cache) {
forEach(cache, function (result, id) {
del(id, result);
});
});
return;
}
conf.on('delete', del = function (id, result) { dispose(result); });
conf.on('clear', function (cache) {
forEach(cache, function (result, id) { del(id, result); });
conf.on("delete", del = function (id, result) {
dispose(result);
});
conf.on("clear", function (cache) {
forEach(cache, function (result, id) {
del(id, result);
});
});
};

View File

@@ -1,13 +1,13 @@
// Timeout cached values
'use strict';
"use strict";
var aFrom = require('es5-ext/array/from')
, forEach = require('es5-ext/object/for-each')
, nextTick = require('next-tick')
, isPromise = require('is-promise')
, timeout = require('timers-ext/valid-timeout')
, extensions = require('../lib/registered-extensions')
var aFrom = require("es5-ext/array/from")
, forEach = require("es5-ext/object/for-each")
, nextTick = require("next-tick")
, isPromise = require("is-promise")
, timeout = require("timers-ext/valid-timeout")
, extensions = require("../lib/registered-extensions")
, noop = Function.prototype
, max = Math.max, min = Math.min, create = Object.create;
@@ -19,23 +19,25 @@ extensions.maxAge = function (maxAge, conf, options) {
if (!maxAge) return;
timeouts = create(null);
postfix = ((options.async && extensions.async) || (options.promise && extensions.promise))
? 'async' : '';
conf.on('set' + postfix, function (id) {
timeouts[id] = setTimeout(function () { conf.delete(id); }, maxAge);
postfix = (options.async && extensions.async) || (options.promise && extensions.promise)
? "async" : "";
conf.on("set" + postfix, function (id) {
timeouts[id] = setTimeout(function () {
conf.delete(id);
}, maxAge);
if (!preFetchTimeouts) return;
if (preFetchTimeouts[id]) {
if (preFetchTimeouts[id] !== 'nextTick') clearTimeout(preFetchTimeouts[id]);
if (preFetchTimeouts[id] !== "nextTick") clearTimeout(preFetchTimeouts[id]);
}
preFetchTimeouts[id] = setTimeout(function () {
delete preFetchTimeouts[id];
}, preFetchAge);
});
conf.on('delete' + postfix, function (id) {
conf.on("delete" + postfix, function (id) {
clearTimeout(timeouts[id]);
delete timeouts[id];
if (!preFetchTimeouts) return;
if (preFetchTimeouts[id] !== 'nextTick') clearTimeout(preFetchTimeouts[id]);
if (preFetchTimeouts[id] !== "nextTick") clearTimeout(preFetchTimeouts[id]);
delete preFetchTimeouts[id];
});
@@ -48,12 +50,12 @@ extensions.maxAge = function (maxAge, conf, options) {
if (preFetchAge) {
preFetchTimeouts = {};
preFetchAge = (1 - preFetchAge) * maxAge;
conf.on('get' + postfix, function (id, args, context) {
conf.on("get" + postfix, function (id, args, context) {
if (!preFetchTimeouts[id]) {
preFetchTimeouts[id] = 'nextTick';
preFetchTimeouts[id] = "nextTick";
nextTick(function () {
var result;
if (preFetchTimeouts[id] !== 'nextTick') return;
if (preFetchTimeouts[id] !== "nextTick") return;
delete preFetchTimeouts[id];
conf.delete(id);
if (options.async) {
@@ -64,7 +66,7 @@ extensions.maxAge = function (maxAge, conf, options) {
if (options.promise) {
// Supress eventual error warnings
if (isPromise(result)) {
if (typeof result.done === 'function') result.done(noop, noop);
if (typeof result.done === "function") result.done(noop, noop);
else result.then(noop, noop);
}
}
@@ -74,12 +76,14 @@ extensions.maxAge = function (maxAge, conf, options) {
}
}
conf.on('clear' + postfix, function () {
forEach(timeouts, function (id) { clearTimeout(id); });
conf.on("clear" + postfix, function () {
forEach(timeouts, function (id) {
clearTimeout(id);
});
timeouts = {};
if (preFetchTimeouts) {
forEach(preFetchTimeouts, function (id) {
if (id !== 'nextTick') clearTimeout(id);
if (id !== "nextTick") clearTimeout(id);
});
preFetchTimeouts = {};
}

View File

@@ -1,10 +1,10 @@
// Limit cache size, LRU (least recently used) algorithm.
'use strict';
"use strict";
var toPosInteger = require('es5-ext/number/to-pos-integer')
, lruQueue = require('lru-queue')
, extensions = require('../lib/registered-extensions');
var toPosInteger = require("es5-ext/number/to-pos-integer")
, lruQueue = require("lru-queue")
, extensions = require("../lib/registered-extensions");
extensions.max = function (max, conf, options) {
var postfix, queue, hit;
@@ -13,15 +13,15 @@ extensions.max = function (max, conf, options) {
if (!max) return;
queue = lruQueue(max);
postfix = ((options.async && extensions.async) || (options.promise && extensions.promise))
? 'async' : '';
postfix = (options.async && extensions.async) || (options.promise && extensions.promise)
? "async" : "";
conf.on('set' + postfix, hit = function (id) {
conf.on("set" + postfix, hit = function (id) {
id = queue.hit(id);
if (id === undefined) return;
conf.delete(id);
});
conf.on('get' + postfix, hit);
conf.on('delete' + postfix, queue.delete);
conf.on('clear' + postfix, queue.clear);
conf.on("get" + postfix, hit);
conf.on("delete" + postfix, queue.delete);
conf.on("clear" + postfix, queue.clear);
};

View File

@@ -1,24 +1,24 @@
// Support for functions returning promise
'use strict';
"use strict";
var objectMap = require('es5-ext/object/map')
, isPromise = require('is-promise')
, nextTick = require('next-tick')
var objectMap = require("es5-ext/object/map")
, isPromise = require("is-promise")
, nextTick = require("next-tick")
, create = Object.create, hasOwnProperty = Object.prototype.hasOwnProperty;
require('../lib/registered-extensions').promise = function (mode, conf) {
require("../lib/registered-extensions").promise = function (mode, conf) {
var waiting = create(null), cache = create(null), promises = create(null);
// After not from cache call
conf.on('set', function (id, ignore, promise) {
conf.on("set", function (id, ignore, promise) {
var isFailed = false;
if (!isPromise(promise)) {
// Non promise result
cache[id] = promise;
conf.emit('setasync', id, 1);
conf.emit("setasync", id, 1);
return;
}
waiting[id] = 1;
@@ -31,22 +31,22 @@ require('../lib/registered-extensions').promise = function (mode, conf) {
"Instead of `promise: true` consider configuring memoization via `promise: 'then'` or " +
"`promise: 'done'");
}
if (!count) return; // deleted from cache before resolved
if (!count) return; // Deleted from cache before resolved
delete waiting[id];
cache[id] = result;
conf.emit('setasync', id, count);
conf.emit("setasync", id, count);
};
var onFailure = function () {
isFailed = true;
if (!waiting[id]) return; // deleted from cache (or succeed in case of finally)
if (!waiting[id]) return; // Deleted from cache (or succeed in case of finally)
delete waiting[id];
delete promises[id];
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)
@@ -69,24 +69,30 @@ require('../lib/registered-extensions').promise = function (mode, conf) {
});
// From cache (sync)
conf.on('get', function (id, args, context) {
conf.on("get", function (id, args, context) {
var promise;
if (waiting[id]) {
++waiting[id]; // Still waiting
return;
}
promise = promises[id];
var emit = function () { conf.emit('getasync', id, args, context); };
var emit = function () {
conf.emit("getasync", id, args, context);
};
if (isPromise(promise)) {
if (typeof promise.done === 'function') promise.done(emit);
else promise.then(function () { nextTick(emit); });
if (typeof promise.done === "function") promise.done(emit);
else {
promise.then(function () {
nextTick(emit);
});
}
} else {
emit();
}
});
// On delete
conf.on('delete', function (id) {
conf.on("delete", function (id) {
delete promises[id];
if (waiting[id]) {
delete waiting[id];
@@ -95,15 +101,17 @@ require('../lib/registered-extensions').promise = function (mode, conf) {
if (!hasOwnProperty.call(cache, id)) return;
var result = cache[id];
delete cache[id];
conf.emit('deleteasync', id, [result]);
conf.emit("deleteasync", id, [result]);
});
// On clear
conf.on('clear', function () {
conf.on("clear", function () {
var oldCache = cache;
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];
}));
});
};

View File

@@ -1,9 +1,9 @@
// Reference counter, useful for garbage collector like functionality
'use strict';
"use strict";
var d = require('d')
, extensions = require('../lib/registered-extensions')
var d = require("d")
, extensions = require("../lib/registered-extensions")
, create = Object.create, defineProperties = Object.defineProperties;
@@ -11,13 +11,21 @@ extensions.refCounter = function (ignore, conf, options) {
var cache, postfix;
cache = create(null);
postfix = ((options.async && extensions.async) || (options.promise && extensions.promise))
? 'async' : '';
postfix = (options.async && extensions.async) || (options.promise && extensions.promise)
? "async" : "";
conf.on('set' + postfix, function (id, length) { cache[id] = length || 1; });
conf.on('get' + postfix, function (id) { ++cache[id]; });
conf.on('delete' + postfix, function (id) { delete cache[id]; });
conf.on('clear' + postfix, function () { cache = {}; });
conf.on("set" + postfix, function (id, length) {
cache[id] = length || 1;
});
conf.on("get" + postfix, function (id) {
++cache[id];
});
conf.on("delete" + postfix, function (id) {
delete cache[id];
});
conf.on("clear" + postfix, function () {
cache = {};
});
defineProperties(conf.memoized, {
deleteRef: d(function () {

View File

@@ -1,8 +1,8 @@
'use strict';
"use strict";
var normalizeOpts = require('es5-ext/object/normalize-options')
, resolveLength = require('./lib/resolve-length')
, plain = require('./plain');
var normalizeOpts = require("es5-ext/object/normalize-options")
, resolveLength = require("./lib/resolve-length")
, plain = require("./plain");
module.exports = function (fn/*, options*/) {
var options = normalizeOpts(arguments[1]), length;
@@ -12,25 +12,23 @@ module.exports = function (fn/*, options*/) {
if (length !== 0) {
if (options.primitive) {
if (length === false) {
options.normalizer = require('./normalizers/primitive');
options.normalizer = require("./normalizers/primitive");
} else if (length > 1) {
options.normalizer = require('./normalizers/get-primitive-fixed')(length);
options.normalizer = require("./normalizers/get-primitive-fixed")(length);
}
} else {
if (length === false) options.normalizer = require('./normalizers/get')();
else if (length === 1) options.normalizer = require('./normalizers/get-1')();
else options.normalizer = require('./normalizers/get-fixed')(length);
}
} else if (length === false) options.normalizer = require("./normalizers/get")();
else if (length === 1) options.normalizer = require("./normalizers/get-1")();
else options.normalizer = require("./normalizers/get-fixed")(length);
}
}
// Assure extensions
if (options.async) require('./ext/async');
if (options.promise) require('./ext/promise');
if (options.dispose) require('./ext/dispose');
if (options.maxAge) require('./ext/max-age');
if (options.max) require('./ext/max');
if (options.refCounter) require('./ext/ref-counter');
if (options.async) require("./ext/async");
if (options.promise) require("./ext/promise");
if (options.dispose) require("./ext/dispose");
if (options.maxAge) require("./ext/max-age");
if (options.max) require("./ext/max");
if (options.refCounter) require("./ext/ref-counter");
return plain(fn, options);
};

View File

@@ -1,11 +1,11 @@
'use strict';
"use strict";
var customError = require('es5-ext/error/custom')
, defineLength = require('es5-ext/function/_define-length')
, d = require('d')
, ee = require('event-emitter').methods
, resolveResolve = require('./resolve-resolve')
, resolveNormalize = require('./resolve-normalize')
var customError = require("es5-ext/error/custom")
, defineLength = require("es5-ext/function/_define-length")
, d = require("d")
, ee = require("event-emitter").methods
, resolveResolve = require("./resolve-resolve")
, resolveNormalize = require("./resolve-normalize")
, apply = Function.prototype.apply, call = Function.prototype.call
, create = Object.create, hasOwnProperty = Object.prototype.hasOwnProperty
@@ -35,7 +35,7 @@ module.exports = function (original, length, options) {
id = get(args);
if (id !== null) {
if (hasOwnProperty.call(cache, id)) {
if (getListeners) conf.emit('get', id, args, this);
if (getListeners) conf.emit("get", id, args, this);
return cache[id];
}
}
@@ -43,29 +43,29 @@ module.exports = function (original, length, options) {
else result = apply.call(original, this, args);
if (id === null) {
id = get(args);
if (id !== null) throw customError("Circular invocation", 'CIRCULAR_INVOCATION');
if (id !== null) throw customError("Circular invocation", "CIRCULAR_INVOCATION");
id = set(args);
} else if (hasOwnProperty.call(cache, id)) {
throw customError("Circular invocation", 'CIRCULAR_INVOCATION');
throw customError("Circular invocation", "CIRCULAR_INVOCATION");
}
cache[id] = result;
if (setListeners) conf.emit('set', id, null, result);
if (setListeners) conf.emit("set", id, null, result);
return result;
}, memLength);
} else if (length === 0) {
memoized = function () {
var result;
if (hasOwnProperty.call(cache, 'data')) {
if (getListeners) conf.emit('get', 'data', arguments, this);
if (hasOwnProperty.call(cache, "data")) {
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 (hasOwnProperty.call(cache, 'data')) {
throw customError("Circular invocation", 'CIRCULAR_INVOCATION');
if (hasOwnProperty.call(cache, "data")) {
throw customError("Circular invocation", "CIRCULAR_INVOCATION");
}
cache.data = result;
if (setListeners) conf.emit('set', 'data', null, result);
if (setListeners) conf.emit("set", "data", null, result);
return result;
};
} else {
@@ -74,16 +74,16 @@ module.exports = function (original, length, options) {
if (resolve) args = resolve(arguments);
id = String(args[0]);
if (hasOwnProperty.call(cache, id)) {
if (getListeners) conf.emit('get', id, args, this);
if (getListeners) conf.emit("get", id, args, this);
return cache[id];
}
if (args.length === 1) result = call.call(original, this, args[0]);
else result = apply.call(original, this, args);
if (hasOwnProperty.call(cache, id)) {
throw customError("Circular invocation", 'CIRCULAR_INVOCATION');
throw customError("Circular invocation", "CIRCULAR_INVOCATION");
}
cache[id] = result;
if (setListeners) conf.emit('set', id, null, result);
if (setListeners) conf.emit("set", id, null, result);
return result;
};
}
@@ -96,29 +96,33 @@ module.exports = function (original, length, options) {
if (get) return get(args);
return String(args[0]);
},
has: function (id) { return hasOwnProperty.call(cache, id); },
has: function (id) {
return hasOwnProperty.call(cache, id);
},
delete: function (id) {
var result;
if (!hasOwnProperty.call(cache, id)) return;
if (del) del(id);
result = cache[id];
delete cache[id];
if (deleteListeners) conf.emit('delete', id, result);
if (deleteListeners) conf.emit("delete", id, result);
},
clear: function () {
var oldCache = cache;
if (clear) clear();
cache = create(null);
conf.emit('clear', oldCache);
conf.emit("clear", oldCache);
},
on: function (type, listener) {
if (type === 'get') getListeners = true;
else if (type === 'set') setListeners = true;
else if (type === 'delete') deleteListeners = true;
if (type === "get") getListeners = true;
else if (type === "set") setListeners = true;
else if (type === "delete") deleteListeners = true;
return on.call(this, type, listener);
},
emit: emit,
updateEnv: function () { original = conf.original; }
updateEnv: function () {
original = conf.original;
}
};
if (get) {
extDel = defineLength(function (arg) {
@@ -129,7 +133,9 @@ module.exports = function (original, length, options) {
conf.delete(id);
}, memLength);
} else if (length === 0) {
extDel = function () { return conf.delete('data'); };
extDel = function () {
return conf.delete("data");
};
} else {
extDel = function (arg) {
if (resolve) arg = resolve(arguments)[0];

View File

@@ -1,11 +1,11 @@
'use strict';
"use strict";
var forEach = require('es5-ext/object/for-each')
, normalizeOpts = require('es5-ext/object/normalize-options')
, callable = require('es5-ext/object/valid-callable')
, lazy = require('d/lazy')
, resolveLength = require('./resolve-length')
, extensions = require('./registered-extensions');
var forEach = require("es5-ext/object/for-each")
, normalizeOpts = require("es5-ext/object/normalize-options")
, callable = require("es5-ext/object/valid-callable")
, lazy = require("d/lazy")
, resolveLength = require("./resolve-length")
, extensions = require("./registered-extensions");
module.exports = function (memoize) {
return function (props) {

View File

@@ -1 +1 @@
'use strict';
"use strict";

View File

@@ -1,6 +1,6 @@
'use strict';
"use strict";
var toPosInt = require('es5-ext/number/to-pos-integer');
var toPosInt = require("es5-ext/number/to-pos-integer");
module.exports = function (optsLength, fnLength, isAsync) {
var length;

View File

@@ -1,10 +1,10 @@
'use strict';
"use strict";
var callable = require('es5-ext/object/valid-callable');
var callable = require("es5-ext/object/valid-callable");
module.exports = function (userNormalizer) {
var normalizer;
if (typeof userNormalizer === 'function') return { set: userNormalizer, get: userNormalizer };
if (typeof userNormalizer === "function") return { set: userNormalizer, get: userNormalizer };
normalizer = { get: callable(userNormalizer.get) };
if (userNormalizer.set !== undefined) {
normalizer.set = callable(userNormalizer.set);

View File

@@ -1,7 +1,7 @@
'use strict';
"use strict";
var toArray = require('es5-ext/array/to-array')
, callable = require('es5-ext/object/valid-callable')
var toArray = require("es5-ext/array/to-array")
, callable = require("es5-ext/object/valid-callable")
, slice = Array.prototype.slice
, resolveArgs;

View File

@@ -1,17 +1,17 @@
'use strict';
"use strict";
var customError = require('es5-ext/error/custom')
, defineLength = require('es5-ext/function/_define-length')
, partial = require('es5-ext/function/#/partial')
, copy = require('es5-ext/object/copy')
, normalizeOpts = require('es5-ext/object/normalize-options')
, callable = require('es5-ext/object/valid-callable')
, d = require('d')
, WeakMap = require('es6-weak-map')
, resolveLength = require('./resolve-length')
, extensions = require('./registered-extensions')
, resolveResolve = require('./resolve-resolve')
, resolveNormalize = require('./resolve-normalize')
var customError = require("es5-ext/error/custom")
, defineLength = require("es5-ext/function/_define-length")
, partial = require("es5-ext/function/#/partial")
, copy = require("es5-ext/object/copy")
, normalizeOpts = require("es5-ext/object/normalize-options")
, callable = require("es5-ext/object/valid-callable")
, d = require("d")
, WeakMap = require("es6-weak-map")
, resolveLength = require("./resolve-length")
, extensions = require("./registered-extensions")
, resolveResolve = require("./resolve-resolve")
, resolveNormalize = require("./resolve-normalize")
, slice = Array.prototype.slice, defineProperties = Object.defineProperties
, hasOwnProperty = Object.prototype.hasOwnProperty;
@@ -23,7 +23,7 @@ module.exports = function (memoize) {
callable(fn);
// Do not memoize already memoized function
if (hasOwnProperty.call(fn, '__memoized__') && !options.force) return fn;
if (hasOwnProperty.call(fn, "__memoized__") && !options.force) return fn;
length = resolveLength(options.length, fn.length, options.async && extensions.async);
options.length = length ? length - 1 : 0;
@@ -40,7 +40,7 @@ module.exports = function (memoize) {
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');
if (map.has(obj)) throw customError("Circular invocation", "CIRCULAR_INVOCATION");
map.set(obj, result);
return result;
}, {

View File

@@ -1,3 +1,3 @@
'use strict';
"use strict";
module.exports = require('./lib/methods')(require('./plain'));
module.exports = require("./lib/methods")(require("./plain"));

View File

@@ -1,3 +1,3 @@
'use strict';
"use strict";
module.exports = require('./lib/methods')(require('./'));
module.exports = require("./lib/methods")(require("./"));

View File

@@ -1,13 +1,13 @@
'use strict';
"use strict";
var indexOf = require('es5-ext/array/#/e-index-of');
var indexOf = require("es5-ext/array/#/e-index-of");
module.exports = function () {
var lastId = 0, argsMap = [], cache = [];
return {
get: function (args) {
var index = indexOf.call(argsMap, args[0]);
return (index === -1) ? null : cache[index];
return index === -1 ? null : cache[index];
},
set: function (args) {
argsMap.push(args[0]);

View File

@@ -1,6 +1,6 @@
'use strict';
"use strict";
var indexOf = require('es5-ext/array/#/e-index-of')
var indexOf = require("es5-ext/array/#/e-index-of")
, create = Object.create;
module.exports = function (length) {

View File

@@ -1,12 +1,16 @@
'use strict';
"use strict";
module.exports = function (length) {
if (!length) {
return function () { return ''; };
return function () {
return "";
};
}
return function (args) {
var id = String(args[0]), i = 0, l = length;
while (--l) { id += '\u0001' + args[++i]; }
while (--l) {
id += "\u0001" + args[++i];
}
return id;
};
};

View File

@@ -1,6 +1,6 @@
'use strict';
"use strict";
var indexOf = require('es5-ext/array/#/e-index-of')
var indexOf = require("es5-ext/array/#/e-index-of")
, create = Object.create;
module.exports = function () {

View File

@@ -1,9 +1,9 @@
'use strict';
"use strict";
module.exports = function (args) {
var id, i, length = args.length;
if (!length) return '\u0002';
if (!length) return "\u0002";
id = String(args[i = 0]);
while (--length) id += '\u0001' + args[++i];
while (--length) id += "\u0001" + args[++i];
return id;
};

View File

@@ -1,14 +1,14 @@
'use strict';
"use strict";
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')
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")
, hasOwnProperty = Object.prototype.hasOwnProperty;
module.exports = function self(fn/*, options */) {
module.exports = function self (fn/*, options */) {
var options, length, conf;
callable(fn);
@@ -19,7 +19,7 @@ module.exports = function self(fn/*, options */) {
}
// Do not memoize already memoized function
if (hasOwnProperty.call(fn, '__memoized__') && !options.force) return fn;
if (hasOwnProperty.call(fn, "__memoized__") && !options.force) return fn;
// Resolve length;
length = resolveLength(options.length, fn.length, options.async && extensions.async);

View File

@@ -1,36 +1,40 @@
// Gathers statistical data, and provides them in convinient form
'use strict';
"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 = {};
Object.defineProperty(memoize, '__profiler__', d(function (conf) {
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();
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';
source = "unknown";
}
id = compact.call([conf.profileName, source]).join(', ');
id = compact.call([conf.profileName, source]).join(", ");
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 () {
@@ -41,7 +45,7 @@ exports.log = function () {
toPrc = function (initial, cached) {
if (!initial && !cached) {
return '0.00';
return "0.00";
}
return ((cached / (initial + cached)) * 100).toFixed(2);
};

View File

@@ -1,11 +1,11 @@
'use strict';
"use strict";
var memoize = require('../..')
, nextTick = require('next-tick');
var memoize = require("../..")
, nextTick = require("next-tick");
module.exports = function () {
return {
Regular: {
"Regular": {
Success: function (a, d) {
var mfn, fn, u = {}, i = 0, invoked = 0;
fn = function (x, y, cb) {
@@ -120,8 +120,8 @@ module.exports = function () {
});
}
},
Primitive: {
Success: function (a, d) {
"Primitive": {
"Success": function (a, d) {
var mfn, fn, u = {}, i = 0;
fn = function (x, y, cb) {
nextTick(function () {
@@ -178,7 +178,7 @@ module.exports = function () {
});
});
},
Error: function (a, d) {
"Error": function (a, d) {
var mfn, fn, u = {}, i = 0, e = new Error("Test");
fn = function (x, y, cb) {
nextTick(function () {
@@ -223,7 +223,9 @@ module.exports = function () {
});
},
"Primitive null arg case": function (a, d) {
var x = {}, mfn = memoize(function f(id, cb) { cb(null, x); }, {
var x = {}, mfn = memoize(function f (id, cb) {
cb(null, x);
}, {
async: true,
primitive: true
});

View File

@@ -1,17 +1,21 @@
'use strict';
"use strict";
var memoize = require('../..')
, nextTick = require('next-tick')
, delay = require('timers-ext/delay')
, Promise = require('plain-promise');
var memoize = require("../..")
, nextTick = require("next-tick")
, delay = require("timers-ext/delay")
, Promise = require("plain-promise");
module.exports = function () {
return {
Regular: {
Sync: function (a) {
"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 (x, y) {
return x + y;
};
mfn = memoize(fn, { dispose: function (val) {
value.push(val);
} });
mfn(3, 7);
mfn(5, 8);
@@ -30,8 +34,12 @@ 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");
@@ -42,9 +50,13 @@ module.exports = function () {
},
"Ref counter": function (a) {
var mfn, fn, value = [];
fn = function (x, y) { return x + y; };
fn = function (x, y) {
return x + y;
};
mfn = memoize(fn, { refCounter: true,
dispose: function (val) { value.push(val); } });
dispose: function (val) {
value.push(val);
} });
mfn(3, 7);
mfn(5, 8);
@@ -64,15 +76,19 @@ module.exports = function () {
mfn.clear();
a.deep(value, [10, 88], "Clear all");
},
Async: function (a, d) {
"Async": function (a, d) {
var mfn, fn, u = {}, value = [];
fn = function (x, y, cb) {
nextTick(function () { cb(null, x + y); });
nextTick(function () {
cb(null, x + y);
});
return u;
};
mfn = memoize(fn, { async: true,
dispose: function (val) { value.push(val); } });
dispose: function (val) {
value.push(val);
} });
mfn(3, 7, function () {
mfn(5, 8, function () {
@@ -94,14 +110,18 @@ module.exports = function () {
});
});
},
Promise: function (a, d) {
"Promise": function (a, d) {
var mfn, fn, value = [];
fn = function (x, y) {
return new Promise(function (res) { res(x + y); });
return new Promise(function (res) {
res(x + y);
});
};
mfn = memoize(fn, { promise: true,
dispose: function (val) { value.push(val); } });
dispose: function (val) {
value.push(val);
} });
mfn(3, 7).done(function () {
mfn(5, 8).done(function () {
@@ -125,10 +145,14 @@ module.exports = function () {
}
},
Primitive: {
Sync: function (a) {
"Sync": function (a) {
var mfn, fn, value = [];
fn = function (x, y) { return x + y; };
mfn = memoize(fn, { dispose: function (val) { value.push(val); } });
fn = function (x, y) {
return x + y;
};
mfn = memoize(fn, { dispose: function (val) {
value.push(val);
} });
mfn(3, 7);
mfn(5, 8);
@@ -147,9 +171,13 @@ module.exports = function () {
},
"Ref counter": function (a) {
var mfn, fn, value = [];
fn = function (x, y) { return x + y; };
fn = function (x, y) {
return x + y;
};
mfn = memoize(fn, { refCounter: true,
dispose: function (val) { value.push(val); } });
dispose: function (val) {
value.push(val);
} });
mfn(3, 7);
mfn(5, 8);
@@ -169,15 +197,19 @@ module.exports = function () {
mfn.clear();
a.deep(value, [10, 88], "Clear all");
},
Async: function (a, d) {
"Async": function (a, d) {
var mfn, fn, u = {}, value = [];
fn = function (x, y, cb) {
nextTick(function () { cb(null, x + y); });
nextTick(function () {
cb(null, x + y);
});
return u;
};
mfn = memoize(fn, { async: true,
dispose: function (val) { value.push(val); } });
dispose: function (val) {
value.push(val);
} });
mfn(3, 7, function () {
mfn(5, 8, function () {
@@ -199,14 +231,18 @@ module.exports = function () {
});
});
},
Promise: function (a, d) {
"Promise": function (a, d) {
var mfn, fn, value = [];
fn = function (x, y) {
return new Promise(function (res) { res(x + y); });
return new Promise(function (res) {
res(x + y);
});
};
mfn = memoize(fn, { promise: true,
dispose: function (val) { value.push(val); } });
dispose: function (val) {
value.push(val);
} });
mfn(3, 7).done(function () {
mfn(5, 8).done(function () {

View File

@@ -1,12 +1,12 @@
'use strict';
"use strict";
var memoize = require('../..')
, nextTick = require('next-tick')
, delay = require('timers-ext/delay')
, Promise = require('plain-promise');
var memoize = require("../..")
, nextTick = require("next-tick")
, delay = require("timers-ext/delay")
, Promise = require("plain-promise");
require('../../ext/async');
require('../../ext/promise');
require("../../ext/async");
require("../../ext/promise");
module.exports = function () {
return {
@@ -380,7 +380,9 @@ module.exports = function () {
var mfn, fn, i = 0;
fn = function (x, y, cb) {
++i;
setTimeout(function () { cb(null, x + y); }, 0);
setTimeout(function () {
cb(null, x + y);
}, 0);
};
mfn = memoize(fn, { maxAge: 600, preFetch: true, async: true });
@@ -469,7 +471,9 @@ module.exports = function () {
var mfn, fn, i = 0;
fn = function (x, y) {
++i;
return new Promise(function (res) { res(x + y); });
return new Promise(function (res) {
res(x + y);
});
};
mfn = memoize(fn, { maxAge: 600, preFetch: true, promise: true });

View File

@@ -1,9 +1,9 @@
'use strict';
"use strict";
var memoize = require('../..')
, nextTick = require('next-tick')
, delay = require('timers-ext/delay')
, Promise = require('plain-promise');
var memoize = require("../..")
, nextTick = require("next-tick")
, delay = require("timers-ext/delay")
, Promise = require("plain-promise");
module.exports = function () {
return {
@@ -186,7 +186,9 @@ module.exports = function () {
var mfn, fn, i = 0;
fn = function (x, y) {
++i;
return new Promise(function (res) { res(x + y); });
return new Promise(function (res) {
res(x + y);
});
};
mfn = memoize(fn, { promise: true, max: 3 });
@@ -475,7 +477,9 @@ module.exports = function () {
var mfn, fn, i = 0;
fn = function (x, y) {
++i;
return new Promise(function (res) { res(x + y); });
return new Promise(function (res) {
res(x + y);
});
};
mfn = memoize(fn, { promise: true, primitive: true, max: 3 });

View File

@@ -1,12 +1,12 @@
'use strict';
"use strict";
var memoize = require('../..')
, nextTick = require('next-tick')
, Promise = require('plain-promise');
var memoize = require("../..")
, nextTick = require("next-tick")
, Promise = require("plain-promise");
module.exports = function () {
return {
Regular: {
"Regular": {
Success: function (a, d) {
var mfn, fn, i = 0, invoked = 0;
fn = function (x, y) {
@@ -90,7 +90,7 @@ module.exports = function () {
});
};
mfn = memoize(fn, { promise: 'done', dispose: a.never });
mfn = memoize(fn, { promise: "done", dispose: a.never });
mfn(3, 7).done(a.never, function (err) {
a(err, e, "Result #1");
@@ -101,7 +101,7 @@ module.exports = function () {
});
setTimeout(function () {
a(i, 2, 'Called #2');
a(i, 2, "Called #2");
mfn(3, 7).done(a.never, function (err) {
a(err, e, "Again: Result");
@@ -118,8 +118,8 @@ module.exports = function () {
}, 10);
}
},
Primitive: {
Success: function (a, d) {
"Primitive": {
"Success": function (a, d) {
var mfn, fn, i = 0;
fn = function (x, y) {
return new Promise(function (res) {
@@ -181,7 +181,7 @@ module.exports = function () {
}, 10);
}, 10);
},
Error: function (a, d) {
"Error": function (a, d) {
var mfn, fn, i = 0, e = new Error("Test");
fn = function (x, y) {
return new Promise(function (res, rej) {
@@ -190,7 +190,7 @@ module.exports = function () {
});
};
mfn = memoize(fn, { promise: 'done', primitive: true });
mfn = memoize(fn, { promise: "done", primitive: true });
mfn(3, 7).done(a.never, function (err) {
a(err, e, "Result #1");
@@ -201,7 +201,7 @@ module.exports = function () {
});
setTimeout(function () {
a(i, 2, 'Called #2');
a(i, 2, "Called #2");
mfn(3, 7).done(a.never, function (err) {
a(err, e, "Again: Result");
@@ -219,8 +219,10 @@ 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); });
mfn = memoize(function f (id) {
return new Promise(function (res) {
res(x);
});
}, {
promise: true,
primitive: true

View File

@@ -1,13 +1,15 @@
'use strict';
"use strict";
var memoize = require('../..')
, nextTick = require('next-tick')
, Promise = require('plain-promise');
var memoize = require("../..")
, nextTick = require("next-tick")
, Promise = require("plain-promise");
module.exports = function () {
return {
Regular: function (a) {
var i = 0, fn = function (x, y, z) { ++i; return x + y + z; }, mfn;
"Regular": function (a) {
var i = 0, fn = function (x, y, z) {
++i; return x + y + z;
}, mfn;
mfn = memoize(fn, { refCounter: true });
a(mfn.deleteRef(3, 5, 7), null, "Delete before");
a(mfn(3, 5, 7), 15, "Initial");
@@ -92,7 +94,9 @@ module.exports = function () {
var mfn, fn, i = 0;
fn = function (x, y) {
++i;
return new Promise(function (res) { res(x + y); });
return new Promise(function (res) {
res(x + y);
});
};
mfn = memoize(fn, { promise: true, refCounter: true });
@@ -147,8 +151,10 @@ module.exports = function () {
}, 10);
}, 10);
},
Primitive: function (a) {
var i = 0, fn = function (x, y, z) { ++i; return x + y + z; }, mfn;
"Primitive": function (a) {
var i = 0, fn = function (x, y, z) {
++i; return x + y + z;
}, mfn;
mfn = memoize(fn, { primitive: true, refCounter: true });
a(mfn.deleteRef(3, 5, 7), null, "Delete before");
a(mfn(3, 5, 7), 15, "Initial");
@@ -233,7 +239,9 @@ module.exports = function () {
var mfn, fn, i = 0;
fn = function (x, y) {
++i;
return new Promise(function (res) { res(x + y); });
return new Promise(function (res) {
res(x + y);
});
};
mfn = memoize(fn, { promise: true, primitive: true, refCounter: true });

View File

@@ -1,14 +1,16 @@
'use strict';
"use strict";
var aFrom = require('es5-ext/array/from')
, nextTick = require('next-tick')
var aFrom = require("es5-ext/array/from")
, nextTick = require("next-tick")
, 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");
@@ -17,7 +19,9 @@ 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 {
@@ -28,7 +32,7 @@ module.exports = function (t, a) {
a(fn(), undefined, "Third");
a(i, 1, "Called once");
},
Arg: function () {
"Arg": function () {
var x = {};
i = 0;
a(fn(x, 8), x, "First");
@@ -47,7 +51,9 @@ 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 {
@@ -91,18 +97,24 @@ 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]); } });
a(mfn(false, 'raz'), 'false|raz', "#1");
a(mfn(0, 'dwa'), 'false|raz', "#2");
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");
a(mfn(34, 'bar'), '34|bar', "#3");
a(mfn(34, "bar"), "34|bar", "#3");
a(i, 2, "Called twice");
a(mfn(true, 'ola'), '34|bar', "#4");
a(mfn(true, "ola"), "34|bar", "#4");
a(i, 2, "Called twice #2");
},
Dynamic: function () {
var i = 0, fn = function () { ++i; return arguments; }, r;
"Dynamic": function () {
var i = 0, fn = function () {
++i; return arguments;
}, r;
fn = t(fn, { length: false });
return {
@@ -131,14 +143,16 @@ module.exports = function (t, a) {
}
};
},
Resolvers: function () {
"Resolvers": function () {
var i = 0, fn, r;
fn = t(function () { ++i; return arguments; },
fn = t(function () {
++i; return arguments;
},
{ length: 3, resolvers: [Boolean, String] });
return {
"No args": function () {
i = 0;
a.deep(aFrom(r = fn()), [false, 'undefined'], "First");
a.deep(aFrom(r = fn()), [false, "undefined"], "First");
a(fn(), r, "Second");
a(fn(), r, "Third");
a(i, 1, "Called once");
@@ -146,7 +160,7 @@ 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],
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");
@@ -154,7 +168,7 @@ module.exports = function (t, a) {
return {
Other: function () {
a.deep(aFrom(r = fn(1, 34, x, 34)),
[true, '34', x, 34], "Second");
[true, "34", x, 34], "Second");
a(fn(1, 34, x, 89), r, "Third");
a(i, 2, "Called once");
}
@@ -216,46 +230,64 @@ module.exports = function (t, a) {
a(i, 4, "After clear");
}
},
Primitive: {
"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(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(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(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(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
a(i, 1, "Called once");
mfn.delete('foo', { toString: function () { return 'bar'; } },
'zeta');
a(mfn(y, 'bar', 'zeta'), 'foobarzeta', "#3");
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");
@@ -275,7 +307,9 @@ 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");
@@ -295,9 +329,9 @@ module.exports = function (t, a) {
a(i, 2, "Cached again");
}
},
Async: {
"Async": {
Regular: {
Success: function (a, d) {
"Success": function (a, d) {
var mfn, fn, u = {}, i = 0, invoked = 0;
fn = function (x, y, cb) {
nextTick(function () {
@@ -428,7 +462,7 @@ module.exports = function (t, a) {
});
});
},
Error: function (a, d) {
"Error": function (a, d) {
var mfn, fn, u = {}, i = 0, e = new Error("Test");
fn = function (x, y, cb) {
nextTick(function () {
@@ -474,7 +508,7 @@ module.exports = function (t, a) {
}
},
Primitive: {
Success: function (a, d) {
"Success": function (a, d) {
var mfn, fn, u = {}, i = 0;
fn = function (x, y, cb) {
nextTick(function () {
@@ -593,7 +627,7 @@ module.exports = function (t, a) {
});
});
},
Error: function (a, d) {
"Error": function (a, d) {
var mfn, fn, u = {}, i = 0, e = new Error("Test");
fn = function (x, y, cb) {
nextTick(function () {
@@ -639,7 +673,7 @@ module.exports = function (t, a) {
}
}
},
MaxAge: {
"MaxAge": {
Regular: {
Sync: function (a, d) {
var mfn, fn, i = 0;
@@ -833,7 +867,7 @@ module.exports = function (t, a) {
}
}
},
Max: {
"Max": {
Regular: {
Sync: function (a) {
var mfn, fn, i = 0;
@@ -1187,12 +1221,16 @@ module.exports = function (t, a) {
}
}
},
Dispose: {
"Dispose": {
Regular: {
Sync: function (a) {
"Sync": function (a) {
var mfn, fn, value = [], x, invoked;
fn = function (x, y) { return x + y; };
mfn = t(fn, { dispose: function (val) { value.push(val); } });
fn = function (x, y) {
return x + y;
};
mfn = t(fn, { dispose: function (val) {
value.push(val);
} });
mfn(3, 7);
mfn(5, 8);
@@ -1211,8 +1249,12 @@ 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");
@@ -1223,9 +1265,13 @@ module.exports = function (t, a) {
},
"Ref counter": function (a) {
var mfn, fn, value = [];
fn = function (x, y) { return x + y; };
fn = function (x, y) {
return x + y;
};
mfn = t(fn, { refCounter: true,
dispose: function (val) { value.push(val); } });
dispose: function (val) {
value.push(val);
} });
mfn(3, 7);
mfn(5, 8);
@@ -1245,15 +1291,19 @@ module.exports = function (t, a) {
mfn.clear();
a.deep(value, [10, 88], "Clear all");
},
Async: function (a, d) {
"Async": function (a, d) {
var mfn, fn, u = {}, value = [];
fn = function (x, y, cb) {
nextTick(function () { cb(null, x + y); });
nextTick(function () {
cb(null, x + y);
});
return u;
};
mfn = t(fn, { async: true,
dispose: function (val) { value.push(val); } });
dispose: function (val) {
value.push(val);
} });
mfn(3, 7, function () {
mfn(5, 8, function () {
@@ -1277,10 +1327,14 @@ module.exports = function (t, a) {
}
},
Primitive: {
Sync: function (a) {
"Sync": function (a) {
var mfn, fn, value = [];
fn = function (x, y) { return x + y; };
mfn = t(fn, { dispose: function (val) { value.push(val); } });
fn = function (x, y) {
return x + y;
};
mfn = t(fn, { dispose: function (val) {
value.push(val);
} });
mfn(3, 7);
mfn(5, 8);
@@ -1299,9 +1353,13 @@ module.exports = function (t, a) {
},
"Ref counter": function (a) {
var mfn, fn, value = [];
fn = function (x, y) { return x + y; };
fn = function (x, y) {
return x + y;
};
mfn = t(fn, { refCounter: true,
dispose: function (val) { value.push(val); } });
dispose: function (val) {
value.push(val);
} });
mfn(3, 7);
mfn(5, 8);
@@ -1321,15 +1379,19 @@ module.exports = function (t, a) {
mfn.clear();
a.deep(value, [10, 88], "Clear all");
},
Async: function (a, d) {
"Async": function (a, d) {
var mfn, fn, u = {}, value = [];
fn = function (x, y, cb) {
nextTick(function () { cb(null, x + y); });
nextTick(function () {
cb(null, x + y);
});
return u;
};
mfn = t(fn, { async: true,
dispose: function (val) { value.push(val); } });
dispose: function (val) {
value.push(val);
} });
mfn(3, 7, function () {
mfn(5, 8, function () {

View File

@@ -1,88 +1,106 @@
'use strict';
"use strict";
var aFrom = require('es5-ext/array/from')
, memoize = require('../..');
var aFrom = require("es5-ext/array/from")
, memoize = require("../..");
module.exports = function () {
return {
"One arg": function (a) {
var i = 0, fn = function (x) { ++i; return x; }, mfn
, y = { toString: function () { return 'foo'; } };
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(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(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
a(i, 1, "Called once");
mfn.delete('foo', { toString: function () { return 'bar'; } },
'zeta');
a(mfn(y, 'bar', 'zeta'), 'foobarzeta', "#3");
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;
"_get": function (a) {
var fn = function (x) {
return x;
}, mfn;
mfn = memoize(fn);
a(mfn._get('foo'), undefined);
mfn('foo');
a(mfn._get('foo'), 'foo');
a(mfn._get("foo"), undefined);
mfn("foo");
a(mfn._get("foo"), "foo");
},
_has: function (a) {
var fn = function (x) { return x; }, mfn;
"_has": function (a) {
var fn = function (x) {
return x;
}, mfn;
mfn = memoize(fn);
a(mfn._has('foo'), false);
mfn('foo');
a(mfn._has('foo'), true);
a(mfn._has("foo"), false);
mfn("foo");
a(mfn._has("foo"), true);
},
Circular: function (a) {
"Circular": function (a) {
var i = 0, fn;
fn = memoize(function (x) {
if (++i < 2) fn(x);
});
a.throws(function () {
fn('foo');
}, 'CIRCULAR_INVOCATION');
fn("foo");
}, "CIRCULAR_INVOCATION");
i = 0;
fn = memoize(function (x, y) {
if (++i < 2) fn(x, y);
});
a.throws(function () {
fn('foo', 'bar');
}, 'CIRCULAR_INVOCATION');
fn("foo", "bar");
}, "CIRCULAR_INVOCATION");
},
Resolvers: function () {
"Resolvers": function () {
var i = 0, fn, r;
fn = memoize(function () { ++i; return arguments; },
fn = memoize(function () {
++i; return arguments;
},
{ length: 3, resolvers: [Boolean, String] });
return {
"No args": function (a) {
i = 0;
a.deep(aFrom(r = fn()), [false, 'undefined'], "First");
a.deep(aFrom(r = fn()), [false, "undefined"], "First");
a(fn(), r, "Second");
a(fn(), r, "Third");
a(i, 1, "Called once");
},
"One arg": function (a) {
var fn = memoize(function (elo) { ++i; return arguments; }, { resolvers: [Boolean] });
a.deep(aFrom(r = fn('elo')), [true], "First");
var fn = memoize(function (elo) {
++i; return arguments;
}, { resolvers: [Boolean] });
a.deep(aFrom(r = fn("elo")), [true], "First");
},
"Some Args": function (a) {
var x = {};
i = 0;
a.deep(aFrom(r = fn(0, 34, x, 45)), [false, '34', x, 45], "First");
a.deep(aFrom(r = fn(0, 34, x, 45)), [false, "34", x, 45], "First");
a(fn(0, 34, x, 22), r, "Second");
a(fn(0, 34, x, false), r, "Third");
a(i, 1, "Called once");
return {
Other: function (a) {
a.deep(aFrom(r = fn(1, 34, x, 34)),
[true, '34', x, 34], "Second");
[true, "34", x, 34], "Second");
a(fn(1, 34, x, 89), r, "Third");
a(i, 2, "Called once");
}

View File

@@ -1,18 +1,22 @@
'use strict';
"use strict";
var d = require('d')
, memoize = require('../..');
var d = require("d")
, memoize = require("../..");
require('../ext/dispose');
require('../ext/ref-counter');
require("../ext/dispose");
require("../ext/ref-counter");
module.exports = function (t, a) {
var value = [], obj = {};
t = t(memoize);
Object.defineProperties(obj, t({
someFn: d(function (x, y) { a(this, obj); return x + y; },
someFn: d(function (x, y) {
a(this, obj); return x + y;
},
{ refCounter: true,
dispose: function (val) { value.push(val); } })
dispose: function (val) {
value.push(val);
} })
}));
obj = Object.create(obj);

View File

@@ -1,6 +1,6 @@
'use strict';
"use strict";
module.exports = function (t, a) {
require('../../ext/async');
a(typeof t.async, 'function');
require("../../ext/async");
a(typeof t.async, "function");
};

View File

@@ -1,4 +1,4 @@
'use strict';
"use strict";
module.exports = function (t, a) {
a(t(1, 2), 1, "Options");

View File

@@ -1,4 +1,4 @@
'use strict';
"use strict";
module.exports = function (t, a) {
var fn = function () {}, resolved = t(fn);

View File

@@ -1,5 +1,5 @@
'use strict';
"use strict";
module.exports = function (t, a) {
a.deep(t([String, null, Number])([23, 'foo', '45', 'elo']), ['23', 'foo', 45, 'elo']);
a.deep(t([String, null, Number])([23, "foo", "45", "elo"]), ["23", "foo", 45, "elo"]);
};

View File

@@ -1,15 +1,20 @@
'use strict';
"use strict";
var memoize = require('../..');
var memoize = require("../..");
require('../ext/dispose');
require('../ext/ref-counter');
require("../ext/dispose");
require("../ext/ref-counter");
module.exports = function (t, a) {
var value = [], obj = {}, memoized, count = 0, x, y, z;
t = t(memoize);
memoized = t(function (arg, x, y) { a(arg, obj); return x + y; },
{ refCounter: true, dispose: function (val) { value.push(val); } });
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,7 +35,9 @@ module.exports = function (t, a) {
x = {};
y = {};
z = {};
memoized = t(function (arg) { return ++count; });
memoized = t(function (arg) {
return ++count;
});
a(memoized(x), 1);
a(memoized(y), 2);
a(memoized(x), 1);

View File

@@ -1,16 +1,20 @@
'use strict';
"use strict";
var d = require('d');
var d = require("d");
require('../ext/dispose');
require('../ext/ref-counter');
require("../ext/dispose");
require("../ext/ref-counter");
module.exports = function (t, a) {
var value = [], obj = {};
Object.defineProperties(obj, t({
someFn: d(function (x, y) { a(this, obj); return x + y; },
someFn: d(function (x, y) {
a(this, obj); return x + y;
},
{ refCounter: true,
dispose: function (val) { value.push(val); } })
dispose: function (val) {
value.push(val);
} })
}));
obj = Object.create(obj);

View File

@@ -1,13 +1,17 @@
'use strict';
"use strict";
var d = require('d');
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; },
someFn: d(function (x, y) {
a(this, obj); return x + y;
},
{ refCounter: true,
dispose: function (val) { value.push(val); } })
dispose: function (val) {
value.push(val);
} })
}));
obj = Object.create(obj);

View File

@@ -1,10 +1,12 @@
'use strict';
"use strict";
var memoize = require('../..');
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 {
@@ -15,7 +17,7 @@ module.exports = {
a(fn(), undefined, "Third");
a(i, 1, "Called once");
},
Arg: function () {
"Arg": function () {
var x = {};
i = 0;
a(fn(x, 8), x, "First");
@@ -33,11 +35,11 @@ module.exports = {
}
};
},
Delete: function (a) {
"Delete": function (a) {
var i = 0, fn, mfn, x = {};
fn = function (a, b, c) {
return a + (++i);
return a + ++i;
};
mfn = memoize(fn, { length: 1 });
a(mfn(3), 4, "Init");

View File

@@ -1,10 +1,12 @@
'use strict';
"use strict";
var memoize = require('../..');
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 {
@@ -47,11 +49,11 @@ module.exports = {
}
};
},
Delete: function (a) {
"Delete": function (a) {
var i = 0, fn, mfn, x = {};
fn = function (a, b, c) {
return a + (++i);
return a + ++i;
};
mfn = memoize(fn);
a(mfn(3, x, 1), 4, "Init");
@@ -67,7 +69,7 @@ module.exports = {
a(mfn(3, x, 1), 6, "Reinit Cached");
a(i, 3, "Reinit count");
},
Clear: function (a) {
"Clear": function (a) {
var i = 0, fn, x = {};
fn = function () {

View File

@@ -1,43 +1,53 @@
'use strict';
"use strict";
var memoize = require('../..');
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(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'; } };
"Delete": function (a) {
var i = 0, fn = function (x, y, z) {
++i; return x + y + z;
}, mfn
, y = { toString: function () {
return "foo";
} };
mfn = memoize(fn, { primitive: true });
a(mfn(y, 'bar', 'zeta'), 'foobarzeta', "#1");
a(mfn('foo', 'bar', 'zeta'), 'foobarzeta', "#2");
a(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
a(i, 1, "Called once");
mfn.delete('foo', { toString: function () { return 'bar'; } },
'zeta');
a(mfn(y, 'bar', 'zeta'), 'foobarzeta', "#3");
mfn.delete("foo", { toString: function () {
return "bar";
} },
"zeta");
a(mfn(y, "bar", "zeta"), "foobarzeta", "#3");
a(i, 2, "Called twice");
},
Clear: function (a) {
"Clear": function (a) {
var i = 0, fn;
fn = memoize(function (x) {
if (++i < 2) fn(x);
});
a.throws(function () {
fn('foo');
}, 'CIRCULAR_INVOCATION');
fn("foo");
}, "CIRCULAR_INVOCATION");
i = 0;
fn = memoize(function (x, y) {
if (++i < 2) fn(x, y);
});
a.throws(function () {
fn('foo', 'bar');
}, 'CIRCULAR_INVOCATION');
fn("foo", "bar");
}, "CIRCULAR_INVOCATION");
}
};

View File

@@ -1,12 +1,14 @@
'use strict';
"use strict";
var aFrom = require('es5-ext/array/from')
, memoize = require('../..');
var aFrom = require("es5-ext/array/from")
, memoize = require("../..");
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 {
@@ -35,11 +37,11 @@ module.exports = function () {
}
};
},
Delete: function (a) {
"Delete": function (a) {
var i = 0, fn, mfn, x = {};
fn = function (a, b, c) {
return a + (++i);
return a + ++i;
};
mfn = memoize(fn, { length: false });
a(mfn(3, x, 1), 4, "Init");

View File

@@ -1,18 +1,22 @@
'use strict';
"use strict";
var memoize = require('../..')
var memoize = require("../..")
, join = Array.prototype.join;
module.exports = function (a) {
var i = 0, fn = function () { ++i; return join.call(arguments, '|'); }
, y = { toString: function () { return 'foo'; } }, mfn;
var i = 0, fn = function () {
++i; return join.call(arguments, "|");
}
, y = { toString: function () {
return "foo";
} }, mfn;
mfn = memoize(fn, { primitive: true, length: false });
a(mfn(y, 'bar', 'zeta'), 'foo|bar|zeta', "#1");
a(mfn('foo', 'bar', 'zeta'), 'foo|bar|zeta', "#2");
a(mfn(y, "bar", "zeta"), "foo|bar|zeta", "#1");
a(mfn("foo", "bar", "zeta"), "foo|bar|zeta", "#2");
a(i, 1, "Called once");
a(mfn(y, 'bar'), 'foo|bar', "#3");
a(mfn(y, "bar"), "foo|bar", "#3");
a(i, 2, "Called twice");
a(mfn(y, 'bar'), 'foo|bar', "#4");
a(mfn(y, "bar"), "foo|bar", "#4");
a(i, 2, "Called twice #2");
};

View File

@@ -1,28 +1,38 @@
'use strict';
"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(typeof mfn, "function", "Returns");
a(mfn.__memoized__, true, "Marked");
a(t(mfn), mfn, "Do not memoize memoized");
a(mfn(y), y, "#1");
a(mfn('foo'), y, "#2");
a(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 = t(fn, { primitive: true });
a(mfn(y, 'bar', 'zeta'), 'foobarzeta', "#1");
a(mfn('foo', 'bar', 'zeta'), 'foobarzeta', "#2");
a(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
a(i, 1, "Called once");
mfn.delete('foo', { toString: function () { return 'bar'; } },
'zeta');
a(mfn(y, 'bar', 'zeta'), 'foobarzeta', "#3");
mfn.delete("foo", { toString: function () {
return "bar";
} },
"zeta");
a(mfn(y, "bar", "zeta"), "foobarzeta", "#3");
a(i, 2, "Called twice");
}
};

View File

@@ -1,12 +1,12 @@
'use strict';
"use strict";
var memoize = require('../plain');
var memoize = require("../plain");
module.exports = function (t, a) {
memoize(function () {})();
memoize(function () {}, { profileName: 'test' })();
a(typeof t.statistics, 'object', "Access to statistics");
memoize(function () {}, { profileName: "test" })();
a(typeof t.statistics, "object", "Access to statistics");
a(Object.keys(t.statistics).length, 2, "Statistics collected including named function");
a(typeof t.log, 'function', "Access to log function");
a(typeof t.log(), 'string', "Log outputs string");
a(typeof t.log, "function", "Access to log function");
a(typeof t.log(), "string", "Log outputs string");
};

View File

@@ -1,12 +1,17 @@
'use strict';
"use strict";
require('../ext/dispose');
require('../ext/ref-counter');
require("../ext/dispose");
require("../ext/ref-counter");
module.exports = function (t, a) {
var value = [], obj = {}, memoized, count = 0, x, y, z;
memoized = t(function (arg, x, y) { a(arg, obj); return x + y; },
{ refCounter: true, dispose: function (val) { value.push(val); } });
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);
@@ -27,7 +32,9 @@ module.exports = function (t, a) {
x = {};
y = {};
z = {};
memoized = t(function (arg) { return ++count; });
memoized = t(function (arg) {
return ++count;
});
a(memoized(x), 1);
a(memoized(y), 2);
a(memoized(x), 1);

View File

@@ -1,9 +1,14 @@
'use strict';
"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);
@@ -24,7 +29,9 @@ module.exports = function (t, a, d) {
x = {};
y = {};
z = {};
memoized = t(function (arg) { return ++count; });
memoized = t(function (arg) {
return ++count;
});
a(memoized(x), 1);
a(memoized(y), 2);
a(memoized(x), 1);
@@ -32,7 +39,9 @@ module.exports = function (t, a, d) {
a(count, 3);
count = 0;
memoized = t(function (arg) { return ++count; }, { maxAge: 1 });
memoized = t(function (arg) {
return ++count;
}, { maxAge: 1 });
memoized(obj);
setTimeout(function () {

View File

@@ -1,3 +1,3 @@
'use strict';
"use strict";
module.exports = require('./lib/weak')(require('./plain'));
module.exports = require("./lib/weak")(require("./plain"));

View File

@@ -1,3 +1,3 @@
'use strict';
"use strict";
module.exports = require('./lib/weak')(require('./'));
module.exports = require("./lib/weak")(require("./"));