From 2b4cf268c8ad9da891c2db55477db0004e4bef79 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 22 Jul 2013 19:34:28 +0200 Subject: [PATCH 1/4] Fix primitive handling for dynamic length --- lib/primitive.js | 4 ++-- test/primitive.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/primitive.js b/lib/primitive.js index 0f0ef0d..aeb87f7 100644 --- a/lib/primitive.js +++ b/lib/primitive.js @@ -17,8 +17,8 @@ module.exports = require('./_base')(function (conf, length) { if (length === 1) { get = conf.get = getId1; } else if (length === false) { - get = conf.get = function (args, length) { - var id = '', i; + get = conf.get = function (args) { + var id = '', i, length = args.length; if (length) { id += args[i = 0]; while (--length) { diff --git a/test/primitive.js b/test/primitive.js index 557d396..375abc4 100644 --- a/test/primitive.js +++ b/test/primitive.js @@ -1,5 +1,7 @@ 'use strict'; +var join = Array.prototype.join; + module.exports = function (t) { return { "No args": function (a) { @@ -25,6 +27,18 @@ module.exports = function (t) { a(mfn('foo', 'bar', 'zeta'), 'foobarzeta', "#2"); a(i, 1, "Called once"); }, + "Many args: Length false": function (a) { + var i = 0, fn = function () { ++i; return join.call(arguments, '|'); } + , y = { toString: function () { return 'foo'; } }, mfn; + mfn = t(fn, { primitive: true, length: false }); + a(mfn(y, 'bar', 'zeta'), 'foo|bar|zeta', "#1"); + a(mfn('foo', 'bar', 'zeta'), 'foo|bar|zeta', "#2"); + a(i, 1, "Called once"); + a(mfn(y, 'bar'), 'foo|bar', "#3"); + a(i, 2, "Called twice"); + a(mfn(y, 'bar'), 'foo|bar', "#4"); + a(i, 2, "Called twice #2"); + }, "Clear cache": function (a) { var i = 0, fn = function (x, y, z) { ++i; return x + y + z; }, mfn , y = { toString: function () { return 'foo'; } }; From be4cfadbd471685c42e891d32d153294ef6636cb Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 22 Jul 2013 19:39:53 +0200 Subject: [PATCH 2/4] v0.2.5 --- CHANGES | 3 +++ package.json | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index ef7905f..a148c47 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +v0.2.5 -- 2013.06.21 +* Fix primitive handling for dynamic arguments length + v0.2.4 -- 2013.03.23 * Throw on circular invocations, they cannot be memoized as intended. diff --git a/package.json b/package.json index 915a6bf..bcad6a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "memoizee", - "version": "0.2.4", + "version": "0.2.5", "description": "Complete memoize/cache solution. Works with any type and length of function arguments", "main": "lib", "scripts": { @@ -35,11 +35,11 @@ }, "dependencies": { "es5-ext": "~0.9.2", - "event-emitter": "~0.2.1", + "event-emitter": "~0.2.2", "next-tick": "0.1.x" }, "devDependencies": { - "tad": "~0.1.15" + "tad": "~0.1.16" }, "author": "Mariusz Nowak (http://www.medikoo.com/)", "license": "MIT" From ff85fb5228543fa445c6dfbf0be8a00cd071e710 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Tue, 8 Oct 2013 15:20:23 +0200 Subject: [PATCH 3/4] Do not emit `asyncpurge` on uninitialized values Fix #9 --- lib/ext/async.js | 13 +++++++------ test/ext/async.js | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/ext/async.js b/lib/ext/async.js index 453c112..f96eab8 100644 --- a/lib/ext/async.js +++ b/lib/ext/async.js @@ -2,11 +2,12 @@ 'use strict'; -var toArray = require('es5-ext/lib/Array/from') - , last = require('es5-ext/lib/Array/prototype/last') - , forEach = require('es5-ext/lib/Object/for-each') - , isCallable = require('es5-ext/lib/Object/is-callable') - , nextTick = require('next-tick') +var toArray = require('es5-ext/lib/Array/from') + , last = require('es5-ext/lib/Array/prototype/last') + , isArguments = require('es5-ext/lib/Function/is-arguments') + , forEach = require('es5-ext/lib/Object/for-each') + , isCallable = require('es5-ext/lib/Object/is-callable') + , nextTick = require('next-tick') , isArray = Array.isArray, slice = Array.prototype.slice , apply = Function.prototype.apply; @@ -101,7 +102,7 @@ require('../_base').ext.async = function (ignore, conf) { // 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 // gracefully pass to callback - if (!isArray(cache[id])) { + if (isArguments(cache[id])) { conf.emit('purgeasync', id); delete cache[id]; } diff --git a/test/ext/async.js b/test/ext/async.js index 833f121..732f36d 100644 --- a/test/ext/async.js +++ b/test/ext/async.js @@ -3,6 +3,8 @@ var memoize = require('../../lib') , nextTick = require('next-tick'); +require('../../lib/ext/dispose'); + module.exports = function () { return { "Regular": { @@ -85,7 +87,7 @@ module.exports = function () { return u; }; - mfn = memoize(fn, { async: true }); + mfn = memoize(fn, { async: true, dispose: a.never }); a(mfn(3, 7, function (err, res) { a.deep([err, res], [e, undefined], "Result #1"); From 86fc11ac86c21804559cfc3ebe2f6d87ef631402 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Tue, 8 Oct 2013 15:23:17 +0200 Subject: [PATCH 4/4] v0.2.6 --- CHANGES | 5 +++++ package.json | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index a148c47..3403075 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +v0.2.6 -- 2013.10.08 +* Fix internal events propagation when handling async calls that + resolve with errors. `asyncpurge` was emitted for values that had no + `asyncinit` emitted. Issue #9 + v0.2.5 -- 2013.06.21 * Fix primitive handling for dynamic arguments length diff --git a/package.json b/package.json index bcad6a8..0921481 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "memoizee", - "version": "0.2.5", + "version": "0.2.6", "description": "Complete memoize/cache solution. Works with any type and length of function arguments", "main": "lib", "scripts": { @@ -39,7 +39,7 @@ "next-tick": "0.1.x" }, "devDependencies": { - "tad": "~0.1.16" + "tad": "~0.1.19" }, "author": "Mariusz Nowak (http://www.medikoo.com/)", "license": "MIT"