Comparing version 0.2.6 to 0.3.0
@@ -9,5 +9,5 @@ 'use strict'; | ||
var forEach = require('es5-ext/lib/Object/for-each') | ||
, pad = require('es5-ext/lib/String/prototype/pad') | ||
, memoizee = require('../lib') | ||
var forEach = require('es5-ext/object/for-each') | ||
, pad = require('es5-ext/string/#/pad') | ||
, memoizee = require('..') | ||
, underscore = require('underscore').memoize | ||
@@ -14,0 +14,0 @@ , lodash = require('lodash').memoize |
{ | ||
"name": "memoizee", | ||
"version": "0.2.6", | ||
"description": "Complete memoize/cache solution. Works with any type and length of function arguments", | ||
"main": "lib", | ||
"scripts": { | ||
"test": "node node_modules/tad/bin/tad lib" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/medikoo/memoize.git" | ||
}, | ||
"version": "0.3.0", | ||
"description": "Memoize/cache", | ||
"author": "Mariusz Nowak <medikoo@medikoo.com> (http://www.medikoo.com/)", | ||
"keywords": [ | ||
@@ -29,19 +22,21 @@ "memoize", | ||
], | ||
"bugs": { | ||
"email": "medikoo+memoize@medikoo.com", | ||
"url": "https://github.com/medikoo/memoize/issues" | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/medikoo/memoize.git" | ||
}, | ||
"engines": { | ||
"node": ">=0.4" | ||
}, | ||
"dependencies": { | ||
"es5-ext": "~0.9.2", | ||
"event-emitter": "~0.2.2", | ||
"next-tick": "0.1.x" | ||
"d": "~0.1.1", | ||
"es5-ext": "~0.10.2", | ||
"event-emitter": "~0.3.1", | ||
"lru-queue": "0.1.x", | ||
"next-tick": "~0.2.2", | ||
"timers-ext": "0.1.x" | ||
}, | ||
"devDependencies": { | ||
"tad": "~0.1.19" | ||
"tad": "~0.1.21" | ||
}, | ||
"author": "Mariusz Nowak <medikoo+memoize@medikoo.com> (http://www.medikoo.com/)", | ||
"scripts": { | ||
"test": "node node_modules/tad/bin/tad" | ||
}, | ||
"license": "MIT" | ||
} |
162
README.md
@@ -1,2 +0,3 @@ | ||
# Memoize – Complete memoize/cache solution for JavaScript | ||
# Memoize | ||
## Complete memoize/cache solution for JavaScript | ||
@@ -7,3 +8,3 @@ _Originally derived from [es5-ext](https://github.com/medikoo/es5-ext) package._ | ||
## Features | ||
### Features | ||
@@ -23,4 +24,14 @@ * Works with any type of function arguments – __no serialization is needed__ | ||
## Usage | ||
### Installation | ||
In your project path — __note the two `e`'s in `memoizee`:__ | ||
$ npm install memoizee | ||
_`memoize` name was already taken, therefore project is published as `memoizee` on NPM._ | ||
To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/) | ||
### Usage | ||
```javascript | ||
@@ -37,43 +48,7 @@ var memoize = require('memoizee'); | ||
## Installation | ||
### NPM | ||
### Configuration | ||
In your project path: | ||
``` | ||
$ npm install memoizee | ||
``` | ||
### Browser | ||
Browser bundle can be easily created with help of [modules-webmake](https://github.com/medikoo/modules-webmake). Assuming that you have latest [Node.js](http://nodejs.org/) and [Git](http://git-scm.com/) installed, following will work in command shell of any system (Linux/MacOS/Windows): | ||
``` | ||
$ npm install -g webmake | ||
$ git clone git://github.com/medikoo/memoize.git | ||
$ cd memoize | ||
$ npm install | ||
$ cd .. | ||
$ webmake --name=memoize memoize/lib/index.js memoize.js | ||
``` | ||
Last command bundles memoize with all it's functionalities, but you may need just a subset, you can have that by addressing specific modules directly, e.g. with following you will build just primitive mode with support for asynchronous functions: | ||
``` | ||
$ webmake --name=memoize --include=memoize/lib/ext/async.js memoize/lib/primitive.js memoize.js | ||
``` | ||
If you work with AMD modules, add _amd_ option, so generated bundle is one: | ||
``` | ||
$ webmake --name=memoize --amd memoize/lib/index.js memoize.js | ||
``` | ||
_Mind that memoize relies on some EcmaScript5 features, so for older browsers you need to load as well [es5-shim](https://github.com/kriskowal/es5-shim)_ | ||
## Configuration | ||
All below options can be applied in any combination | ||
### Arguments length | ||
#### Arguments length | ||
@@ -107,3 +82,3 @@ By default fixed number of arguments that function take is assumed (it's read from function's `length` property) this can be overridden: | ||
### Primitive mode | ||
#### Primitive mode | ||
@@ -119,5 +94,5 @@ If we work with large result sets, or memoize hot functions, default mode may not perform as fast as we expect. In that case it's good to run memoization in _primitive_ mode. To provide fast access, results are saved in hash instead of an array. Generated hash ids are result of arguments to string convertion. __Mind that this mode will work correctly only if stringified arguments produce unique strings.__ | ||
### Resolvers | ||
#### Resolvers | ||
When not working in _primitive_ mode but expecting arguments of certain type it's good to coerce them before doing memoization. We can do that by passing additional resolvers array: | ||
When we're expecting arguments of certain type it's good to coerce them before doing memoization. We can do that by passing additional resolvers array: | ||
@@ -132,7 +107,7 @@ ```javascript | ||
__Note. If your arguments are collections (arrays or hashes) that you want to memoize by content (not by self objects), you need to cast them to strings__, for that just use [primitive mode](#primitive-mode). Arrays have standard string representation and work with primitive mode out of a box, for hashes you need to define `toString` method, that will produce unique string descriptions. | ||
__Note. If your arguments are collections (arrays or hashes) that you want to memoize by content (not by self objects), you need to cast them to strings__, for it's best to just use [primitive mode](#primitive-mode). Arrays have standard string representation and work with primitive mode out of a box, for hashes you need to define `toString` method, that will produce unique string descriptions, or rely on `JSON.stringify`. | ||
Similarly __if you want to memoize functions by their code representation not by their objects, you should use primitive mode__. | ||
### Memoizing asynchronous functions | ||
#### Memoizing asynchronous functions | ||
@@ -161,3 +136,3 @@ With _async_ option we indicate that we memoize asynchronous function. | ||
### Memoizing a method | ||
#### Memoizing a methods | ||
@@ -168,3 +143,3 @@ When we are defining a prototype, we may want to define method that will memoize it's results in relation to each instance. Basic way to obtain that would be: | ||
var Foo = function () { | ||
this.bar = memoize(this.bar.bind(this)); | ||
this.bar = memoize(this.bar.bind(this), { someOption: true }); | ||
// ... constructor logic | ||
@@ -177,35 +152,29 @@ }; | ||
With _method_ option we can configure memoization directly on prototype: | ||
There's a lazy methods descriptor generator provided: | ||
```javascript | ||
var Foo = function () { | ||
// ... constructor logic | ||
}; | ||
Foo.prototype.bar = memoize(function () { | ||
// ... method logic | ||
}, { method: 'bar' }); | ||
``` | ||
var d = require('d'); | ||
var memoizeMethods = require('memoizee/methods'); | ||
Additionally we may provide descriptor which would be used for defining method on instance object: | ||
```javascript | ||
var Foo = function () { | ||
// ... constructor logic | ||
}; | ||
Foo.prototype.bar = memoize(function () { | ||
// ... method logic | ||
}, { method: { name: 'bar', descriptor: { configurable: true } } }); | ||
Object.definePropeties(Foo.prototype, memoizeMethods({ | ||
bar: d(function () { | ||
// ... method logic | ||
}, { someOption: true }) | ||
})); | ||
``` | ||
### Cache handling | ||
#### Cache handling | ||
#### Manual clean up: | ||
##### Manual clean up: | ||
Clear data for particular call. | ||
Delete data for particular call. | ||
```javascript | ||
memoized.clear('foo', true); | ||
memoized.delete('foo', true); | ||
``` | ||
Arguments passed to `clear` are treated with same rules as input arguments passed to function | ||
Arguments passed to `delete` are treated with same rules as input arguments passed to function | ||
@@ -215,11 +184,11 @@ Clear all cached data: | ||
```javascript | ||
memoized.clearAll(); | ||
memoized.clear(); | ||
``` | ||
#### Expire cache after given period of time | ||
##### Expire cache after given period of time | ||
With _maxAge_ option we can ensure that cache for given call is cleared after predefined period of time | ||
With _maxAge_ option we can ensure that cache for given call is cleared after predefined period of time (in milliseconds) | ||
```javascript | ||
memoized = memoize(fn, { maxAge: 1000 }); | ||
memoized = memoize(fn, { maxAge: 1000 }); // 1 second | ||
@@ -274,5 +243,5 @@ memoized('foo', 3); | ||
#### Reference counter | ||
##### Reference counter | ||
We can track number of references returned from cache, and manually clear them. When last reference is cleared, cache is purged automatically: | ||
We can track number of references returned from cache, and manually delete them. When last reference is cleared, cache is purged automatically: | ||
@@ -282,14 +251,14 @@ ```javascript | ||
memoized('foo', 3); // refs: 1 | ||
memoized('foo', 3); // Cache hit, refs: 2 | ||
memoized('foo', 3); // Cache hit, refs: 3 | ||
memoized.clearRef('foo', 3); // refs: 2 | ||
memoized.clearRef('foo', 3); // refs: 1 | ||
memoized.clearRef('foo', 3); // refs: 0, Cache purged for 'foo', 3 | ||
memoized('foo', 3); // Re-executed, refs: 1 | ||
memoized('foo', 3); // refs: 1 | ||
memoized('foo', 3); // Cache hit, refs: 2 | ||
memoized('foo', 3); // Cache hit, refs: 3 | ||
memoized.deleteRef('foo', 3); // refs: 2 | ||
memoized.deleteRef('foo', 3); // refs: 1 | ||
memoized.deleteRef('foo', 3); // refs: 0, Cache purged for 'foo', 3 | ||
memoized('foo', 3); // Re-executed, refs: 1 | ||
``` | ||
#### Limiting cache size | ||
##### Limiting cache size | ||
With _max_ option you can limit cache size, it's backed with [LRU algorithm](http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used) | ||
With _max_ option you can limit cache size, it's backed with [LRU algorithm](http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used), provided by low-level [lru-queue](https://github.com/medikoo/lru-queue) utility | ||
@@ -311,3 +280,4 @@ ```javascript | ||
#### Registering dispose callback | ||
##### Registering dispose callback | ||
You can register callback that is called on each value being removed from cache: | ||
@@ -324,3 +294,3 @@ | ||
## Benchmarks | ||
### Benchmarks | ||
@@ -331,3 +301,3 @@ Simple benchmark tests can be found in _benchmark_ folder. Currently it's just plain simple calculation of fibonacci sequences. To run it you need to install other test candidates: | ||
Example output taken under Node v0.8.9 on 2008 MBP Pro: | ||
Example output taken under Node v0.8.26 on 2008 MBP Pro: | ||
@@ -337,12 +307,12 @@ ``` | ||
1: 21ms Memoizee (primitive mode) | ||
1: 21ms Lo-dash | ||
3: 23ms Underscore | ||
4: 88ms Memoizee (primitive mode) LRU (max: 1000) | ||
5: 178ms Memoizee (object mode) | ||
6: 234ms Memoizee (object mode) LRU (max: 1000) | ||
7: 2852ms lru-cache LRU (max: 1000) | ||
1: 25ms Memoizee (primitive mode) | ||
2: 28ms Underscore | ||
3: 34ms lru-cache LRU (max: 1000) | ||
4: 65ms Lo-dash | ||
5: 94ms Memoizee (primitive mode) LRU (max: 1000) | ||
6: 262ms Memoizee (object mode) LRU (max: 1000) | ||
7: 280ms Memoizee (object mode) | ||
``` | ||
## Profiling & Statistics | ||
### Profiling & Statistics | ||
@@ -354,3 +324,3 @@ If you want to make sure how much you benefit from memoization or just check if memoization works as expected, loading profile module will give access to all valuable information. | ||
```javascript | ||
var memProfile = require('memoizee/lib/ext/profile'); | ||
var memProfile = require('memoizee/profile'); | ||
``` | ||
@@ -385,9 +355,9 @@ | ||
## Tests [![Build Status](https://secure.travis-ci.org/medikoo/memoize.png?branch=master)](https://secure.travis-ci.org/medikoo/memoize) | ||
### Tests [![Build Status](https://api.travis-ci.org/medikoo/memoize.png?branch=master)](https://travis-ci.org/medikoo/memoize) | ||
$ npm test | ||
## Contributors | ||
### Contributors | ||
* [@puzrin](https://github.com/puzrin) (Vitaly Puzrin) | ||
* Proposal and help with coining right _pre-fetch_ logic for [_maxAge_](https://github.com/medikoo/memoize#expire-cache-after-given-period-of-time) variant |
'use strict'; | ||
var memoize = require('../../lib') | ||
var memoize = require('../..') | ||
, nextTick = require('next-tick'); | ||
require('../../lib/ext/dispose'); | ||
module.exports = function () { | ||
@@ -61,3 +59,3 @@ return { | ||
mfn.clear(3, 7); | ||
mfn.delete(3, 7); | ||
@@ -74,4 +72,4 @@ a(mfn(3, 7, function (err, res) { | ||
nextTick(function () { | ||
a(i, 3, "Init After clear"); | ||
a(invoked, 9, "Cb After clear"); | ||
a(i, 3, "Init After delete"); | ||
a(invoked, 9, "Cb After delete"); | ||
d(); | ||
@@ -169,3 +167,3 @@ }); | ||
mfn.clear(3, 7); | ||
mfn.delete(3, 7); | ||
@@ -180,3 +178,3 @@ a(mfn(3, 7, function (err, res) { | ||
nextTick(function () { | ||
a(i, 3, "Call After clear"); | ||
a(i, 3, "Call After delete"); | ||
d(); | ||
@@ -183,0 +181,0 @@ }); |
'use strict'; | ||
var memoize = require('../../lib') | ||
var memoize = require('../..') | ||
, nextTick = require('next-tick'); | ||
@@ -10,7 +10,4 @@ | ||
"Sync": function (a) { | ||
var mfn, fn, i = 0, value = [], x, invoked; | ||
fn = function (x, y) { | ||
++i; | ||
return x + y; | ||
}; | ||
var mfn, fn, value = [], x, invoked; | ||
fn = function (x, y) { return x + y; }; | ||
mfn = memoize(fn, { dispose: function (val) { value.push(val); } }); | ||
@@ -22,6 +19,6 @@ | ||
a.deep(value, [], "Pre"); | ||
mfn.clear(5, 8); | ||
mfn.delete(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value = []; | ||
mfn.clear(12, 4); | ||
mfn.delete(12, 4); | ||
a.deep(value, [16], "#2"); | ||
@@ -31,3 +28,3 @@ | ||
mfn(77, 11); | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
@@ -40,41 +37,12 @@ | ||
mfn.clear(); | ||
a(invoked, false, "No args: Post invalid clear"); | ||
mfn.delete(); | ||
a(invoked, false, "No args: Post invalid delete"); | ||
mfn(); | ||
a(invoked, false, "No args: Post cache"); | ||
mfn.clear(); | ||
a(invoked, x, "No args: Pre clear"); | ||
mfn.delete(); | ||
a(invoked, x, "No args: Pre delete"); | ||
}, | ||
"Method": function (a) { | ||
var fn, i = 0, value = []; | ||
fn = function (x, y) { | ||
++i; | ||
return x + y; | ||
}; | ||
Object.defineProperty(value, 'mfn', { value: memoize(fn, { | ||
method: 'mfn', | ||
dispose: function (val) { this.push(val); } | ||
}), configurable: true }); | ||
value.mfn(3, 7); | ||
value.mfn(5, 8); | ||
value.mfn(12, 4); | ||
a.deep(value, [], "Pre"); | ||
value.mfn.clear(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value.length = 0; | ||
value.mfn.clear(12, 4); | ||
a.deep(value, [16], "#2"); | ||
value.length = 0; | ||
value.mfn(77, 11); | ||
value.mfn.clearAll(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
}, | ||
"Ref counter": function (a) { | ||
var mfn, fn, i = 0, value = []; | ||
fn = function (x, y) { | ||
++i; | ||
return x + y; | ||
}; | ||
var mfn, fn, value = []; | ||
fn = function (x, y) { return x + y; }; | ||
mfn = memoize(fn, { refCounter: true, | ||
@@ -88,8 +56,8 @@ dispose: function (val) { value.push(val); } }); | ||
mfn(5, 8); | ||
mfn.clearRef(5, 8); | ||
mfn.deleteRef(5, 8); | ||
a.deep(value, [], "Pre"); | ||
mfn.clearRef(5, 8); | ||
mfn.deleteRef(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value = []; | ||
mfn.clearRef(12, 4); | ||
mfn.deleteRef(12, 4); | ||
a.deep(value, [16], "#2"); | ||
@@ -99,12 +67,9 @@ | ||
mfn(77, 11); | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
}, | ||
"Async": function (a, d) { | ||
var mfn, fn, u = {}, i = 0, value = []; | ||
var mfn, fn, u = {}, value = []; | ||
fn = function (x, y, cb) { | ||
nextTick(function () { | ||
++i; | ||
cb(null, x + y); | ||
}); | ||
nextTick(function () { cb(null, x + y); }); | ||
return u; | ||
@@ -120,6 +85,6 @@ }; | ||
a.deep(value, [], "Pre"); | ||
mfn.clear(5, 8); | ||
mfn.delete(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value = []; | ||
mfn.clear(12, 4); | ||
mfn.delete(12, 4); | ||
a.deep(value, [16], "#2"); | ||
@@ -129,3 +94,3 @@ | ||
mfn(77, 11, function () { | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
@@ -141,7 +106,4 @@ d(); | ||
"Sync": function (a) { | ||
var mfn, fn, i = 0, value = []; | ||
fn = function (x, y) { | ||
++i; | ||
return x + y; | ||
}; | ||
var mfn, fn, value = []; | ||
fn = function (x, y) { return x + y; }; | ||
mfn = memoize(fn, { dispose: function (val) { value.push(val); } }); | ||
@@ -153,6 +115,6 @@ | ||
a.deep(value, [], "Pre"); | ||
mfn.clear(5, 8); | ||
mfn.delete(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value = []; | ||
mfn.clear(12, 4); | ||
mfn.delete(12, 4); | ||
a.deep(value, [16], "#2"); | ||
@@ -162,11 +124,8 @@ | ||
mfn(77, 11); | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
}, | ||
"Ref counter": function (a) { | ||
var mfn, fn, i = 0, value = []; | ||
fn = function (x, y) { | ||
++i; | ||
return x + y; | ||
}; | ||
var mfn, fn, value = []; | ||
fn = function (x, y) { return x + y; }; | ||
mfn = memoize(fn, { refCounter: true, | ||
@@ -180,8 +139,8 @@ dispose: function (val) { value.push(val); } }); | ||
mfn(5, 8); | ||
mfn.clearRef(5, 8); | ||
mfn.deleteRef(5, 8); | ||
a.deep(value, [], "Pre"); | ||
mfn.clearRef(5, 8); | ||
mfn.deleteRef(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value = []; | ||
mfn.clearRef(12, 4); | ||
mfn.deleteRef(12, 4); | ||
a.deep(value, [16], "#2"); | ||
@@ -191,12 +150,9 @@ | ||
mfn(77, 11); | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
}, | ||
"Async": function (a, d) { | ||
var mfn, fn, u = {}, i = 0, value = []; | ||
var mfn, fn, u = {}, value = []; | ||
fn = function (x, y, cb) { | ||
nextTick(function () { | ||
++i; | ||
cb(null, x + y); | ||
}); | ||
nextTick(function () { cb(null, x + y); }); | ||
return u; | ||
@@ -212,6 +168,6 @@ }; | ||
a.deep(value, [], "Pre"); | ||
mfn.clear(5, 8); | ||
mfn.delete(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value = []; | ||
mfn.clear(12, 4); | ||
mfn.delete(12, 4); | ||
a.deep(value, [16], "#2"); | ||
@@ -221,3 +177,3 @@ | ||
mfn(77, 11, function () { | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
@@ -224,0 +180,0 @@ d(); |
'use strict'; | ||
var memoize = require('../../lib') | ||
var memoize = require('../..') | ||
, nextTick = require('next-tick'); | ||
require('../../ext/async'); | ||
module.exports = function () { | ||
@@ -7,0 +9,0 @@ return { |
'use strict'; | ||
var memoize = require('../../lib') | ||
var memoize = require('../..') | ||
, nextTick = require('next-tick'); | ||
@@ -34,12 +34,12 @@ | ||
a(mfn(77, 11), 88, "Result D #1"); // Clear 12, 4 | ||
a(mfn(77, 11), 88, "Result D #1"); // Delete 12, 4 | ||
a(i, 4, "Called D #1"); | ||
a(mfn(5, 8), 13, "Result B #4"); | ||
a(i, 4, "Called B #4"); | ||
a(mfn(12, 4), 16, "Result C #2"); // Clear 3, 7 | ||
a(mfn(12, 4), 16, "Result C #2"); // Delete 3, 7 | ||
a(i, 5, "Called C #2"); | ||
a(mfn(3, 7), 10, "Result #5"); // Clear 77, 11 | ||
a(mfn(3, 7), 10, "Result #5"); // Delete 77, 11 | ||
a(i, 6, "Called #5"); | ||
a(mfn(77, 11), 88, "Result D #2"); // Clear 5, 8 | ||
a(mfn(77, 11), 88, "Result D #2"); // Delete 5, 8 | ||
a(i, 7, "Called D #2"); | ||
@@ -49,3 +49,3 @@ a(mfn(12, 4), 16, "Result C #3"); | ||
a(mfn(5, 8), 13, "Result B #5"); // Clear 3, 7 | ||
a(mfn(5, 8), 13, "Result B #5"); // Delete 3, 7 | ||
a(i, 8, "Called B #5"); | ||
@@ -56,7 +56,7 @@ | ||
mfn.clear(77, 11); | ||
mfn.delete(77, 11); | ||
a(mfn(77, 11), 88, "Result D #4"); | ||
a(i, 9, "Called D #4"); | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a(mfn(5, 8), 13, "Result B #6"); | ||
@@ -147,3 +147,3 @@ a(i, 10, "Called B #6"); | ||
mfn.clear(77, 11); | ||
mfn.delete(77, 11); | ||
a(mfn(77, 11, function (err, res) { | ||
@@ -154,3 +154,3 @@ a.deep([err, res], [null, 88], | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a(mfn(5, 8, function (err, res) { | ||
@@ -215,12 +215,12 @@ a.deep([err, res], [null, 13], | ||
a(mfn(77, 11), 88, "Result D #1"); // Clear 12, 4 | ||
a(mfn(77, 11), 88, "Result D #1"); // Delete 12, 4 | ||
a(i, 4, "Called D #1"); | ||
a(mfn(5, 8), 13, "Result B #4"); | ||
a(i, 4, "Called B #4"); | ||
a(mfn(12, 4), 16, "Result C #2"); // Clear 3, 7 | ||
a(mfn(12, 4), 16, "Result C #2"); // Delete 3, 7 | ||
a(i, 5, "Called C #2"); | ||
a(mfn(3, 7), 10, "Result #5"); // Clear 77, 11 | ||
a(mfn(3, 7), 10, "Result #5"); // Delete 77, 11 | ||
a(i, 6, "Called #5"); | ||
a(mfn(77, 11), 88, "Result D #2"); // Clear 5, 8 | ||
a(mfn(77, 11), 88, "Result D #2"); // Delete 5, 8 | ||
a(i, 7, "Called D #2"); | ||
@@ -230,3 +230,3 @@ a(mfn(12, 4), 16, "Result C #3"); | ||
a(mfn(5, 8), 13, "Result B #5"); // Clear 3, 7 | ||
a(mfn(5, 8), 13, "Result B #5"); // Delete 3, 7 | ||
a(i, 8, "Called B #5"); | ||
@@ -237,7 +237,7 @@ | ||
mfn.clear(77, 11); | ||
mfn.delete(77, 11); | ||
a(mfn(77, 11), 88, "Result D #4"); | ||
a(i, 9, "Called D #4"); | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a(mfn(5, 8), 13, "Result B #6"); | ||
@@ -328,3 +328,3 @@ a(i, 10, "Called B #6"); | ||
mfn.clear(77, 11); | ||
mfn.delete(77, 11); | ||
a(mfn(77, 11, function (err, res) { | ||
@@ -335,3 +335,3 @@ a.deep([err, res], [null, 88], | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a(mfn(5, 8, function (err, res) { | ||
@@ -338,0 +338,0 @@ a.deep([err, res], [null, 13], |
'use strict'; | ||
var memoize = require('../../lib') | ||
var memoize = require('../..') | ||
, nextTick = require('next-tick'); | ||
@@ -11,14 +11,14 @@ | ||
mfn = memoize(fn, { refCounter: true }); | ||
a(mfn.clearRef(3, 5, 7), null, "Clear before"); | ||
a(mfn.deleteRef(3, 5, 7), null, "Delete before"); | ||
a(mfn(3, 5, 7), 15, "Initial"); | ||
a(mfn(3, 5, 7), 15, "Cache"); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #1"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Delete #1"); | ||
mfn(3, 5, 7); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #2"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Delete #2"); | ||
mfn(3, 5, 7); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #3"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Delete #3"); | ||
mfn(3, 5, 7); | ||
a(i, 1, "Not cleared"); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #4"); | ||
a(mfn.clearRef(3, 5, 7), true, "Clear final"); | ||
a(i, 1, "Not deleteed"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Delete #4"); | ||
a(mfn.deleteRef(3, 5, 7), true, "Delete final"); | ||
mfn(3, 5, 7); | ||
@@ -41,3 +41,3 @@ a(i, 2, "Restarted"); | ||
a(mfn.clearRef(3, 7), null, "Clear ref before"); | ||
a(mfn.deleteRef(3, 7), null, "Delete ref before"); | ||
@@ -73,6 +73,6 @@ a(mfn(3, 7, function (err, res) { | ||
a(mfn.clearRef(3, 7), false, "Clear ref #1"); | ||
a(mfn.clearRef(3, 7), false, "Clear ref #2"); | ||
a(mfn.clearRef(3, 7), false, "Clear ref #3"); | ||
a(mfn.clearRef(3, 7), true, "Clear ref Final"); | ||
a(mfn.deleteRef(3, 7), false, "Delete ref #1"); | ||
a(mfn.deleteRef(3, 7), false, "Delete ref #2"); | ||
a(mfn.deleteRef(3, 7), false, "Delete ref #3"); | ||
a(mfn.deleteRef(3, 7), true, "Delete ref Final"); | ||
@@ -87,3 +87,3 @@ a(mfn(3, 7, function (err, res) { | ||
nextTick(function () { | ||
a(i, 3, "Call After clear"); | ||
a(i, 3, "Call After delete"); | ||
d(); | ||
@@ -97,14 +97,14 @@ }); | ||
mfn = memoize(fn, { primitive: true, refCounter: true }); | ||
a(mfn.clearRef(3, 5, 7), null, "Clear before"); | ||
a(mfn.deleteRef(3, 5, 7), null, "Delete before"); | ||
a(mfn(3, 5, 7), 15, "Initial"); | ||
a(mfn(3, 5, 7), 15, "Cache"); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #1"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Delete #1"); | ||
mfn(3, 5, 7); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #2"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Delete #2"); | ||
mfn(3, 5, 7); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #3"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Delete #3"); | ||
mfn(3, 5, 7); | ||
a(i, 1, "Not cleared"); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #4"); | ||
a(mfn.clearRef(3, 5, 7), true, "Clear final"); | ||
a(i, 1, "Not deleteed"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Delete #4"); | ||
a(mfn.deleteRef(3, 5, 7), true, "Delete final"); | ||
mfn(3, 5, 7); | ||
@@ -127,3 +127,3 @@ a(i, 2, "Restarted"); | ||
a(mfn.clearRef(3, 7), null, "Clear ref before"); | ||
a(mfn.deleteRef(3, 7), null, "Delete ref before"); | ||
@@ -159,6 +159,6 @@ a(mfn(3, 7, function (err, res) { | ||
a(mfn.clearRef(3, 7), false, "Clear ref #1"); | ||
a(mfn.clearRef(3, 7), false, "Clear ref #2"); | ||
a(mfn.clearRef(3, 7), false, "Clear ref #3"); | ||
a(mfn.clearRef(3, 7), true, "Clear ref Final"); | ||
a(mfn.deleteRef(3, 7), false, "Delete ref #1"); | ||
a(mfn.deleteRef(3, 7), false, "Delete ref #2"); | ||
a(mfn.deleteRef(3, 7), false, "Delete ref #3"); | ||
a(mfn.deleteRef(3, 7), true, "Delete ref Final"); | ||
@@ -173,3 +173,3 @@ a(mfn(3, 7, function (err, res) { | ||
nextTick(function () { | ||
a(i, 3, "Call After clear"); | ||
a(i, 3, "Call After delete"); | ||
d(); | ||
@@ -176,0 +176,0 @@ }); |
'use strict'; | ||
var toArray = require('es5-ext/lib/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) { | ||
@@ -91,2 +93,13 @@ return { | ||
}, | ||
"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"); | ||
a(i, 1, "Called once"); | ||
a(mfn(34, 'bar'), '34|bar', "#3"); | ||
a(i, 2, "Called twice"); | ||
a(mfn(true, 'ola'), '34|bar', "#4"); | ||
a(i, 2, "Called twice #2"); | ||
}, | ||
"Dynamic": function () { | ||
@@ -99,3 +112,3 @@ var i = 0, fn = function () { ++i; return arguments; }, r; | ||
i = 0; | ||
a.deep(toArray(r = fn()), [], "First"); | ||
a.deep(aFrom(r = fn()), [], "First"); | ||
a(fn(), r, "Second"); | ||
@@ -108,3 +121,3 @@ a(fn(), r, "Third"); | ||
i = 0; | ||
a.deep(toArray(r = fn(x, 8)), [x, 8], "First"); | ||
a.deep(aFrom(r = fn(x, 8)), [x, 8], "First"); | ||
a(fn(x, 8), r, "Second"); | ||
@@ -117,3 +130,3 @@ a(fn(x, 8), r, "Third"); | ||
i = 0; | ||
a.deep(toArray(r = fn(x, 8, 23, 98)), [x, 8, 23, 98], "First"); | ||
a.deep(aFrom(r = fn(x, 8, 23, 98)), [x, 8, 23, 98], "First"); | ||
a(fn(x, 8, 23, 98), r, "Second"); | ||
@@ -125,17 +138,10 @@ a(fn(x, 8, 23, 98), r, "Third"); | ||
}, | ||
"Original arguments": function (a) { | ||
var fn, mfn, x = {}; | ||
fn = function (x, y) { x = y; return toArray(mfn.args); }; | ||
mfn = t(fn, { resolvers: [] }); | ||
a.deep(mfn(23, 'raz', x), [23, 'raz', x]); | ||
}, | ||
"Resolvers": function () { | ||
var i = 0, fn, r; | ||
fn = t(function () { ++i; return arguments; }, | ||
{ length: 3, resolvers: [Boolean, String] }); | ||
{ length: 3, resolvers: [Boolean, String] }); | ||
return { | ||
"No args": function () { | ||
i = 0; | ||
a.deep(toArray(r = fn()), [false, 'undefined'], "First"); | ||
a.deep(aFrom(r = fn()), [false, 'undefined'], "First"); | ||
a(fn(), r, "Second"); | ||
@@ -148,3 +154,3 @@ a(fn(), r, "Third"); | ||
i = 0; | ||
a.deep(toArray(r = fn(0, 34, x, 45)), [false, '34', x, 45], | ||
a.deep(aFrom(r = fn(0, 34, x, 45)), [false, '34', x, 45], | ||
"First"); | ||
@@ -156,3 +162,3 @@ a(fn(0, 34, x, 22), r, "Second"); | ||
"Other": function () { | ||
a.deep(toArray(r = fn(1, 34, x, 34)), | ||
a.deep(aFrom(r = fn(1, 34, x, 34)), | ||
[true, '34', x, 34], "Second"); | ||
@@ -180,7 +186,7 @@ a(fn(1, 34, x, 89), r, "Third"); | ||
mfn(1, x, 4); | ||
mfn.clear(1, x, 4); | ||
mfn.delete(1, x, 4); | ||
mfn(1, x, 3); | ||
mfn(1, x, 3); | ||
a(i, 1, "Pre clear"); | ||
mfn.clear(1, x, 3); | ||
mfn.delete(1, x, 3); | ||
mfn(1, x, 3); | ||
@@ -195,3 +201,3 @@ a(i, 2, "After clear"); | ||
mfn(); | ||
mfn.clear(); | ||
mfn.delete(); | ||
mfn(1, x, 3); | ||
@@ -214,3 +220,3 @@ a(i, 1, "Proper no arguments clear"); | ||
a(i, 2, "Pre clear"); | ||
fn.clearAll(); | ||
fn.clear(); | ||
fn(1, x, 3); | ||
@@ -223,30 +229,2 @@ fn(1, x, 4); | ||
}, | ||
"Method": { | ||
"No descriptor": function (a) { | ||
var mfn, x = {}, i = 0, fn = function () { | ||
++i; | ||
return this; | ||
}; | ||
mfn = t(fn, { method: 'foo' }); | ||
a(mfn.call(x), x, "Context"); | ||
a(x.foo(), x, "Method"); | ||
a(i, 1, "Cached"); | ||
}, | ||
"Descriptor": function (a) { | ||
var mfn, x = {}, i = 0, fn = function () { | ||
++i; | ||
return this; | ||
}; | ||
mfn = t(fn, | ||
{ method: { name: 'foo', descriptor: { configurable: true } } }); | ||
a(mfn.call(x), x, "Context"); | ||
a.deep(Object.getOwnPropertyDescriptor(x, 'foo'), | ||
{ enumerable: false, configurable: true, writable: false, | ||
value: x.foo }); | ||
a(x.foo(), x, "Method"); | ||
a(i, 1, "Cached"); | ||
} | ||
}, | ||
"Primitive": { | ||
@@ -283,3 +261,3 @@ "No args": function (a) { | ||
a(i, 1, "Called once"); | ||
mfn.clear('foo', { toString: function () { return 'bar'; } }, | ||
mfn.delete('foo', { toString: function () { return 'bar'; } }, | ||
'zeta'); | ||
@@ -294,14 +272,14 @@ a(mfn(y, 'bar', 'zeta'), 'foobarzeta', "#3"); | ||
mfn = t(fn, { refCounter: true }); | ||
a(mfn.clearRef(3, 5, 7), null, "Clear before"); | ||
a(mfn.deleteRef(3, 5, 7), null, "Clear before"); | ||
a(mfn(3, 5, 7), 15, "Initial"); | ||
a(mfn(3, 5, 7), 15, "Cache"); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #1"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Clear #1"); | ||
mfn(3, 5, 7); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #2"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Clear #2"); | ||
mfn(3, 5, 7); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #3"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Clear #3"); | ||
mfn(3, 5, 7); | ||
a(i, 1, "Not cleared"); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #4"); | ||
a(mfn.clearRef(3, 5, 7), true, "Clear final"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Clear #4"); | ||
a(mfn.deleteRef(3, 5, 7), true, "Clear final"); | ||
mfn(3, 5, 7); | ||
@@ -315,14 +293,14 @@ a(i, 2, "Restarted"); | ||
mfn = t(fn, { primitive: true, refCounter: true }); | ||
a(mfn.clearRef(3, 5, 7), null, "Clear before"); | ||
a(mfn.deleteRef(3, 5, 7), null, "Clear before"); | ||
a(mfn(3, 5, 7), 15, "Initial"); | ||
a(mfn(3, 5, 7), 15, "Cache"); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #1"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Clear #1"); | ||
mfn(3, 5, 7); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #2"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Clear #2"); | ||
mfn(3, 5, 7); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #3"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Clear #3"); | ||
mfn(3, 5, 7); | ||
a(i, 1, "Not cleared"); | ||
a(mfn.clearRef(3, 5, 7), false, "Clear #4"); | ||
a(mfn.clearRef(3, 5, 7), true, "Clear final"); | ||
a(mfn.deleteRef(3, 5, 7), false, "Clear #4"); | ||
a(mfn.deleteRef(3, 5, 7), true, "Clear final"); | ||
mfn(3, 5, 7); | ||
@@ -386,3 +364,3 @@ a(i, 2, "Restarted"); | ||
mfn.clear(3, 7); | ||
mfn.delete(3, 7); | ||
@@ -418,3 +396,3 @@ a(mfn(3, 7, function (err, res) { | ||
a(mfn.clearRef(3, 7), null, "Clear ref before"); | ||
a(mfn.deleteRef(3, 7), null, "Clear ref before"); | ||
@@ -450,6 +428,6 @@ a(mfn(3, 7, function (err, res) { | ||
a(mfn.clearRef(3, 7), false, "Clear ref #1"); | ||
a(mfn.clearRef(3, 7), false, "Clear ref #2"); | ||
a(mfn.clearRef(3, 7), false, "Clear ref #3"); | ||
a(mfn.clearRef(3, 7), true, "Clear ref Final"); | ||
a(mfn.deleteRef(3, 7), false, "Clear ref #1"); | ||
a(mfn.deleteRef(3, 7), false, "Clear ref #2"); | ||
a(mfn.deleteRef(3, 7), false, "Clear ref #3"); | ||
a(mfn.deleteRef(3, 7), true, "Clear ref Final"); | ||
@@ -557,3 +535,3 @@ a(mfn(3, 7, function (err, res) { | ||
mfn.clear(3, 7); | ||
mfn.delete(3, 7); | ||
@@ -586,3 +564,3 @@ a(mfn(3, 7, function (err, res) { | ||
a(mfn.clearRef(3, 7), null, "Clear ref before"); | ||
a(mfn.deleteRef(3, 7), null, "Clear ref before"); | ||
@@ -618,6 +596,6 @@ a(mfn(3, 7, function (err, res) { | ||
a(mfn.clearRef(3, 7), false, "Clear ref #1"); | ||
a(mfn.clearRef(3, 7), false, "Clear ref #2"); | ||
a(mfn.clearRef(3, 7), false, "Clear ref #3"); | ||
a(mfn.clearRef(3, 7), true, "Clear ref Final"); | ||
a(mfn.deleteRef(3, 7), false, "Clear ref #1"); | ||
a(mfn.deleteRef(3, 7), false, "Clear ref #2"); | ||
a(mfn.deleteRef(3, 7), false, "Clear ref #3"); | ||
a(mfn.deleteRef(3, 7), true, "Clear ref Final"); | ||
@@ -925,7 +903,7 @@ a(mfn(3, 7, function (err, res) { | ||
mfn.clear(77, 11); | ||
mfn.delete(77, 11); | ||
a(mfn(77, 11), 88, "Result D #4"); | ||
a(i, 9, "Called D #4"); | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a(mfn(5, 8), 13, "Result B #6"); | ||
@@ -1016,3 +994,3 @@ a(i, 10, "Called B #6"); | ||
mfn.clear(77, 11); | ||
mfn.delete(77, 11); | ||
a(mfn(77, 11, function (err, res) { | ||
@@ -1023,3 +1001,3 @@ a.deep([err, res], [null, 88], | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a(mfn(5, 8, function (err, res) { | ||
@@ -1104,7 +1082,7 @@ a.deep([err, res], [null, 13], | ||
mfn.clear(77, 11); | ||
mfn.delete(77, 11); | ||
a(mfn(77, 11), 88, "Result D #4"); | ||
a(i, 9, "Called D #4"); | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a(mfn(5, 8), 13, "Result B #6"); | ||
@@ -1195,3 +1173,3 @@ a(i, 10, "Called B #6"); | ||
mfn.clear(77, 11); | ||
mfn.delete(77, 11); | ||
a(mfn(77, 11, function (err, res) { | ||
@@ -1202,3 +1180,3 @@ a.deep([err, res], [null, 88], | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a(mfn(5, 8, function (err, res) { | ||
@@ -1241,7 +1219,4 @@ a.deep([err, res], [null, 13], | ||
"Sync": function (a) { | ||
var mfn, fn, i = 0, value = [], x, invoked; | ||
fn = function (x, y) { | ||
++i; | ||
return x + y; | ||
}; | ||
var mfn, fn, value = [], x, invoked; | ||
fn = function (x, y) { return x + y; }; | ||
mfn = t(fn, { dispose: function (val) { value.push(val); } }); | ||
@@ -1253,6 +1228,6 @@ | ||
a.deep(value, [], "Pre"); | ||
mfn.clear(5, 8); | ||
mfn.delete(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value = []; | ||
mfn.clear(12, 4); | ||
mfn.delete(12, 4); | ||
a.deep(value, [16], "#2"); | ||
@@ -1262,3 +1237,3 @@ | ||
mfn(77, 11); | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
@@ -1271,15 +1246,12 @@ | ||
mfn.clear(); | ||
mfn.delete(); | ||
a(invoked, false, "No args: Post invalid clear"); | ||
mfn(); | ||
a(invoked, false, "No args: Post cache"); | ||
mfn.clear(); | ||
mfn.delete(); | ||
a(invoked, x, "No args: Pre clear"); | ||
}, | ||
"Ref counter": function (a) { | ||
var mfn, fn, i = 0, value = []; | ||
fn = function (x, y) { | ||
++i; | ||
return x + y; | ||
}; | ||
var mfn, fn, value = []; | ||
fn = function (x, y) { return x + y; }; | ||
mfn = t(fn, { refCounter: true, | ||
@@ -1293,8 +1265,8 @@ dispose: function (val) { value.push(val); } }); | ||
mfn(5, 8); | ||
mfn.clearRef(5, 8); | ||
mfn.deleteRef(5, 8); | ||
a.deep(value, [], "Pre"); | ||
mfn.clearRef(5, 8); | ||
mfn.deleteRef(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value = []; | ||
mfn.clearRef(12, 4); | ||
mfn.deleteRef(12, 4); | ||
a.deep(value, [16], "#2"); | ||
@@ -1304,12 +1276,9 @@ | ||
mfn(77, 11); | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
}, | ||
"Async": function (a, d) { | ||
var mfn, fn, u = {}, i = 0, value = []; | ||
var mfn, fn, u = {}, value = []; | ||
fn = function (x, y, cb) { | ||
nextTick(function () { | ||
++i; | ||
cb(null, x + y); | ||
}); | ||
nextTick(function () { cb(null, x + y); }); | ||
return u; | ||
@@ -1325,6 +1294,6 @@ }; | ||
a.deep(value, [], "Pre"); | ||
mfn.clear(5, 8); | ||
mfn.delete(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value = []; | ||
mfn.clear(12, 4); | ||
mfn.delete(12, 4); | ||
a.deep(value, [16], "#2"); | ||
@@ -1334,3 +1303,3 @@ | ||
mfn(77, 11, function () { | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
@@ -1346,7 +1315,4 @@ d(); | ||
"Sync": function (a) { | ||
var mfn, fn, i = 0, value = []; | ||
fn = function (x, y) { | ||
++i; | ||
return x + y; | ||
}; | ||
var mfn, fn, value = []; | ||
fn = function (x, y) { return x + y; }; | ||
mfn = t(fn, { dispose: function (val) { value.push(val); } }); | ||
@@ -1358,6 +1324,6 @@ | ||
a.deep(value, [], "Pre"); | ||
mfn.clear(5, 8); | ||
mfn.delete(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value = []; | ||
mfn.clear(12, 4); | ||
mfn.delete(12, 4); | ||
a.deep(value, [16], "#2"); | ||
@@ -1367,11 +1333,8 @@ | ||
mfn(77, 11); | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
}, | ||
"Ref counter": function (a) { | ||
var mfn, fn, i = 0, value = []; | ||
fn = function (x, y) { | ||
++i; | ||
return x + y; | ||
}; | ||
var mfn, fn, value = []; | ||
fn = function (x, y) { return x + y; }; | ||
mfn = t(fn, { refCounter: true, | ||
@@ -1385,8 +1348,8 @@ dispose: function (val) { value.push(val); } }); | ||
mfn(5, 8); | ||
mfn.clearRef(5, 8); | ||
mfn.deleteRef(5, 8); | ||
a.deep(value, [], "Pre"); | ||
mfn.clearRef(5, 8); | ||
mfn.deleteRef(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value = []; | ||
mfn.clearRef(12, 4); | ||
mfn.deleteRef(12, 4); | ||
a.deep(value, [16], "#2"); | ||
@@ -1396,12 +1359,9 @@ | ||
mfn(77, 11); | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
}, | ||
"Async": function (a, d) { | ||
var mfn, fn, u = {}, i = 0, value = []; | ||
var mfn, fn, u = {}, value = []; | ||
fn = function (x, y, cb) { | ||
nextTick(function () { | ||
++i; | ||
cb(null, x + y); | ||
}); | ||
nextTick(function () { cb(null, x + y); }); | ||
return u; | ||
@@ -1417,6 +1377,6 @@ }; | ||
a.deep(value, [], "Pre"); | ||
mfn.clear(5, 8); | ||
mfn.delete(5, 8); | ||
a.deep(value, [13], "#1"); | ||
value = []; | ||
mfn.clear(12, 4); | ||
mfn.delete(12, 4); | ||
a.deep(value, [16], "#2"); | ||
@@ -1426,3 +1386,3 @@ | ||
mfn(77, 11, function () { | ||
mfn.clearAll(); | ||
mfn.clear(); | ||
a.deep(value, [10, 88], "Clear all"); | ||
@@ -1429,0 +1389,0 @@ d(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129700
49
6
3649
1
346
+ Addedd@~0.1.1
+ Addedlru-queue@0.1.x
+ Addedtimers-ext@0.1.x
+ Addedd@0.1.11.0.2(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@2.0.3(transitive)
+ Addedes6-symbol@3.1.4(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedext@1.7.0(transitive)
+ Addedlru-queue@0.1.0(transitive)
+ Addednext-tick@0.2.21.1.0(transitive)
+ Addedtimers-ext@0.1.8(transitive)
+ Addedtype@2.7.3(transitive)
- Removedes5-ext@0.9.2(transitive)
- Removedevent-emitter@0.2.2(transitive)
- Removednext-tick@0.1.0(transitive)
Updatedes5-ext@~0.10.2
Updatedevent-emitter@~0.3.1
Updatednext-tick@~0.2.2