Update to v13 and add queue and completely change code
This commit is contained in:
parent
dcef23d0ed
commit
55a38726a3
6706 changed files with 424137 additions and 61608 deletions
15
node_modules/memoizee/LICENSE
generated
vendored
Normal file
15
node_modules/memoizee/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
ISC License
|
||||
|
||||
Copyright (c) 2012-2018, Mariusz Nowak, @medikoo, medikoo.com
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
503
node_modules/memoizee/README.md
generated
vendored
Normal file
503
node_modules/memoizee/README.md
generated
vendored
Normal file
|
@ -0,0 +1,503 @@
|
|||
[![*nix build status][nix-build-image]][nix-build-url]
|
||||
[![Windows build status][win-build-image]][win-build-url]
|
||||
![Transpilation status][transpilation-image]
|
||||
[![npm version][npm-image]][npm-url]
|
||||
|
||||
# Memoizee
|
||||
|
||||
## Complete memoize/cache solution for JavaScript
|
||||
|
||||
_Originally derived from [es5-ext](https://github.com/medikoo/es5-ext) package._
|
||||
|
||||
Memoization is best technique to save on memory or CPU cycles when we deal with repeated operations. For detailed insight see: http://en.wikipedia.org/wiki/Memoization
|
||||
|
||||
### Features
|
||||
|
||||
* Works with any type of function arguments – **no serialization is needed**
|
||||
* Works with [**any length of function arguments**](#arguments-length). Length can be set as fixed or dynamic.
|
||||
* One of the [**fastest**](#benchmarks) available solutions.
|
||||
* Support for [**promises**](#promise-returning-functions) and [**asynchronous functions**](#nodejs-callback-style-functions)
|
||||
* [**Primitive mode**](#primitive-mode) which assures fast performance when arguments are convertible to strings.
|
||||
* [**WeakMap based mode**](#weakmap-based-configurations) for garbage collection friendly configuration
|
||||
* Can be configured [**for methods**](#memoizing-methods) (when `this` counts in)
|
||||
* Cache [**can be cleared manually**](#manual-clean-up) or [**after specified timeout**](#expire-cache-after-given-period-of-time)
|
||||
* Cache size can be **[limited on LRU basis](#limiting-cache-size)**
|
||||
* Optionally [**accepts resolvers**](#argument-resolvers) that normalize function arguments before passing them to underlying function.
|
||||
* Optional [**reference counter mode**](#reference-counter), that allows more sophisticated cache management
|
||||
* [**Profile tool**](#profiling--statistics) that provides valuable usage statistics
|
||||
* Covered by [**over 500 unit tests**](#tests)
|
||||
|
||||
### 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
|
||||
var memoize = require("memoizee");
|
||||
|
||||
var fn = function(one, two, three) {
|
||||
/* ... */
|
||||
};
|
||||
|
||||
memoized = memoize(fn);
|
||||
|
||||
memoized("foo", 3, "bar");
|
||||
memoized("foo", 3, "bar"); // Cache hit
|
||||
```
|
||||
|
||||
__Note__: Invocations that throw exceptions are not cached.
|
||||
|
||||
### Configuration
|
||||
|
||||
All below options can be applied in any combination
|
||||
|
||||
#### Arguments length
|
||||
|
||||
By default fixed number of arguments that function take is assumed (it's read from function's `length` property) this can be overridden:
|
||||
|
||||
```javascript
|
||||
memoized = memoize(fn, { length: 2 });
|
||||
|
||||
memoized("foo"); // Assumed: 'foo', undefined
|
||||
memoized("foo", undefined); // Cache hit
|
||||
|
||||
memoized("foo", 3, {}); // Third argument is ignored (but passed to underlying function)
|
||||
memoized("foo", 3, 13); // Cache hit
|
||||
```
|
||||
|
||||
__Note:__ [Parameters predefined with default values (ES2015+ feature)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters) are not reflected in function's `length`, therefore if you want to memoize them as well, you need to tweak `length` setting accordingly
|
||||
|
||||
Dynamic _length_ behavior can be forced by setting _length_ to `false`, that means memoize will work with any number of arguments.
|
||||
|
||||
```javascript
|
||||
memoized = memoize(fn, { length: false });
|
||||
|
||||
memoized("foo");
|
||||
memoized("foo"); // Cache hit
|
||||
memoized("foo", undefined);
|
||||
memoized("foo", undefined); // Cache hit
|
||||
|
||||
memoized("foo", 3, {});
|
||||
memoized("foo", 3, 13);
|
||||
memoized("foo", 3, 13); // Cache hit
|
||||
```
|
||||
|
||||
#### Primitive mode
|
||||
|
||||
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 conversion. **Mind that this mode will work correctly only if stringified arguments produce unique strings.**
|
||||
|
||||
```javascript
|
||||
memoized = memoize(fn, { primitive: true });
|
||||
|
||||
memoized("/path/one");
|
||||
memoized("/path/one"); // Cache hit
|
||||
```
|
||||
|
||||
#### Cache id resolution (normalization)
|
||||
|
||||
By default cache id for given call is resolved either by:
|
||||
|
||||
* Direct Comparison of values passed in arguments as they are. In such case two different objects, even if their characteristics is exactly same (e.g. `var a = { foo: 'bar' }, b = { foo: 'bar' }`) will be treated as two different values.
|
||||
* Comparison of stringified values of given arguments (`primitive` mode), which serves well, when arguments are expected to be primitive values, or objects that stringify naturally do unique values (e.g. arrays)
|
||||
|
||||
Still above two methods do not serve all cases, e.g. if we want to memoize function where arguments are hash objects which we do not want to compare by instance but by its content.
|
||||
|
||||
##### Writing custom cache id normalizers
|
||||
|
||||
There's a `normalizer` option through which we can pass custom cache id normalization function
|
||||
e.g. if we want to memoize a function where argument is a hash object which we do not want to compare by instance but by its content, then we can achieve it as following:
|
||||
|
||||
```javascript
|
||||
var mfn = memoize(
|
||||
function(hash) {
|
||||
// body of memoized function
|
||||
},
|
||||
{
|
||||
normalizer: function(args) {
|
||||
// args is arguments object as accessible in memoized function
|
||||
return JSON.stringify(args[0]);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
mfn({ foo: "bar" });
|
||||
mfn({ foo: "bar" }); // Cache hit
|
||||
```
|
||||
|
||||
#### Argument resolvers
|
||||
|
||||
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:
|
||||
|
||||
```javascript
|
||||
memoized = memoize(fn, { length: 2, resolvers: [String, Boolean] });
|
||||
|
||||
memoized(12, [1, 2, 3].length);
|
||||
memoized("12", true); // Cache hit
|
||||
memoized(
|
||||
{
|
||||
toString: function() {
|
||||
return "12";
|
||||
}
|
||||
},
|
||||
{}
|
||||
); // Cache hit
|
||||
```
|
||||
|
||||
**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
|
||||
|
||||
##### Promise returning functions
|
||||
|
||||
With _promise_ option we indicate that we memoize a function that returns promise.
|
||||
|
||||
The difference from natural behavior is that in case when promise was rejected with exception,
|
||||
the result is immediately removed from memoize cache, and not kept as further reusable result.
|
||||
|
||||
```javascript
|
||||
var afn = function(a, b) {
|
||||
return new Promise(function(res) {
|
||||
res(a + b);
|
||||
});
|
||||
};
|
||||
memoized = memoize(afn, { promise: true });
|
||||
|
||||
memoized(3, 7);
|
||||
memoized(3, 7); // Cache hit
|
||||
```
|
||||
|
||||
###### Important notice on internal promises handling
|
||||
|
||||
Default handling stands purely on _then_ which has side-effect of muting eventual unhandled rejection notifications.
|
||||
Alternatively we can other (explained below), by stating with `promise` option desired mode:
|
||||
|
||||
```javascript
|
||||
memoized = memoize(afn, { promise: "done:finally" });
|
||||
```
|
||||
|
||||
Supported modes
|
||||
|
||||
* `then` _(default)_. Values are resolved purely by passing callbacks to `promise.then`. **Side effect is that eventual unhandled rejection on given promise
|
||||
come with no logged warning!**, and that to avoid implied error swallowing both states are resolved tick after callbacks were invoked
|
||||
|
||||
* `done` Values are resolved purely by passing callback to `done` method. **Side effect is that eventual unhandled rejection on given promise come with no logged warning!**.
|
||||
|
||||
* `done:finally` The only method that may work with no side-effects assuming that promise implementaion does not throw unconditionally
|
||||
if no _onFailure_ callback was passed to `done`, and promise error was handled by other consumer (this is not commonly implemented _done_ behavior). Otherwise side-effect is that exception is thrown on promise rejection (highly not recommended)
|
||||
|
||||
##### Node.js callback style functions
|
||||
|
||||
With _async_ option we indicate that we memoize asynchronous (Node.js style) function
|
||||
Operations that result with an error are not cached.
|
||||
|
||||
```javascript
|
||||
afn = function(a, b, cb) {
|
||||
setTimeout(function() {
|
||||
cb(null, a + b);
|
||||
}, 200);
|
||||
};
|
||||
memoized = memoize(afn, { async: true });
|
||||
|
||||
memoized(3, 7, function(err, res) {
|
||||
memoized(3, 7, function(err, res) {
|
||||
// Cache hit
|
||||
});
|
||||
});
|
||||
|
||||
memoized(3, 7, function(err, res) {
|
||||
// Cache hit
|
||||
});
|
||||
```
|
||||
|
||||
#### Memoizing methods
|
||||
|
||||
When we are defining a prototype, we may want to define a method that will memoize it's results in relation to each instance. A basic way to obtain that would be:
|
||||
|
||||
```javascript
|
||||
var Foo = function() {
|
||||
this.bar = memoize(this.bar.bind(this), { someOption: true });
|
||||
// ... constructor logic
|
||||
};
|
||||
Foo.prototype.bar = function() {
|
||||
// ... method logic
|
||||
};
|
||||
```
|
||||
|
||||
There's a lazy methods descriptor generator provided:
|
||||
|
||||
```javascript
|
||||
var d = require("d");
|
||||
var memoizeMethods = require("memoizee/methods");
|
||||
|
||||
var Foo = function() {
|
||||
// ... constructor logic
|
||||
};
|
||||
Object.defineProperties(
|
||||
Foo.prototype,
|
||||
memoizeMethods({
|
||||
bar: d(
|
||||
function() {
|
||||
// ... method logic
|
||||
},
|
||||
{ someOption: true }
|
||||
)
|
||||
})
|
||||
);
|
||||
```
|
||||
|
||||
#### WeakMap based configurations
|
||||
|
||||
In this case memoization cache is not bound to memoized function (which we may want to keep forever), but to objects for which given results were generated.
|
||||
|
||||
This mode works only for functions of which first argument is expected to be an object.
|
||||
It can be combined with other options mentioned across documentation. However due to WeakMap specificity global clear is not possible.
|
||||
|
||||
```javascript
|
||||
var memoize = require("memoizee/weak");
|
||||
|
||||
var memoized = memoize(function(obj) {
|
||||
return Object.keys(obj);
|
||||
});
|
||||
|
||||
var obj = { foo: true, bar: false };
|
||||
memoized(obj);
|
||||
memoized(obj); // Cache hit
|
||||
```
|
||||
|
||||
#### Cache handling
|
||||
|
||||
##### Manual clean up:
|
||||
|
||||
Delete data for particular call.
|
||||
|
||||
```javascript
|
||||
memoized.delete("foo", true);
|
||||
```
|
||||
|
||||
Arguments passed to `delete` are treated with same rules as input arguments passed to function
|
||||
|
||||
Clear all cached data:
|
||||
|
||||
```javascript
|
||||
memoized.clear();
|
||||
```
|
||||
|
||||
##### 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 (in milliseconds)
|
||||
|
||||
```javascript
|
||||
memoized = memoize(fn, { maxAge: 1000 }); // 1 second
|
||||
|
||||
memoized("foo", 3);
|
||||
memoized("foo", 3); // Cache hit
|
||||
setTimeout(function() {
|
||||
memoized("foo", 3); // No longer in cache, re-executed
|
||||
memoized("foo", 3); // Cache hit
|
||||
}, 2000);
|
||||
```
|
||||
|
||||
Additionally we may ask to _pre-fetch_ in a background a value that is about to expire. _Pre-fetch_ is invoked only if value is accessed close to its expiry date. By default it needs to be within at least 33% of _maxAge_ timespan before expire:
|
||||
|
||||
```javascript
|
||||
memoized = memoize(fn, { maxAge: 1000, preFetch: true }); // Defaults to 0.33
|
||||
|
||||
memoized("foo", 3);
|
||||
memoized("foo", 3); // Cache hit
|
||||
|
||||
setTimeout(function() {
|
||||
memoized("foo", 3); // Cache hit
|
||||
}, 500);
|
||||
|
||||
setTimeout(function() {
|
||||
memoized("foo", 3); // Cache hit, silently pre-fetched in next tick
|
||||
}, 800);
|
||||
|
||||
setTimeout(function() {
|
||||
memoized("foo", 3); // Cache hit
|
||||
}, 1300);
|
||||
```
|
||||
|
||||
_Pre-fetch_ timespan can be customized:
|
||||
|
||||
```javascript
|
||||
memoized = memoize(fn, { maxAge: 1000, preFetch: 0.6 });
|
||||
|
||||
memoized("foo", 3);
|
||||
memoized("foo", 3); // Cache hit
|
||||
|
||||
setTimeout(function() {
|
||||
memoized("foo", 3); // Cache hit, silently pre-fetched in next tick
|
||||
}, 500);
|
||||
|
||||
setTimeout(function() {
|
||||
memoized("foo", 3); // Cache hit
|
||||
}, 1300);
|
||||
```
|
||||
|
||||
_Thanks [@puzrin](https://github.com/puzrin) for helpful suggestions concerning this functionality_
|
||||
|
||||
##### Reference counter
|
||||
|
||||
We can track number of references returned from cache, and manually delete them. When the last reference is cleared, the cache is purged automatically:
|
||||
|
||||
```javascript
|
||||
memoized = memoize(fn, { refCounter: true });
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
|
||||
The _size_ relates purely to count of results we want to keep in cache, it doesn't relate to memory cost associated with cache value (but such feature is likely to be introduced with next version of memoizee).
|
||||
|
||||
```javascript
|
||||
memoized = memoize(fn, { max: 2 });
|
||||
|
||||
memoized("foo", 3);
|
||||
memoized("bar", 7);
|
||||
memoized("foo", 3); // Cache hit
|
||||
memoized("bar", 7); // Cache hit
|
||||
memoized("lorem", 11); // Cache cleared for 'foo', 3
|
||||
memoized("bar", 7); // Cache hit
|
||||
memoized("foo", 3); // Re-executed, Cache cleared for 'lorem', 11
|
||||
memoized("lorem", 11); // Re-executed, Cache cleared for 'bar', 7
|
||||
memoized("foo", 3); // Cache hit
|
||||
memoized("bar", 7); // Re-executed, Cache cleared for 'lorem', 11
|
||||
```
|
||||
|
||||
##### Registering dispose callback
|
||||
|
||||
You can register a callback to be called on each value removed from the cache:
|
||||
|
||||
```javascript
|
||||
memoized = memoize(fn, {
|
||||
dispose: function(value) {
|
||||
/*…*/
|
||||
}
|
||||
});
|
||||
|
||||
var foo3 = memoized("foo", 3);
|
||||
var bar7 = memoized("bar", 7);
|
||||
memoized.clear("foo", 3); // Dispose called with foo3 value
|
||||
memoized.clear("bar", 7); // Dispose called with bar7 value
|
||||
```
|
||||
|
||||
### Benchmarks
|
||||
|
||||
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:
|
||||
|
||||
$ npm install underscore lodash lru-cache secondary-cache
|
||||
|
||||
Example output taken under Node v0.10.35 on 2011 MBP Pro:
|
||||
|
||||
```
|
||||
Fibonacci 3000 x10:
|
||||
|
||||
1: 15ms Memoizee (primitive mode)
|
||||
2: 15ms Underscore
|
||||
3: 18ms lru-cache LRU (max: 1000)
|
||||
4: 21ms secondary-cache LRU (max: 1000)
|
||||
5: 37ms Lo-dash
|
||||
6: 62ms Memoizee (primitive mode) LRU (max: 1000)
|
||||
7: 163ms Memoizee (object mode) LRU (max: 1000)
|
||||
8: 195ms Memoizee (object mode)
|
||||
```
|
||||
|
||||
### Profiling & Statistics
|
||||
|
||||
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.
|
||||
|
||||
**Module needs to be imported before any memoization (that we want to track) is configured. Mind also that running profile module affects performance, it's best not to use it in production environment**
|
||||
|
||||
```javascript
|
||||
var memProfile = require('memoizee/profile');
|
||||
...
|
||||
...
|
||||
memoize(fn);
|
||||
...
|
||||
memoize(fn, { profileName: 'Some Function' })
|
||||
...
|
||||
memoize(fn, { profileName: 'Another Function' })
|
||||
```
|
||||
|
||||
Access statistics at any time:
|
||||
|
||||
```javascript
|
||||
memProfile.statistics; // Statistics accessible for programmatic use
|
||||
console.log(memProfile.log()); // Output statistics data in readable form
|
||||
```
|
||||
|
||||
Example console output:
|
||||
|
||||
```
|
||||
------------------------------------------------------------
|
||||
Memoize statistics:
|
||||
|
||||
Init Cache %Cache Source location
|
||||
11604 35682 75.46 (all)
|
||||
2112 19901 90.41 Some Function, at /Users/medikoo/Projects/_packages/next/lib/fs/is-ignored.js:276:12
|
||||
2108 9087 81.17 Another Function, at /Users/medikoo/Projects/_packages/next/lib/fs/is-ignored.js:293:10
|
||||
6687 2772 29.31 at /Users/medikoo/Projects/_packages/next/lib/fs/watch.js:125:9
|
||||
697 3922 84.91 at /Users/medikoo/Projects/_packages/next/lib/fs/is-ignored.js:277:15
|
||||
------------------------------------------------------------
|
||||
```
|
||||
|
||||
* _Init_ – Initial hits
|
||||
* _Cache_ – Cache hits
|
||||
* _%Cache_ – What's the percentage of cache hits (of all function calls)
|
||||
* _Source location_ – Where in the source code given memoization was initialized
|
||||
|
||||
### Tests
|
||||
|
||||
$ npm test
|
||||
|
||||
Project cross-browser compatibility to be supported by:
|
||||
|
||||
<a href="https://browserstack.com"><img src="https://bstacksupport.zendesk.com/attachments/token/Pj5uf2x5GU9BvWErqAr51Jh2R/?name=browserstack-logo-600x315.png" height="150" /></a>
|
||||
|
||||
## Security contact information
|
||||
|
||||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-memoizee?utm_source=npm-memoizee&utm_medium=referral&utm_campaign=readme">Get professional support for d with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
||||
|
||||
### 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
|
||||
|
||||
[nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/memoizee/branches/master/shields_badge.svg
|
||||
[nix-build-url]: https://semaphoreci.com/medikoo-org/memoizee
|
||||
[win-build-image]: https://ci.appveyor.com/api/projects/status/hsxubnbwe89c26bu?svg=true
|
||||
[win-build-url]: https://ci.appveyor.com/project/medikoo/memoizee
|
||||
[transpilation-image]: https://img.shields.io/badge/transpilation-free-brightgreen.svg
|
||||
[npm-image]: https://img.shields.io/npm/v/memoizee.svg
|
||||
[npm-url]: https://www.npmjs.com/package/memoizee
|
154
node_modules/memoizee/ext/async.js
generated
vendored
Normal file
154
node_modules/memoizee/ext/async.js
generated
vendored
Normal file
|
@ -0,0 +1,154 @@
|
|||
/* eslint consistent-this: 0, no-shadow:0, no-eq-null: 0, eqeqeq: 0, no-unused-vars: 0 */
|
||||
|
||||
// Support for asynchronous functions
|
||||
|
||||
"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 slice = Array.prototype.slice, apply = Function.prototype.apply, create = Object.create;
|
||||
|
||||
require("../lib/registered-extensions").async = function (tbi, conf) {
|
||||
var waiting = create(null)
|
||||
, cache = create(null)
|
||||
, base = conf.memoized
|
||||
, original = conf.original
|
||||
, currentCallback
|
||||
, currentContext
|
||||
, currentArgs;
|
||||
|
||||
// Initial
|
||||
conf.memoized = defineLength(function (arg) {
|
||||
var args = arguments, last = args[args.length - 1];
|
||||
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) {}
|
||||
|
||||
// From cache (sync)
|
||||
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];
|
||||
else waiting[id].push(currentCallback);
|
||||
currentCallback = null;
|
||||
return;
|
||||
}
|
||||
|
||||
// Resolved, assure next tick invocation
|
||||
cb = currentCallback;
|
||||
context = currentContext;
|
||||
args = currentArgs;
|
||||
currentCallback = currentContext = currentArgs = null;
|
||||
nextTick(function () {
|
||||
var data;
|
||||
if (hasOwnProperty.call(cache, id)) {
|
||||
data = cache[id];
|
||||
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
|
||||
currentCallback = cb;
|
||||
currentContext = context;
|
||||
currentArgs = args;
|
||||
base.apply(context, args);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Not from cache
|
||||
conf.original = function () {
|
||||
var args, cb, origCb, result;
|
||||
if (!currentCallback) return apply.call(original, this, arguments);
|
||||
args = aFrom(arguments);
|
||||
cb = function self(err) {
|
||||
var cb, args, id = self.id;
|
||||
if (id == null) {
|
||||
// Shouldn't happen, means async callback was called sync way
|
||||
nextTick(apply.bind(self, this, arguments));
|
||||
return undefined;
|
||||
}
|
||||
delete self.id;
|
||||
cb = waiting[id];
|
||||
delete waiting[id];
|
||||
if (!cb) {
|
||||
// Already processed,
|
||||
// outcome of race condition: asyncFn(1, cb), asyncFn.clear(), asyncFn(1, cb)
|
||||
return undefined;
|
||||
}
|
||||
args = aFrom(arguments);
|
||||
if (conf.has(id)) {
|
||||
if (err) {
|
||||
conf.delete(id);
|
||||
} else {
|
||||
cache[id] = { context: this, args: args };
|
||||
conf.emit("setasync", id, typeof cb === "function" ? 1 : cb.length);
|
||||
}
|
||||
}
|
||||
if (typeof cb === "function") {
|
||||
result = apply.call(cb, this, args);
|
||||
} else {
|
||||
cb.forEach(function (cb) { result = apply.call(cb, this, args); }, this);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
origCb = currentCallback;
|
||||
currentCallback = currentContext = currentArgs = null;
|
||||
args.push(cb);
|
||||
result = apply.call(original, this, args);
|
||||
cb.cb = origCb;
|
||||
currentCallback = cb;
|
||||
return result;
|
||||
};
|
||||
|
||||
// After not from cache call
|
||||
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];
|
||||
else waiting[id].push(currentCallback.cb);
|
||||
} else {
|
||||
waiting[id] = currentCallback.cb;
|
||||
}
|
||||
delete currentCallback.cb;
|
||||
currentCallback.id = id;
|
||||
currentCallback = null;
|
||||
});
|
||||
|
||||
// On delete
|
||||
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
|
||||
// gracefully pass to callback
|
||||
if (hasOwnProperty.call(waiting, id)) return;
|
||||
if (!cache[id]) return;
|
||||
result = cache[id];
|
||||
delete cache[id];
|
||||
conf.emit("deleteasync", id, slice.call(result.args, 1));
|
||||
});
|
||||
|
||||
// On clear
|
||||
conf.on("clear", function () {
|
||||
var oldCache = cache;
|
||||
cache = create(null);
|
||||
conf.emit(
|
||||
"clearasync", objectMap(oldCache, function (data) { return slice.call(data.args, 1); })
|
||||
);
|
||||
});
|
||||
};
|
33
node_modules/memoizee/ext/dispose.js
generated
vendored
Normal file
33
node_modules/memoizee/ext/dispose.js
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Call dispose callback on each cache purge
|
||||
|
||||
"use strict";
|
||||
|
||||
var callable = require("es5-ext/object/valid-callable")
|
||||
, forEach = require("es5-ext/object/for-each")
|
||||
, extensions = require("../lib/registered-extensions")
|
||||
|
||||
, apply = Function.prototype.apply;
|
||||
|
||||
extensions.dispose = function (dispose, conf, options) {
|
||||
var del;
|
||||
callable(dispose);
|
||||
if ((options.async && extensions.async) || (options.promise && extensions.promise)) {
|
||||
conf.on("deleteasync", del = function (id, resultArray) {
|
||||
apply.call(dispose, null, resultArray);
|
||||
});
|
||||
conf.on("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);
|
||||
});
|
||||
});
|
||||
};
|
90
node_modules/memoizee/ext/max-age.js
generated
vendored
Normal file
90
node_modules/memoizee/ext/max-age.js
generated
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
/* eslint consistent-this: 0 */
|
||||
|
||||
// Timeout cached values
|
||||
|
||||
"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 noop = Function.prototype, max = Math.max, min = Math.min, create = Object.create;
|
||||
|
||||
extensions.maxAge = function (maxAge, conf, options) {
|
||||
var timeouts, postfix, preFetchAge, preFetchTimeouts;
|
||||
|
||||
maxAge = timeout(maxAge);
|
||||
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);
|
||||
if (typeof timeouts[id].unref === "function") timeouts[id].unref();
|
||||
if (!preFetchTimeouts) return;
|
||||
if (preFetchTimeouts[id]) {
|
||||
if (preFetchTimeouts[id] !== "nextTick") clearTimeout(preFetchTimeouts[id]);
|
||||
}
|
||||
preFetchTimeouts[id] = setTimeout(function () {
|
||||
delete preFetchTimeouts[id];
|
||||
}, preFetchAge);
|
||||
if (typeof preFetchTimeouts[id].unref === "function") preFetchTimeouts[id].unref();
|
||||
});
|
||||
conf.on("delete" + postfix, function (id) {
|
||||
clearTimeout(timeouts[id]);
|
||||
delete timeouts[id];
|
||||
if (!preFetchTimeouts) return;
|
||||
if (preFetchTimeouts[id] !== "nextTick") clearTimeout(preFetchTimeouts[id]);
|
||||
delete preFetchTimeouts[id];
|
||||
});
|
||||
|
||||
if (options.preFetch) {
|
||||
if (options.preFetch === true || isNaN(options.preFetch)) {
|
||||
preFetchAge = 0.333;
|
||||
} else {
|
||||
preFetchAge = max(min(Number(options.preFetch), 1), 0);
|
||||
}
|
||||
if (preFetchAge) {
|
||||
preFetchTimeouts = {};
|
||||
preFetchAge = (1 - preFetchAge) * maxAge;
|
||||
conf.on("get" + postfix, function (id, args, context) {
|
||||
if (!preFetchTimeouts[id]) {
|
||||
preFetchTimeouts[id] = "nextTick";
|
||||
nextTick(function () {
|
||||
var result;
|
||||
if (preFetchTimeouts[id] !== "nextTick") return;
|
||||
delete preFetchTimeouts[id];
|
||||
conf.delete(id);
|
||||
if (options.async) {
|
||||
args = aFrom(args);
|
||||
args.push(noop);
|
||||
}
|
||||
result = conf.memoized.apply(context, args);
|
||||
if (options.promise) {
|
||||
// Supress eventual error warnings
|
||||
if (isPromise(result)) {
|
||||
if (typeof result.done === "function") result.done(noop, noop);
|
||||
else result.then(noop, noop);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
conf.on("clear" + postfix, function () {
|
||||
forEach(timeouts, function (id) { clearTimeout(id); });
|
||||
timeouts = {};
|
||||
if (preFetchTimeouts) {
|
||||
forEach(preFetchTimeouts, function (id) { if (id !== "nextTick") clearTimeout(id); });
|
||||
preFetchTimeouts = {};
|
||||
}
|
||||
});
|
||||
};
|
27
node_modules/memoizee/ext/max.js
generated
vendored
Normal file
27
node_modules/memoizee/ext/max.js
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Limit cache size, LRU (least recently used) algorithm.
|
||||
|
||||
"use strict";
|
||||
|
||||
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;
|
||||
|
||||
max = toPosInteger(max);
|
||||
if (!max) return;
|
||||
|
||||
queue = lruQueue(max);
|
||||
postfix = (options.async && extensions.async) || (options.promise && extensions.promise)
|
||||
? "async" : "";
|
||||
|
||||
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);
|
||||
};
|
147
node_modules/memoizee/ext/promise.js
generated
vendored
Normal file
147
node_modules/memoizee/ext/promise.js
generated
vendored
Normal file
|
@ -0,0 +1,147 @@
|
|||
/* eslint max-statements: 0 */
|
||||
|
||||
// Support for functions returning promise
|
||||
|
||||
"use strict";
|
||||
|
||||
var objectMap = require("es5-ext/object/map")
|
||||
, primitiveSet = require("es5-ext/object/primitive-set")
|
||||
, ensureString = require("es5-ext/object/validate-stringifiable-value")
|
||||
, toShortString = require("es5-ext/to-short-string-representation")
|
||||
, isPromise = require("is-promise")
|
||||
, nextTick = require("next-tick");
|
||||
|
||||
var create = Object.create
|
||||
, supportedModes = primitiveSet("then", "then:finally", "done", "done:finally");
|
||||
|
||||
require("../lib/registered-extensions").promise = function (mode, conf) {
|
||||
var waiting = create(null), cache = create(null), promises = create(null);
|
||||
|
||||
if (mode === true) {
|
||||
mode = null;
|
||||
} else {
|
||||
mode = ensureString(mode);
|
||||
if (!supportedModes[mode]) {
|
||||
throw new TypeError("'" + toShortString(mode) + "' is not valid promise mode");
|
||||
}
|
||||
}
|
||||
|
||||
// After not from cache call
|
||||
conf.on("set", function (id, ignore, promise) {
|
||||
var isFailed = false;
|
||||
|
||||
if (!isPromise(promise)) {
|
||||
// Non promise result
|
||||
cache[id] = promise;
|
||||
conf.emit("setasync", id, 1);
|
||||
return;
|
||||
}
|
||||
waiting[id] = 1;
|
||||
promises[id] = promise;
|
||||
var onSuccess = function (result) {
|
||||
var count = waiting[id];
|
||||
if (isFailed) {
|
||||
throw new Error(
|
||||
"Memoizee error: Detected unordered then|done & finally resolution, which " +
|
||||
"in turn makes proper detection of success/failure impossible (when in " +
|
||||
"'done:finally' mode)\n" +
|
||||
"Consider to rely on 'then' or 'done' mode instead."
|
||||
);
|
||||
}
|
||||
if (!count) return; // Deleted from cache before resolved
|
||||
delete waiting[id];
|
||||
cache[id] = result;
|
||||
conf.emit("setasync", id, count);
|
||||
};
|
||||
var onFailure = function () {
|
||||
isFailed = true;
|
||||
if (!waiting[id]) return; // Deleted from cache (or succeed in case of finally)
|
||||
delete waiting[id];
|
||||
delete promises[id];
|
||||
conf.delete(id);
|
||||
};
|
||||
|
||||
var resolvedMode = mode;
|
||||
if (!resolvedMode) resolvedMode = "then";
|
||||
|
||||
if (resolvedMode === "then") {
|
||||
var nextTickFailure = function () { nextTick(onFailure); };
|
||||
// Eventual finally needs to be attached to non rejected promise
|
||||
// (so we not force propagation of unhandled rejection)
|
||||
promise = promise.then(function (result) {
|
||||
nextTick(onSuccess.bind(this, result));
|
||||
}, nextTickFailure);
|
||||
// If `finally` is a function we attach to it to remove cancelled promises.
|
||||
if (typeof promise.finally === "function") {
|
||||
promise.finally(nextTickFailure);
|
||||
}
|
||||
} else if (resolvedMode === "done") {
|
||||
// Not recommended, as it may mute any eventual "Unhandled error" events
|
||||
if (typeof promise.done !== "function") {
|
||||
throw new Error(
|
||||
"Memoizee error: Retrieved promise does not implement 'done' " +
|
||||
"in 'done' mode"
|
||||
);
|
||||
}
|
||||
promise.done(onSuccess, onFailure);
|
||||
} else if (resolvedMode === "done:finally") {
|
||||
// The only mode with no side effects assuming library does not throw unconditionally
|
||||
// for rejected promises.
|
||||
if (typeof promise.done !== "function") {
|
||||
throw new Error(
|
||||
"Memoizee error: Retrieved promise does not implement 'done' " +
|
||||
"in 'done:finally' mode"
|
||||
);
|
||||
}
|
||||
if (typeof promise.finally !== "function") {
|
||||
throw new Error(
|
||||
"Memoizee error: Retrieved promise does not implement 'finally' " +
|
||||
"in 'done:finally' mode"
|
||||
);
|
||||
}
|
||||
promise.done(onSuccess);
|
||||
promise.finally(onFailure);
|
||||
}
|
||||
});
|
||||
|
||||
// From cache (sync)
|
||||
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); };
|
||||
if (isPromise(promise)) {
|
||||
if (typeof promise.done === "function") promise.done(emit);
|
||||
else {
|
||||
promise.then(function () { nextTick(emit); });
|
||||
}
|
||||
} else {
|
||||
emit();
|
||||
}
|
||||
});
|
||||
|
||||
// On delete
|
||||
conf.on("delete", function (id) {
|
||||
delete promises[id];
|
||||
if (waiting[id]) {
|
||||
delete waiting[id];
|
||||
return; // Not yet resolved
|
||||
}
|
||||
if (!hasOwnProperty.call(cache, id)) return;
|
||||
var result = cache[id];
|
||||
delete cache[id];
|
||||
conf.emit("deleteasync", id, [result]);
|
||||
});
|
||||
|
||||
// On clear
|
||||
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]; }));
|
||||
});
|
||||
};
|
48
node_modules/memoizee/ext/ref-counter.js
generated
vendored
Normal file
48
node_modules/memoizee/ext/ref-counter.js
generated
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
// Reference counter, useful for garbage collector like functionality
|
||||
|
||||
"use strict";
|
||||
|
||||
var d = require("d")
|
||||
, extensions = require("../lib/registered-extensions")
|
||||
|
||||
, create = Object.create, defineProperties = Object.defineProperties;
|
||||
|
||||
extensions.refCounter = function (ignore, conf, options) {
|
||||
var cache, postfix;
|
||||
|
||||
cache = create(null);
|
||||
postfix = (options.async && extensions.async) || (options.promise && extensions.promise)
|
||||
? "async" : "";
|
||||
|
||||
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 () {
|
||||
var id = conf.get(arguments);
|
||||
if (id === null) return null;
|
||||
if (!cache[id]) return null;
|
||||
if (!--cache[id]) {
|
||||
conf.delete(id);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}),
|
||||
getRefCount: d(function () {
|
||||
var id = conf.get(arguments);
|
||||
if (id === null) return 0;
|
||||
if (!cache[id]) return 0;
|
||||
return cache[id];
|
||||
})
|
||||
});
|
||||
};
|
34
node_modules/memoizee/index.js
generated
vendored
Normal file
34
node_modules/memoizee/index.js
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
"use strict";
|
||||
|
||||
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;
|
||||
|
||||
if (!options.normalizer) {
|
||||
length = options.length = resolveLength(options.length, fn.length, options.async);
|
||||
if (length !== 0) {
|
||||
if (options.primitive) {
|
||||
if (length === false) {
|
||||
options.normalizer = require("./normalizers/primitive");
|
||||
} else if (length > 1) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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");
|
||||
|
||||
return plain(fn, options);
|
||||
};
|
182
node_modules/memoizee/lib/configure-map.js
generated
vendored
Normal file
182
node_modules/memoizee/lib/configure-map.js
generated
vendored
Normal file
|
@ -0,0 +1,182 @@
|
|||
/* eslint no-eq-null: 0, eqeqeq: 0, no-unused-vars: 0 */
|
||||
|
||||
"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 apply = Function.prototype.apply
|
||||
, call = Function.prototype.call
|
||||
, create = Object.create
|
||||
, defineProperties = Object.defineProperties
|
||||
, on = ee.on
|
||||
, emit = ee.emit;
|
||||
|
||||
module.exports = function (original, length, options) {
|
||||
var cache = create(null)
|
||||
, conf
|
||||
, memLength
|
||||
, get
|
||||
, set
|
||||
, del
|
||||
, clear
|
||||
, extDel
|
||||
, extGet
|
||||
, extHas
|
||||
, normalizer
|
||||
, getListeners
|
||||
, setListeners
|
||||
, deleteListeners
|
||||
, memoized
|
||||
, resolve;
|
||||
if (length !== false) memLength = length;
|
||||
else if (isNaN(original.length)) memLength = 1;
|
||||
else memLength = original.length;
|
||||
|
||||
if (options.normalizer) {
|
||||
normalizer = resolveNormalize(options.normalizer);
|
||||
get = normalizer.get;
|
||||
set = normalizer.set;
|
||||
del = normalizer.delete;
|
||||
clear = normalizer.clear;
|
||||
}
|
||||
if (options.resolvers != null) resolve = resolveResolve(options.resolvers);
|
||||
|
||||
if (get) {
|
||||
memoized = defineLength(function (arg) {
|
||||
var id, result, args = arguments;
|
||||
if (resolve) args = resolve(args);
|
||||
id = get(args);
|
||||
if (id !== null) {
|
||||
if (hasOwnProperty.call(cache, id)) {
|
||||
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 (id === null) {
|
||||
id = get(args);
|
||||
if (id !== null) throw customError("Circular invocation", "CIRCULAR_INVOCATION");
|
||||
id = set(args);
|
||||
} else if (hasOwnProperty.call(cache, id)) {
|
||||
throw customError("Circular invocation", "CIRCULAR_INVOCATION");
|
||||
}
|
||||
cache[id] = 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);
|
||||
return cache.data;
|
||||
}
|
||||
if (arguments.length) result = apply.call(original, this, arguments);
|
||||
else result = call.call(original, this);
|
||||
if (hasOwnProperty.call(cache, "data")) {
|
||||
throw customError("Circular invocation", "CIRCULAR_INVOCATION");
|
||||
}
|
||||
cache.data = result;
|
||||
if (setListeners) conf.emit("set", "data", null, result);
|
||||
return result;
|
||||
};
|
||||
} else {
|
||||
memoized = function (arg) {
|
||||
var result, args = arguments, id;
|
||||
if (resolve) args = resolve(arguments);
|
||||
id = String(args[0]);
|
||||
if (hasOwnProperty.call(cache, id)) {
|
||||
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");
|
||||
}
|
||||
cache[id] = result;
|
||||
if (setListeners) conf.emit("set", id, null, result);
|
||||
return result;
|
||||
};
|
||||
}
|
||||
conf = {
|
||||
original: original,
|
||||
memoized: memoized,
|
||||
profileName: options.profileName,
|
||||
get: function (args) {
|
||||
if (resolve) args = resolve(args);
|
||||
if (get) return get(args);
|
||||
return String(args[0]);
|
||||
},
|
||||
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);
|
||||
},
|
||||
clear: function () {
|
||||
var oldCache = cache;
|
||||
if (clear) clear();
|
||||
cache = create(null);
|
||||
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;
|
||||
return on.call(this, type, listener);
|
||||
},
|
||||
emit: emit,
|
||||
updateEnv: function () { original = conf.original; }
|
||||
};
|
||||
if (get) {
|
||||
extDel = defineLength(function (arg) {
|
||||
var id, args = arguments;
|
||||
if (resolve) args = resolve(args);
|
||||
id = get(args);
|
||||
if (id === null) return;
|
||||
conf.delete(id);
|
||||
}, memLength);
|
||||
} else if (length === 0) {
|
||||
extDel = function () { return conf.delete("data"); };
|
||||
} else {
|
||||
extDel = function (arg) {
|
||||
if (resolve) arg = resolve(arguments)[0];
|
||||
return conf.delete(arg);
|
||||
};
|
||||
}
|
||||
extGet = defineLength(function () {
|
||||
var id, args = arguments;
|
||||
if (length === 0) return cache.data;
|
||||
if (resolve) args = resolve(args);
|
||||
if (get) id = get(args);
|
||||
else id = String(args[0]);
|
||||
return cache[id];
|
||||
});
|
||||
extHas = defineLength(function () {
|
||||
var id, args = arguments;
|
||||
if (length === 0) return conf.has("data");
|
||||
if (resolve) args = resolve(args);
|
||||
if (get) id = get(args);
|
||||
else id = String(args[0]);
|
||||
if (id === null) return false;
|
||||
return conf.has(id);
|
||||
});
|
||||
defineProperties(memoized, {
|
||||
__memoized__: d(true),
|
||||
delete: d(extDel),
|
||||
clear: d(conf.clear),
|
||||
_get: d(extGet),
|
||||
_has: d(extHas)
|
||||
});
|
||||
return conf;
|
||||
};
|
32
node_modules/memoizee/lib/methods.js
generated
vendored
Normal file
32
node_modules/memoizee/lib/methods.js
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
"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");
|
||||
|
||||
module.exports = function (memoize) {
|
||||
return function (props) {
|
||||
forEach(props, function (desc) {
|
||||
var fn = callable(desc.value), length;
|
||||
desc.value = function (options) {
|
||||
if (options.getNormalizer) {
|
||||
options = normalizeOpts(options);
|
||||
if (length === undefined) {
|
||||
length = resolveLength(
|
||||
options.length,
|
||||
fn.length,
|
||||
options.async && extensions.async
|
||||
);
|
||||
}
|
||||
options.normalizer = options.getNormalizer(length);
|
||||
delete options.getNormalizer;
|
||||
}
|
||||
return memoize(fn.bind(this), options);
|
||||
};
|
||||
});
|
||||
return lazy(props);
|
||||
};
|
||||
};
|
1
node_modules/memoizee/lib/registered-extensions.js
generated
vendored
Normal file
1
node_modules/memoizee/lib/registered-extensions.js
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
"use strict";
|
15
node_modules/memoizee/lib/resolve-length.js
generated
vendored
Normal file
15
node_modules/memoizee/lib/resolve-length.js
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
"use strict";
|
||||
|
||||
var toPosInt = require("es5-ext/number/to-pos-integer");
|
||||
|
||||
module.exports = function (optsLength, fnLength, isAsync) {
|
||||
var length;
|
||||
if (isNaN(optsLength)) {
|
||||
length = fnLength;
|
||||
if (!(length >= 0)) return 1;
|
||||
if (isAsync && length) return length - 1;
|
||||
return length;
|
||||
}
|
||||
if (optsLength === false) return false;
|
||||
return toPosInt(optsLength);
|
||||
};
|
17
node_modules/memoizee/lib/resolve-normalize.js
generated
vendored
Normal file
17
node_modules/memoizee/lib/resolve-normalize.js
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
var callable = require("es5-ext/object/valid-callable");
|
||||
|
||||
module.exports = function (userNormalizer) {
|
||||
var normalizer;
|
||||
if (typeof userNormalizer === "function") return { set: userNormalizer, get: userNormalizer };
|
||||
normalizer = { get: callable(userNormalizer.get) };
|
||||
if (userNormalizer.set !== undefined) {
|
||||
normalizer.set = callable(userNormalizer.set);
|
||||
if (userNormalizer.delete) normalizer.delete = callable(userNormalizer.delete);
|
||||
if (userNormalizer.clear) normalizer.clear = callable(userNormalizer.clear);
|
||||
return normalizer;
|
||||
}
|
||||
normalizer.set = normalizer.get;
|
||||
return normalizer;
|
||||
};
|
21
node_modules/memoizee/lib/resolve-resolve.js
generated
vendored
Normal file
21
node_modules/memoizee/lib/resolve-resolve.js
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
"use strict";
|
||||
|
||||
var toArray = require("es5-ext/array/to-array")
|
||||
, isValue = require("es5-ext/object/is-value")
|
||||
, callable = require("es5-ext/object/valid-callable");
|
||||
|
||||
var slice = Array.prototype.slice, resolveArgs;
|
||||
|
||||
resolveArgs = function (args) {
|
||||
return this.map(function (resolve, i) {
|
||||
return resolve ? resolve(args[i]) : args[i];
|
||||
}).concat(slice.call(args, this.length));
|
||||
};
|
||||
|
||||
module.exports = function (resolvers) {
|
||||
resolvers = toArray(resolvers);
|
||||
resolvers.forEach(function (resolve) {
|
||||
if (isValue(resolve)) callable(resolve);
|
||||
});
|
||||
return resolveArgs.bind(resolvers);
|
||||
};
|
134
node_modules/memoizee/lib/weak.js
generated
vendored
Normal file
134
node_modules/memoizee/lib/weak.js
generated
vendored
Normal file
|
@ -0,0 +1,134 @@
|
|||
"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 slice = Array.prototype.slice, defineProperties = Object.defineProperties;
|
||||
|
||||
module.exports = function (memoize) {
|
||||
return function (fn/*, options*/) {
|
||||
var map, length, options = normalizeOpts(arguments[1]), memoized, resolve, normalizer;
|
||||
|
||||
callable(fn);
|
||||
|
||||
// Do not memoize already memoized function
|
||||
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;
|
||||
map = new WeakMap();
|
||||
|
||||
if (options.resolvers) resolve = resolveResolve(options.resolvers);
|
||||
if (options.normalizer) normalizer = resolveNormalize(options.normalizer);
|
||||
|
||||
if (
|
||||
length === 1 &&
|
||||
!normalizer &&
|
||||
!options.async &&
|
||||
!options.dispose &&
|
||||
!options.maxAge &&
|
||||
!options.max &&
|
||||
!options.refCounter
|
||||
) {
|
||||
return defineProperties(
|
||||
function (obj) {
|
||||
var result, args = arguments;
|
||||
if (resolve) args = resolve(args);
|
||||
obj = args[0];
|
||||
if (map.has(obj)) return map.get(obj);
|
||||
result = fn.apply(this, args);
|
||||
if (map.has(obj)) {
|
||||
throw customError("Circular invocation", "CIRCULAR_INVOCATION");
|
||||
}
|
||||
map.set(obj, result);
|
||||
return result;
|
||||
},
|
||||
{
|
||||
__memoized__: d(true),
|
||||
delete: d(function (obj) {
|
||||
if (resolve) obj = resolve(arguments)[0];
|
||||
return map.delete(obj);
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
memoized = defineProperties(
|
||||
defineLength(function (obj) {
|
||||
var memoizer, args = arguments;
|
||||
if (resolve) {
|
||||
args = resolve(args);
|
||||
obj = args[0];
|
||||
}
|
||||
memoizer = map.get(obj);
|
||||
if (!memoizer) {
|
||||
if (normalizer) {
|
||||
options = copy(options);
|
||||
options.normalizer = copy(normalizer);
|
||||
options.normalizer.get = partial.call(options.normalizer.get, obj);
|
||||
options.normalizer.set = partial.call(options.normalizer.set, obj);
|
||||
if (options.normalizer.delete) {
|
||||
options.normalizer.delete = partial.call(
|
||||
options.normalizer.delete, obj
|
||||
);
|
||||
}
|
||||
}
|
||||
map.set(obj, memoizer = memoize(partial.call(fn, obj), options));
|
||||
}
|
||||
return memoizer.apply(this, slice.call(args, 1));
|
||||
}, length),
|
||||
{
|
||||
__memoized__: d(true),
|
||||
delete: d(
|
||||
defineLength(function (obj) {
|
||||
var memoizer, args = arguments;
|
||||
if (resolve) {
|
||||
args = resolve(args);
|
||||
obj = args[0];
|
||||
}
|
||||
memoizer = map.get(obj);
|
||||
if (!memoizer) return;
|
||||
memoizer.delete.apply(this, slice.call(args, 1));
|
||||
}, length)
|
||||
)
|
||||
}
|
||||
);
|
||||
if (!options.refCounter) return memoized;
|
||||
defineProperties(memoized, {
|
||||
deleteRef: d(
|
||||
defineLength(function (obj) {
|
||||
var memoizer, args = arguments;
|
||||
if (resolve) {
|
||||
args = resolve(args);
|
||||
obj = args[0];
|
||||
}
|
||||
memoizer = map.get(obj);
|
||||
if (!memoizer) return null;
|
||||
return memoizer.deleteRef.apply(this, slice.call(args, 1));
|
||||
}, length)
|
||||
),
|
||||
getRefCount: d(
|
||||
defineLength(function (obj) {
|
||||
var memoizer, args = arguments;
|
||||
if (resolve) {
|
||||
args = resolve(args);
|
||||
obj = args[0];
|
||||
}
|
||||
memoizer = map.get(obj);
|
||||
if (!memoizer) return 0;
|
||||
return memoizer.getRefCount.apply(this, slice.call(args, 1));
|
||||
}, length)
|
||||
)
|
||||
});
|
||||
return memoized;
|
||||
};
|
||||
};
|
3
node_modules/memoizee/methods-plain.js
generated
vendored
Normal file
3
node_modules/memoizee/methods-plain.js
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = require("./lib/methods")(require("./plain"));
|
3
node_modules/memoizee/methods.js
generated
vendored
Normal file
3
node_modules/memoizee/methods.js
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = require("./lib/methods")(require("./"));
|
16
node_modules/memoizee/node_modules/next-tick/.editorconfig
generated
vendored
Normal file
16
node_modules/memoizee/node_modules/next-tick/.editorconfig
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
# EditorConfig is awesome: http://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = tab
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
trim_trailing_whitespace = false
|
1
node_modules/memoizee/node_modules/next-tick/.github/FUNDING.yml
generated
vendored
Normal file
1
node_modules/memoizee/node_modules/next-tick/.github/FUNDING.yml
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
tidelift: "npm/next-tick"
|
16
node_modules/memoizee/node_modules/next-tick/.lint
generated
vendored
Normal file
16
node_modules/memoizee/node_modules/next-tick/.lint
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
@root
|
||||
|
||||
module
|
||||
es5
|
||||
|
||||
indent 2
|
||||
maxlen 100
|
||||
tabs
|
||||
|
||||
ass
|
||||
bitwise
|
||||
nomen
|
||||
plusplus
|
||||
vars
|
||||
|
||||
predef+ queueMicrotask, process, setImmediate, setTimeout, clearTimeout, document, MutationObserver, WebKitMutationObserver
|
13
node_modules/memoizee/node_modules/next-tick/CHANGELOG.md
generated
vendored
Normal file
13
node_modules/memoizee/node_modules/next-tick/CHANGELOG.md
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
## [1.1.0](https://github.com/medikoo/next-tick/compare/v1.0.0...v1.1.0) (2020-02-11)
|
||||
|
||||
### Features
|
||||
|
||||
* Add support for queueMicrotask (Closes [#13](https://github.com/medikoo/next-tick/issues/13)) ([471986e](https://github.com/medikoo/next-tick/commit/471986ee5f7179a498850cc03138a5ed5b9a248c))
|
||||
|
||||
## Changelog for previous versions
|
||||
|
||||
See `CHANGES` file
|
28
node_modules/memoizee/node_modules/next-tick/CHANGES
generated
vendored
Normal file
28
node_modules/memoizee/node_modules/next-tick/CHANGES
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
For recent changelog see CHANGELOG.md
|
||||
|
||||
-----
|
||||
|
||||
v1.0.0 -- 2016.06.09
|
||||
* In case MutationObserver based solution ensure all callbacks are propagated
|
||||
even if any on the way crashes (fixes #3)
|
||||
* Support older engines (as IE8) which see typeof setTimeout as 'object'
|
||||
* Fix spelling of LICENSE
|
||||
* Configure lint scripts
|
||||
|
||||
v0.2.2 -- 2014.04.18
|
||||
- Do not rely on es5-ext's valid-callable. Replace it with simple internal function
|
||||
- In MutationObserver fallback rely on text node instead of attribute and assure
|
||||
mutation event is invoked by real change of data
|
||||
|
||||
v0.2.1 -- 2014.02.24
|
||||
- Fix case in import path
|
||||
|
||||
v0.2.0 -- 2014.02.24
|
||||
- Assure microtask resultion if MutationObserver is available (thanks @Raynos) #1
|
||||
- Unify validation of callback. TypeError is throw for any non callable input
|
||||
- Move main module from `lib` to root directory
|
||||
- Improve documentation
|
||||
- Remove Makefile (it's environment agnostic pacakge)
|
||||
|
||||
v0.1.0 -- 2012.08.29
|
||||
Initial
|
15
node_modules/memoizee/node_modules/next-tick/LICENSE
generated
vendored
Normal file
15
node_modules/memoizee/node_modules/next-tick/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
ISC License
|
||||
|
||||
Copyright (c) 2012-2020, Mariusz Nowak, @medikoo, medikoo.com
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
41
node_modules/memoizee/node_modules/next-tick/README.md
generated
vendored
Normal file
41
node_modules/memoizee/node_modules/next-tick/README.md
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
# next-tick
|
||||
## Environment agnostic nextTick polyfill
|
||||
|
||||
To be used in environment agnostic modules that need nextTick functionality.
|
||||
|
||||
- When run in Node.js `process.nextTick` is used
|
||||
- In modern engines, microtask resolution is guaranteed by `queueMicrotask`
|
||||
- In older browsers, `MutationObserver` is used as a fallback
|
||||
- In other engines `setImmediate` or `setTimeout(fn, 0)` is used as fallback.
|
||||
- If none of the above is supported module resolves to `null`
|
||||
|
||||
## Installation
|
||||
### NPM
|
||||
|
||||
In your project path:
|
||||
|
||||
$ npm install next-tick
|
||||
|
||||
#### Browser
|
||||
|
||||
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/)
|
||||
|
||||
## Tests [](https://travis-ci.org/medikoo/next-tick)
|
||||
|
||||
$ npm test
|
||||
|
||||
## Security contact information
|
||||
|
||||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-next-tick?utm_source=npm-next-tick&utm_medium=referral&utm_campaign=readme">Get professional support for d with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
74
node_modules/memoizee/node_modules/next-tick/index.js
generated
vendored
Normal file
74
node_modules/memoizee/node_modules/next-tick/index.js
generated
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
'use strict';
|
||||
|
||||
var ensureCallable = function (fn) {
|
||||
if (typeof fn !== 'function') throw new TypeError(fn + " is not a function");
|
||||
return fn;
|
||||
};
|
||||
|
||||
var byObserver = function (Observer) {
|
||||
var node = document.createTextNode(''), queue, currentQueue, i = 0;
|
||||
new Observer(function () {
|
||||
var callback;
|
||||
if (!queue) {
|
||||
if (!currentQueue) return;
|
||||
queue = currentQueue;
|
||||
} else if (currentQueue) {
|
||||
queue = currentQueue.concat(queue);
|
||||
}
|
||||
currentQueue = queue;
|
||||
queue = null;
|
||||
if (typeof currentQueue === 'function') {
|
||||
callback = currentQueue;
|
||||
currentQueue = null;
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
node.data = (i = ++i % 2); // Invoke other batch, to handle leftover callbacks in case of crash
|
||||
while (currentQueue) {
|
||||
callback = currentQueue.shift();
|
||||
if (!currentQueue.length) currentQueue = null;
|
||||
callback();
|
||||
}
|
||||
}).observe(node, { characterData: true });
|
||||
return function (fn) {
|
||||
ensureCallable(fn);
|
||||
if (queue) {
|
||||
if (typeof queue === 'function') queue = [queue, fn];
|
||||
else queue.push(fn);
|
||||
return;
|
||||
}
|
||||
queue = fn;
|
||||
node.data = (i = ++i % 2);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = (function () {
|
||||
// Node.js
|
||||
if ((typeof process === 'object') && process && (typeof process.nextTick === 'function')) {
|
||||
return process.nextTick;
|
||||
}
|
||||
|
||||
// queueMicrotask
|
||||
if (typeof queueMicrotask === "function") {
|
||||
return function (cb) { queueMicrotask(ensureCallable(cb)); };
|
||||
}
|
||||
|
||||
// MutationObserver
|
||||
if ((typeof document === 'object') && document) {
|
||||
if (typeof MutationObserver === 'function') return byObserver(MutationObserver);
|
||||
if (typeof WebKitMutationObserver === 'function') return byObserver(WebKitMutationObserver);
|
||||
}
|
||||
|
||||
// W3C Draft
|
||||
// http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/setImmediate/Overview.html
|
||||
if (typeof setImmediate === 'function') {
|
||||
return function (cb) { setImmediate(ensureCallable(cb)); };
|
||||
}
|
||||
|
||||
// Wide available standard
|
||||
if ((typeof setTimeout === 'function') || (typeof setTimeout === 'object')) {
|
||||
return function (cb) { setTimeout(ensureCallable(cb), 0); };
|
||||
}
|
||||
|
||||
return null;
|
||||
}());
|
27
node_modules/memoizee/node_modules/next-tick/package.json
generated
vendored
Normal file
27
node_modules/memoizee/node_modules/next-tick/package.json
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "next-tick",
|
||||
"version": "1.1.0",
|
||||
"description": "Environment agnostic nextTick polyfill",
|
||||
"author": "Mariusz Nowak <medyk@medikoo.com> (http://www.medikoo.com/)",
|
||||
"keywords": [
|
||||
"nexttick",
|
||||
"setImmediate",
|
||||
"setTimeout",
|
||||
"async"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/medikoo/next-tick.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tad": "^3.0.1",
|
||||
"xlint": "^0.2.2",
|
||||
"xlint-jslint-medikoo": "^0.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "node node_modules/xlint/bin/xlint --linter=node_modules/xlint-jslint-medikoo/index.js --no-cache --no-stream",
|
||||
"lint-console": "node node_modules/xlint/bin/xlint --linter=node_modules/xlint-jslint-medikoo/index.js --watch",
|
||||
"test": "node node_modules/tad/bin/tad"
|
||||
},
|
||||
"license": "ISC"
|
||||
}
|
22
node_modules/memoizee/node_modules/next-tick/test/index.js
generated
vendored
Normal file
22
node_modules/memoizee/node_modules/next-tick/test/index.js
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = function (t, a, d) {
|
||||
var invoked;
|
||||
|
||||
a(t(function () {
|
||||
a(arguments.length, 0, "Arguments");
|
||||
invoked = true;
|
||||
}), undefined, "Return");
|
||||
a(invoked, undefined, "Is not run immediately");
|
||||
setTimeout(function () {
|
||||
a(invoked, true, "Run in next tick");
|
||||
invoked = [];
|
||||
t(function () { invoked.push(0); });
|
||||
t(function () { invoked.push(1); });
|
||||
t(function () { invoked.push(2); });
|
||||
setTimeout(function () {
|
||||
a.deep(invoked, [0, 1, 2], "Serial");
|
||||
d();
|
||||
}, 10);
|
||||
}, 10);
|
||||
};
|
29
node_modules/memoizee/normalizers/get-1.js
generated
vendored
Normal file
29
node_modules/memoizee/normalizers/get-1.js
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
"use strict";
|
||||
|
||||
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];
|
||||
},
|
||||
set: function (args) {
|
||||
argsMap.push(args[0]);
|
||||
cache.push(++lastId);
|
||||
return lastId;
|
||||
},
|
||||
delete: function (id) {
|
||||
var index = indexOf.call(cache, id);
|
||||
if (index !== -1) {
|
||||
argsMap.splice(index, 1);
|
||||
cache.splice(index, 1);
|
||||
}
|
||||
},
|
||||
clear: function () {
|
||||
argsMap = [];
|
||||
cache = [];
|
||||
}
|
||||
};
|
||||
};
|
71
node_modules/memoizee/normalizers/get-fixed.js
generated
vendored
Normal file
71
node_modules/memoizee/normalizers/get-fixed.js
generated
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
"use strict";
|
||||
|
||||
var indexOf = require("es5-ext/array/#/e-index-of")
|
||||
, create = Object.create;
|
||||
|
||||
module.exports = function (length) {
|
||||
var lastId = 0, map = [[], []], cache = create(null);
|
||||
return {
|
||||
get: function (args) {
|
||||
var index = 0, set = map, i;
|
||||
while (index < length - 1) {
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) return null;
|
||||
set = set[1][i];
|
||||
++index;
|
||||
}
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) return null;
|
||||
return set[1][i] || null;
|
||||
},
|
||||
set: function (args) {
|
||||
var index = 0, set = map, i;
|
||||
while (index < length - 1) {
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) {
|
||||
i = set[0].push(args[index]) - 1;
|
||||
set[1].push([[], []]);
|
||||
}
|
||||
set = set[1][i];
|
||||
++index;
|
||||
}
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) {
|
||||
i = set[0].push(args[index]) - 1;
|
||||
}
|
||||
set[1][i] = ++lastId;
|
||||
cache[lastId] = args;
|
||||
return lastId;
|
||||
},
|
||||
delete: function (id) {
|
||||
var index = 0, set = map, i, path = [], args = cache[id];
|
||||
while (index < length - 1) {
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) {
|
||||
return;
|
||||
}
|
||||
path.push(set, i);
|
||||
set = set[1][i];
|
||||
++index;
|
||||
}
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) {
|
||||
return;
|
||||
}
|
||||
id = set[1][i];
|
||||
set[0].splice(i, 1);
|
||||
set[1].splice(i, 1);
|
||||
while (!set[0].length && path.length) {
|
||||
i = path.pop();
|
||||
set = path.pop();
|
||||
set[0].splice(i, 1);
|
||||
set[1].splice(i, 1);
|
||||
}
|
||||
delete cache[id];
|
||||
},
|
||||
clear: function () {
|
||||
map = [[], []];
|
||||
cache = create(null);
|
||||
}
|
||||
};
|
||||
};
|
16
node_modules/memoizee/normalizers/get-primitive-fixed.js
generated
vendored
Normal file
16
node_modules/memoizee/normalizers/get-primitive-fixed.js
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = function (length) {
|
||||
if (!length) {
|
||||
return function () {
|
||||
return "";
|
||||
};
|
||||
}
|
||||
return function (args) {
|
||||
var id = String(args[0]), i = 0, currentLength = length;
|
||||
while (--currentLength) {
|
||||
id += "\u0001" + args[++i];
|
||||
}
|
||||
return id;
|
||||
};
|
||||
};
|
90
node_modules/memoizee/normalizers/get.js
generated
vendored
Normal file
90
node_modules/memoizee/normalizers/get.js
generated
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
/* eslint max-statements: 0 */
|
||||
|
||||
"use strict";
|
||||
|
||||
var indexOf = require("es5-ext/array/#/e-index-of");
|
||||
|
||||
var create = Object.create;
|
||||
|
||||
module.exports = function () {
|
||||
var lastId = 0, map = [], cache = create(null);
|
||||
return {
|
||||
get: function (args) {
|
||||
var index = 0, set = map, i, length = args.length;
|
||||
if (length === 0) return set[length] || null;
|
||||
if ((set = set[length])) {
|
||||
while (index < length - 1) {
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) return null;
|
||||
set = set[1][i];
|
||||
++index;
|
||||
}
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) return null;
|
||||
return set[1][i] || null;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
set: function (args) {
|
||||
var index = 0, set = map, i, length = args.length;
|
||||
if (length === 0) {
|
||||
set[length] = ++lastId;
|
||||
} else {
|
||||
if (!set[length]) {
|
||||
set[length] = [[], []];
|
||||
}
|
||||
set = set[length];
|
||||
while (index < length - 1) {
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) {
|
||||
i = set[0].push(args[index]) - 1;
|
||||
set[1].push([[], []]);
|
||||
}
|
||||
set = set[1][i];
|
||||
++index;
|
||||
}
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) {
|
||||
i = set[0].push(args[index]) - 1;
|
||||
}
|
||||
set[1][i] = ++lastId;
|
||||
}
|
||||
cache[lastId] = args;
|
||||
return lastId;
|
||||
},
|
||||
delete: function (id) {
|
||||
var index = 0, set = map, i, args = cache[id], length = args.length, path = [];
|
||||
if (length === 0) {
|
||||
delete set[length];
|
||||
} else if ((set = set[length])) {
|
||||
while (index < length - 1) {
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) {
|
||||
return;
|
||||
}
|
||||
path.push(set, i);
|
||||
set = set[1][i];
|
||||
++index;
|
||||
}
|
||||
i = indexOf.call(set[0], args[index]);
|
||||
if (i === -1) {
|
||||
return;
|
||||
}
|
||||
id = set[1][i];
|
||||
set[0].splice(i, 1);
|
||||
set[1].splice(i, 1);
|
||||
while (!set[0].length && path.length) {
|
||||
i = path.pop();
|
||||
set = path.pop();
|
||||
set[0].splice(i, 1);
|
||||
set[1].splice(i, 1);
|
||||
}
|
||||
}
|
||||
delete cache[id];
|
||||
},
|
||||
clear: function () {
|
||||
map = [];
|
||||
cache = create(null);
|
||||
}
|
||||
};
|
||||
};
|
9
node_modules/memoizee/normalizers/primitive.js
generated
vendored
Normal file
9
node_modules/memoizee/normalizers/primitive.js
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = function (args) {
|
||||
var id, i, length = args.length;
|
||||
if (!length) return "\u0002";
|
||||
id = String(args[i = 0]);
|
||||
while (--length) id += "\u0001" + args[++i];
|
||||
return id;
|
||||
};
|
60
node_modules/memoizee/package.json
generated
vendored
Normal file
60
node_modules/memoizee/package.json
generated
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
{
|
||||
"name": "memoizee",
|
||||
"version": "0.4.15",
|
||||
"description": "Memoize/cache function results",
|
||||
"author": "Mariusz Nowak <medikoo@medikoo.com> (http://www.medikoo.com/)",
|
||||
"keywords": [
|
||||
"memoize",
|
||||
"memoizer",
|
||||
"cache",
|
||||
"memoization",
|
||||
"memo",
|
||||
"memcached",
|
||||
"hashing.",
|
||||
"storage",
|
||||
"caching",
|
||||
"memory",
|
||||
"gc",
|
||||
"weak",
|
||||
"garbage",
|
||||
"collector",
|
||||
"async"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/medikoo/memoizee.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"d": "^1.0.1",
|
||||
"es5-ext": "^0.10.53",
|
||||
"es6-weak-map": "^2.0.3",
|
||||
"event-emitter": "^0.3.5",
|
||||
"is-promise": "^2.2.2",
|
||||
"lru-queue": "^0.1.0",
|
||||
"next-tick": "^1.1.0",
|
||||
"timers-ext": "^0.1.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bluebird": "^3.7.2",
|
||||
"eslint": "^5.16.0",
|
||||
"eslint-config-medikoo-es5": "^1.7.3",
|
||||
"plain-promise": "^0.1.1",
|
||||
"tad": "^2.0.1"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "medikoo-es5",
|
||||
"root": true,
|
||||
"globals": {
|
||||
"setTimeout": true,
|
||||
"clearTimeout": true
|
||||
},
|
||||
"rules": {
|
||||
"max-lines-per-function": "off"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint --ignore-path=.gitignore .",
|
||||
"test": "tad"
|
||||
},
|
||||
"license": "ISC"
|
||||
}
|
37
node_modules/memoizee/plain.js
generated
vendored
Normal file
37
node_modules/memoizee/plain.js
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
"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");
|
||||
|
||||
module.exports = function self(fn /*, options */) {
|
||||
var options, length, conf;
|
||||
|
||||
callable(fn);
|
||||
options = Object(arguments[1]);
|
||||
|
||||
if (options.async && options.promise) {
|
||||
throw new Error("Options 'async' and 'promise' cannot be used together");
|
||||
}
|
||||
|
||||
// Do not memoize already memoized function
|
||||
if (hasOwnProperty.call(fn, "__memoized__") && !options.force) return fn;
|
||||
|
||||
// Resolve length;
|
||||
length = resolveLength(options.length, fn.length, options.async && extensions.async);
|
||||
|
||||
// Configure cache map
|
||||
conf = configure(fn, length, options);
|
||||
|
||||
// Bind eventual extensions
|
||||
forEach(extensions, function (extFn, name) {
|
||||
if (options[name]) extFn(options[name], conf, options);
|
||||
});
|
||||
|
||||
if (self.__profiler__) self.__profiler__(conf);
|
||||
|
||||
conf.updateEnv();
|
||||
return conf.memoized;
|
||||
};
|
107
node_modules/memoizee/profile.js
generated
vendored
Normal file
107
node_modules/memoizee/profile.js
generated
vendored
Normal file
|
@ -0,0 +1,107 @@
|
|||
// Gathers statistical data, and provides them in convinient form
|
||||
|
||||
"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 max = Math.max, stats = exports.statistics = {};
|
||||
|
||||
Object.defineProperty(
|
||||
memoize,
|
||||
"__profiler__",
|
||||
d(function (conf) {
|
||||
var id, source, data, stack;
|
||||
stack = new Error().stack;
|
||||
if (
|
||||
!stack ||
|
||||
!stack.split("\n").slice(3).some(function (line) {
|
||||
if (line.indexOf("/memoizee/") === -1 && line.indexOf(" (native)") === -1) {
|
||||
source = line.replace(/\n/g, "\\n").trim();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
) {
|
||||
source = "unknown";
|
||||
}
|
||||
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; });
|
||||
})
|
||||
);
|
||||
|
||||
exports.log = function () {
|
||||
var initial, cached, ordered, ipad, cpad, ppad, toPrc, log;
|
||||
|
||||
initial = cached = 0;
|
||||
ordered = [];
|
||||
|
||||
toPrc = function (initialCount, cachedCount) {
|
||||
if (!initialCount && !cachedCount) {
|
||||
return "0.00";
|
||||
}
|
||||
return ((cachedCount / (initialCount + cachedCount)) * 100).toFixed(2);
|
||||
};
|
||||
|
||||
log = "------------------------------------------------------------\n";
|
||||
log += "Memoize statistics:\n\n";
|
||||
|
||||
forEach(
|
||||
stats,
|
||||
function (data, name) {
|
||||
initial += data.initial;
|
||||
cached += data.cached;
|
||||
ordered.push([name, data]);
|
||||
},
|
||||
null,
|
||||
function (nameA, nameB) {
|
||||
return (
|
||||
this[nameB].initial +
|
||||
this[nameB].cached -
|
||||
(this[nameA].initial + this[nameA].cached)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipad = partial.call(pad, " ", max(String(initial).length, "Init".length));
|
||||
cpad = partial.call(pad, " ", max(String(cached).length, "Cache".length));
|
||||
ppad = partial.call(pad, " ", "%Cache".length);
|
||||
log +=
|
||||
ipad.call("Init") +
|
||||
" " +
|
||||
cpad.call("Cache") +
|
||||
" " +
|
||||
ppad.call("%Cache") +
|
||||
" Source location\n";
|
||||
log +=
|
||||
ipad.call(initial) +
|
||||
" " +
|
||||
cpad.call(cached) +
|
||||
" " +
|
||||
ppad.call(toPrc(initial, cached)) +
|
||||
" (all)\n";
|
||||
ordered.forEach(function (data) {
|
||||
var name = data[0];
|
||||
data = data[1];
|
||||
log +=
|
||||
ipad.call(data.initial) +
|
||||
" " +
|
||||
cpad.call(data.cached) +
|
||||
" " +
|
||||
ppad.call(toPrc(data.initial, data.cached)) +
|
||||
" " +
|
||||
name +
|
||||
"\n";
|
||||
});
|
||||
log += "------------------------------------------------------------\n";
|
||||
return log;
|
||||
};
|
3
node_modules/memoizee/weak-plain.js
generated
vendored
Normal file
3
node_modules/memoizee/weak-plain.js
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = require("./lib/weak")(require("./plain"));
|
3
node_modules/memoizee/weak.js
generated
vendored
Normal file
3
node_modules/memoizee/weak.js
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = require("./lib/weak")(require("./"));
|
Loading…
Add table
Add a link
Reference in a new issue