Current Dev State

This commit is contained in:
Tim Lorsbach
2025-06-23 20:13:54 +02:00
parent b4f9bb277d
commit ded50edaa2
22617 changed files with 4345095 additions and 174 deletions

61
static/js/ketcher2/node_modules/memoizee/CHANGELOG.md generated vendored Normal file
View File

@ -0,0 +1,61 @@
# Change Log
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.
<a name="0.4.11"></a>
## [0.4.11](https://github.com/medikoo/memoizee/compare/v0.4.10...v0.4.11) (2017-09-11)
### Bug Fixes
* _get and _has internal args handling. ([7cb1c7a](https://github.com/medikoo/memoizee/commit/7cb1c7a)), closes [#88](https://github.com/medikoo/memoizee/issues/88)
<a name="0.4.10"></a>
## [0.4.10](https://github.com/medikoo/memoizee/compare/v0.4.9...v0.4.10) (2017-09-07)
### Bug Fixes
* remove then:finally mode as it can't work right ([5b79698](https://github.com/medikoo/memoizee/commit/5b79698))
<a name="0.4.9"></a>
## [0.4.9](https://github.com/medikoo/memoizee/compare/v0.4.8...v0.4.9) (2017-08-29)
<a name="0.4.8"></a>
## [0.4.8](https://github.com/medikoo/memoizee/compare/v0.4.7...v0.4.8) (2017-08-29)
<a name="0.4.7"></a>
## [0.4.7](https://github.com/medikoo/memoizee/compare/v0.4.6...v0.4.7) (2017-08-29)
### Features
* improve 'promise' mode handling ([759e315](https://github.com/medikoo/memoizee/commit/759e315))
* improve internal promise validation ([d23b94f](https://github.com/medikoo/memoizee/commit/d23b94f))
<a name="0.4.6"></a>
## [0.4.6](https://github.com/medikoo/memoizee/compare/v0.4.5...v0.4.6) (2017-08-24)
* `profileName` option for naming memoizee instances in profile output
<a name="0.4.5"></a>
## [0.4.5](https://github.com/medikoo/memoizee/compare/v0.4.4...v0.4.5) (2017-05-10)
### Bug Fixes
* resolution of extensions with weak handling ([f29a97b](https://github.com/medikoo/memoizee/commit/f29a97b)), closes [#79](https://github.com/medikoo/memoizee/issues/79)
## Old changelog
See `CHANGES`

124
static/js/ketcher2/node_modules/memoizee/CHANGES generated vendored Normal file
View File

@ -0,0 +1,124 @@
-- For new changelog see CHANGELOG.md
v0.4.4 -- 2017.03.15
* Expose _get and _has methods. It provides temporary means for better cache inspection until
v1 is delivered
v0.4.3 -- 2017.02.20
* Fix normalization resolver, so it validates already normalized resolvers (reported at #70)
v0.4.2 -- 2017.02.17
* Guard proper promise resolution in promise mode
* Improve documentation
* Improve npm scripts configuration
* Improve CI configuration
v0.4.1 -- 2016.07.13
* Fix promise mode to not use `then` and `finally` pair. Thanks @Kovensky
* Add 'done' mode to 'promise' mode (so now callbacks can be registered through `done` but no
`finally` event if it's implemented)
v0.4.0 -- 2016.07.07
* Introduce 'promise' mode
* Change signature of internal events for 'async' case
* Document 'normalizer' option
v0.3.10 -- 2016.04.21
* Fix resolvers bug (#12)
* Fix arguments support for weak mode
* Update repository address after rename
v0.3.9 -- 2015.08.04
* Update dependencies
* Improve documentation
* FIx spelling of LICENSE
v0.3.8 -- 2014.10.08
* Introduce WeakMap based `weak` mode
v0.3.7 -- 2014.08.14
* Fix prefetch support for asynchronous functions (#19)
* Configure lint scripts
v0.3.6 -- 2014.07.28
* Fix race condition issue related to clear/delete calls and returning id's (#18)
* Fix maxAge major cache handling issue (on timeout instead of individual record whole cache was
cleared)
v0.3.5 -- 2014.07.07
* Fix internal id genaration, for primitive, length = 1 case.
Ids were not serialized to strings, and that caused issues with other
internal logiv, which e.g. treated `null` case specifically.
Fixes #15 (Thanks @isaacg for reporting)
v0.3.4 -- 2014.06.22
* Fix async handling in case of clear between two async calls
(assurance of unique cache ids solves that). Fixes #13
v0.3.3 -- 2014.05.12
* Fix profiler special property definition
v0.3.2 -- 2014.05.01
* Provide no-arguments memoization out of a box
(no need to provide normalizer to `memoizee/plain`)
v0.3.1 -- 2014.04.27
* Update package.json to use latest 'tad' engine (fixes tests evaluation)
v0.3.0 -- 2014.04.27
Major reorganization and partial refactoring
* Move out main modules from lib folder
* Introduce normalizer based memoization. Primitive and regular handlers were converted into
dedicated normalizers (located in lib/normalizers folder). Custom normalizers can be provided at
run time via `normalizer` option.
* Provide 'plain' module which does not import (require) any extensions or normalizers. Thanks to
that it's lighter for e.g. client-side bundle. Any extensions that are expected to be used should
be required upfront, normalizers should be provided via `normalizer` option.
* Rename `memoized.clear` into `memoized.delete`, and `memoized.clearAll` into `memoized.clear`
* Rename `memoized.clearRef` into `memoized.deleteRef` (applies to 'refCounter' option)
* Remove 'method' option. Instead 'methods' and 'methods-plan' modules are provided which generate
descriptors for lazy created memoized methods.
* 'profile' is no longer an extension. It's provided as dedicated module.
* Clean up logic for `async` handling
* Take out 'max' extension's LRU logic into external `lru-queue` package.
See https://github.com/medikoo/lru-queue
* Remove possibility to access original arguments when resolvers are used
* Assure expected length of memoized functions
* Remove Makefile (it's environment agnostic package)
v0.2.6 -- 2013.10.08
* Fix internal events propagation when handling async calls that
resolve with errors. `asyncpurge` was emitted for values that had no
`asyncinit` emitted. Issue #9
v0.2.5 -- 2013.06.21
* Fix primitive handling for dynamic arguments length
v0.2.4 -- 2013.03.23
* Throw on circular invocations, they cannot be memoized as intended.
v0.2.3 -- 2012.10.04
* Fixed serious bug related to not properly cleared cache when working in
regular mode
v0.2.2 -- 2012.10.03
* preFetch functionality for maxAge variant
* Prevent memoization of already memoized functions
v0.2.1 -- 2012.09.21
* Fix missing global reference in method option logic
* Fix variable visibility in async option logic
* Lint cleanup
v0.2.0 -- 2012.09.21
* Modularization and general algorithm cleanup
* Cache is limited (max option) using LRU instead of FIFO algorithm
* Improved async mode, and its handling by other options
v0.1.1 -- 2012.09.19
* Fix dispose invocations for no arguments call
* Small documentation improvements
v0.1.0 -- 2012.09.18
* Initial. Derived from es5-ext package and added `async`, `maxAge`,
`refCounter`, `max` and `dispose` options.

21
static/js/ketcher2/node_modules/memoizee/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (C) 2012-2016 Mariusz Nowak (www.medikoo.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

442
static/js/ketcher2/node_modules/memoizee/README.md generated vendored Normal file
View File

@ -0,0 +1,442 @@
# 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__](#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
```
### 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
```
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 now 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 [![Build Status](https://img.shields.io/circleci/project/github/medikoo/memoizee.svg)](https://circleci.com/gh/medikoo/memoizee)
$ 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>
### 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

25
static/js/ketcher2/node_modules/memoizee/appveyor.yml generated vendored Normal file
View File

@ -0,0 +1,25 @@
environment:
matrix:
# node.js
- nodejs_version: "0.12"
- nodejs_version: "4"
- nodejs_version: "6"
- nodejs_version: "8"
# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install
# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- npm --version
# run tests
- npm test
# Don't actually build.
build: off

View File

@ -0,0 +1,140 @@
/* global console */
/* eslint no-console: 0, id-length: 0 */
"use strict";
// Simple benchmark for very simple memoization case (fibonacci series)
// To run it, do following in memoizee package path:
//
// $ npm install underscore lodash lru-cache secondary-cache
// $ node benchmark/fibonacci.js
var forEach = require("es5-ext/object/for-each")
, pad = require("es5-ext/string/#/pad")
, memoizee = require("..")
, underscore = require("underscore").memoize
, lodash = require("lodash").memoize
, lruCache = require("lru-cache")
, lruSecondary = require("secondary-cache/lib/lru-cache");
var now = Date.now
, time
, getFib
, lru
, memo
, total
, index = 3000
, count = 10
, i
, lruMax = 1000
, data = {}
, lruObj;
getFib = function (memoize, opts) {
var fib = memoize(function (x) {
return x < 2 ? 1 : fib(x - 1) + fib(x - 2);
}, opts);
return fib;
};
lru = function (x) {
var value = lruObj.get(x);
if (value === undefined) {
value = x < 2 ? 1 : lru(x - 1) + lru(x - 2);
lruObj.set(x, value);
}
return value;
};
console.log("Fibonacci", index, "x" + count + ":\n");
total = 0;
i = count;
while (i--) {
memo = getFib(memoizee);
time = now();
memo(index);
total += now() - time;
}
data["Memoizee (object mode)"] = total;
total = 0;
i = count;
while (i--) {
memo = getFib(memoizee, { primitive: true });
time = now();
memo(index);
total += now() - time;
}
data["Memoizee (primitive mode)"] = total;
total = 0;
i = count;
while (i--) {
memo = getFib(underscore);
time = now();
memo(index);
total += now() - time;
}
data.Underscore = total;
total = 0;
i = count;
while (i--) {
memo = getFib(lodash);
time = now();
memo(index);
total += now() - time;
}
data["Lo-dash"] = total;
total = 0;
i = count;
while (i--) {
memo = getFib(memoizee, { primitive: true, max: lruMax });
time = now();
memo(index);
total += now() - time;
}
data["Memoizee (primitive mode) LRU (max: 1000)"] = total;
total = 0;
i = count;
while (i--) {
memo = getFib(memoizee, { max: lruMax });
time = now();
memo(index);
total += now() - time;
}
data["Memoizee (object mode) LRU (max: 1000)"] = total;
total = 0;
i = count;
while (i--) {
lruObj = lruCache({ max: lruMax });
time = now();
lru(index);
total += now() - time;
}
data["lru-cache LRU (max: 1000)"] = total;
total = 0;
i = count;
while (i--) {
lruObj = lruSecondary(lruMax);
time = now();
lru(index);
total += now() - time;
}
data["secondary-cache LRU (max: 1000)"] = total;
forEach(
data,
function (value, name, obj, currentIndex) {
console.log(currentIndex + 1 + ":", pad.call(value, " ", 5) + "ms ", name);
},
null,
function (a, b) {
return this[a] - this[b];
}
);

160
static/js/ketcher2/node_modules/memoizee/ext/async.js generated vendored Normal file
View File

@ -0,0 +1,160 @@
/* 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);
})
);
});
};

View 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);
});
});
};

View File

@ -0,0 +1,93 @@
/* 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 (!preFetchTimeouts) return;
if (preFetchTimeouts[id]) {
if (preFetchTimeouts[id] !== "nextTick") clearTimeout(preFetchTimeouts[id]);
}
preFetchTimeouts[id] = setTimeout(function () {
delete preFetchTimeouts[id];
}, preFetchAge);
});
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
static/js/ketcher2/node_modules/memoizee/ext/max.js generated vendored Normal file
View 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);
};

156
static/js/ketcher2/node_modules/memoizee/ext/promise.js generated vendored Normal file
View File

@ -0,0 +1,156 @@
/* 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") {
// With no `finally` it's best we can do, side effect is that it mutes any eventual
// "Unhandled error" events on returned promise
promise.then(
function (result) {
nextTick(onSuccess.bind(this, result));
},
function () {
nextTick(onFailure);
}
);
} 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. Otherwise then:finally mode should be used instead
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];
})
);
});
};

View 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
static/js/ketcher2/node_modules/memoizee/index.js generated vendored Normal file
View 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);
};

View File

@ -0,0 +1,188 @@
/* 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;
};

View 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);
};
};

View File

@ -0,0 +1 @@
"use strict";

View 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);
};

View 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;
};

View 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);
};

135
static/js/ketcher2/node_modules/memoizee/lib/weak.js generated vendored Normal file
View File

@ -0,0 +1,135 @@
"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;
};
};

View File

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

3
static/js/ketcher2/node_modules/memoizee/methods.js generated vendored Normal file
View File

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

View 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 = [];
}
};
};

View 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);
}
};
};

View 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;
};
};

View 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);
}
};
};

View 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;
};

90
static/js/ketcher2/node_modules/memoizee/package.json generated vendored Normal file
View File

@ -0,0 +1,90 @@
{
"_from": "memoizee@0.4.X",
"_id": "memoizee@0.4.11",
"_inBundle": false,
"_integrity": "sha1-vemBdmPJ5A/bKk6hw2cpYIeujI8=",
"_location": "/memoizee",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "memoizee@0.4.X",
"name": "memoizee",
"escapedName": "memoizee",
"rawSpec": "0.4.X",
"saveSpec": null,
"fetchSpec": "0.4.X"
},
"_requiredBy": [
"/debug-fabulous"
],
"_resolved": "https://registry.npmjs.org/memoizee/-/memoizee-0.4.11.tgz",
"_shasum": "bde9817663c9e40fdb2a4ea1c367296087ae8c8f",
"_spec": "memoizee@0.4.X",
"_where": "/home/manfred/enviPath/ketcher2/ketcher/node_modules/debug-fabulous",
"author": {
"name": "Mariusz Nowak",
"email": "medikoo@medikoo.com",
"url": "http://www.medikoo.com/"
},
"bugs": {
"url": "https://github.com/medikoo/memoizee/issues"
},
"bundleDependencies": false,
"dependencies": {
"d": "1",
"es5-ext": "^0.10.30",
"es6-weak-map": "^2.0.2",
"event-emitter": "^0.3.5",
"is-promise": "^2.1",
"lru-queue": "0.1",
"next-tick": "1",
"timers-ext": "^0.1.2"
},
"deprecated": false,
"description": "Memoize/cache function results",
"devDependencies": {
"eslint": "^4.6.1",
"eslint-config-medikoo-es5": "^1.4.3",
"plain-promise": "^0.1.1",
"tad": "^0.2.7"
},
"eslintConfig": {
"extends": "medikoo-es5",
"root": true,
"globals": {
"setTimeout": true,
"clearTimeout": true
}
},
"homepage": "https://github.com/medikoo/memoizee#readme",
"keywords": [
"memoize",
"memoizer",
"cache",
"memoization",
"memo",
"memcached",
"hashing.",
"storage",
"caching",
"memory",
"gc",
"weak",
"garbage",
"collector",
"async"
],
"license": "MIT",
"name": "memoizee",
"repository": {
"type": "git",
"url": "git://github.com/medikoo/memoizee.git"
},
"scripts": {
"lint": "eslint --ignore-path=.gitignore .",
"lint-medikoo": "xlint --linter=node_modules/xlint-jslint-medikoo/index.js",
"test": "tad"
},
"version": "0.4.11"
}

37
static/js/ketcher2/node_modules/memoizee/plain.js generated vendored Normal file
View 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;
};

111
static/js/ketcher2/node_modules/memoizee/profile.js generated vendored Normal file
View File

@ -0,0 +1,111 @@
// 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;
};

View File

@ -0,0 +1,413 @@
/* eslint id-length: 0, func-names: 0, handle-callback-err: 0, max-lines: 0 */
"use strict";
var memoize = require("../..")
, nextTick = require("next-tick");
module.exports = function () {
return {
"Regular": {
Success: function (a, d) {
var mfn, fn, u = {}, i = 0, invoked = 0;
fn = function (x, y, cb) {
nextTick(function () {
++i;
cb(null, x + y);
});
return u;
};
mfn = memoize(fn, { async: true });
a(
mfn(3, 7, function (err, res) {
++invoked;
a.deep([err, res], [null, 10], "Result #1");
}),
u,
"Initial"
);
a(
mfn(3, 7, function (err, res) {
++invoked;
a.deep([err, res], [null, 10], "Result #2");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
++invoked;
a.deep([err, res], [null, 13], "Result B #1");
}),
u,
"Initial #2"
);
a(
mfn(3, 7, function (err, res) {
++invoked;
a.deep([err, res], [null, 10], "Result #3");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
++invoked;
a.deep([err, res], [null, 13], "Result B #2");
}),
u,
"Initial #3"
);
nextTick(function () {
a(i, 2, "Init Called");
a(invoked, 5, "Cb Called");
a(
mfn(3, 7, function (err, res) {
++invoked;
a.deep([err, res], [null, 10], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
++invoked;
a.deep([err, res], [null, 13], "Again B: Result");
}),
u,
"Again B: Initial"
);
nextTick(function () {
a(i, 2, "Init Called #2");
a(invoked, 7, "Cb Called #2");
mfn.delete(3, 7);
a(
mfn(3, 7, function (err, res) {
++invoked;
a.deep([err, res], [null, 10], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
++invoked;
a.deep([err, res], [null, 13], "Again B: Result");
}),
u,
"Again B: Initial"
);
nextTick(function () {
a(i, 3, "Init After delete");
a(invoked, 9, "Cb After delete");
d();
});
});
});
},
Error: function (a, d) {
var mfn, fn, u = {}, i = 0, e = new Error("Test");
fn = function (x, y, cb) {
nextTick(function () {
++i;
cb(e);
});
return u;
};
mfn = memoize(fn, { async: true, dispose: a.never });
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [e, undefined], "Result #1");
}),
u,
"Initial"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [e, undefined], "Result #2");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [e, undefined], "Result B #1");
}),
u,
"Initial #2"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [e, undefined], "Result #3");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [e, undefined], "Result B #2");
}),
u,
"Initial #3"
);
nextTick(function () {
a(i, 2, "Called #2");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [e, undefined], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [e, undefined], "Again B: Result");
}),
u,
"Again B: Initial"
);
nextTick(function () {
a(i, 4, "Again Called #2");
d();
});
});
}
},
"Primitive": {
"Success": function (a, d) {
var mfn, fn, u = {}, i = 0;
fn = function (x, y, cb) {
nextTick(function () {
++i;
cb(null, x + y);
});
return u;
};
mfn = memoize(fn, { async: true, primitive: true });
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #1");
}),
u,
"Initial"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #2");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Result B #1");
}),
u,
"Initial #2"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #3");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Result B #2");
}),
u,
"Initial #3"
);
nextTick(function () {
a(i, 2, "Called #2");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Again B: Result");
}),
u,
"Again B: Initial"
);
nextTick(function () {
a(i, 2, "Again Called #2");
mfn.delete(3, 7);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Again B: Result");
}),
u,
"Again B: Initial"
);
nextTick(function () {
a(i, 3, "Call After delete");
d();
});
});
});
},
"Error": function (a, d) {
var mfn, fn, u = {}, i = 0, e = new Error("Test");
fn = function (x, y, cb) {
nextTick(function () {
++i;
cb(e);
});
return u;
};
mfn = memoize(fn, { async: true, primitive: true });
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [e, undefined], "Result #1");
}),
u,
"Initial"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [e, undefined], "Result #2");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [e, undefined], "Result B #1");
}),
u,
"Initial #2"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [e, undefined], "Result #3");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [e, undefined], "Result B #2");
}),
u,
"Initial #3"
);
nextTick(function () {
a(i, 2, "Called #2");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [e, undefined], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [e, undefined], "Again B: Result");
}),
u,
"Again B: Initial"
);
nextTick(function () {
a(i, 4, "Again Called #2");
d();
});
});
},
"Primitive null arg case": function (a, d) {
var x = {}
, mfn = memoize(
function f(id, cb) {
cb(null, x);
},
{
async: true,
primitive: true
}
);
mfn(null, function (err, res) {
a.deep([err, res], [null, x], "Args");
d();
});
}
},
"Sync Clear": function (a, d) {
var mfn, fn;
fn = function (x, cb) {
nextTick(function () {
cb(null, x);
});
};
mfn = memoize(fn, { async: true });
mfn(1, function (err, i) {
a(i, 1, "First");
});
mfn.clear();
mfn(2, function (err, i) {
a(i, 2, "Second");
d();
});
},
"Sync Clear: Primitive": function (a, d) {
var mfn, fn;
fn = function (x, cb) {
nextTick(function () {
cb(null, x);
});
};
mfn = memoize(fn, { async: true, primitive: true });
mfn(2, function (err, i) {
a(i, 2, "First");
});
mfn(1, function (err, i) {
a(i, 1, "Second");
nextTick(d);
});
mfn.clear();
mfn(2, function (err, i) {
a(i, 2, "Third");
});
}
};
};

View File

@ -0,0 +1,298 @@
/* eslint id-length: 0, max-lines: 0, max-statements: 0 */
"use strict";
var memoize = require("../..")
, nextTick = require("next-tick")
, delay = require("timers-ext/delay")
, Promise = require("plain-promise");
module.exports = function () {
return {
Regular: {
"Sync": function (a) {
var mfn, fn, value = [], x, invoked;
fn = function (arg1, arg2) {
return arg1 + arg2;
};
mfn = memoize(fn, {
dispose: function (val) {
value.push(val);
}
});
mfn(3, 7);
mfn(5, 8);
mfn(12, 4);
a.deep(value, [], "Pre");
mfn.delete(5, 8);
a.deep(value, [13], "#1");
value = [];
mfn.delete(12, 4);
a.deep(value, [16], "#2");
value = [];
mfn(77, 11);
mfn.clear();
a.deep(value, [10, 88], "Clear all");
x = {};
invoked = false;
mfn = memoize(
function () {
return x;
},
{
dispose: function (val) {
invoked = val;
}
}
);
mfn.delete();
a(invoked, false, "No args: Post invalid delete");
mfn();
a(invoked, false, "No args: Post cache");
mfn.delete();
a(invoked, x, "No args: Pre delete");
},
"Ref counter": function (a) {
var mfn, fn, value = [];
fn = function (x, y) {
return x + y;
};
mfn = memoize(fn, {
refCounter: true,
dispose: function (val) {
value.push(val);
}
});
mfn(3, 7);
mfn(5, 8);
mfn(12, 4);
a.deep(value, [], "Pre");
mfn(5, 8);
mfn.deleteRef(5, 8);
a.deep(value, [], "Pre");
mfn.deleteRef(5, 8);
a.deep(value, [13], "#1");
value = [];
mfn.deleteRef(12, 4);
a.deep(value, [16], "#2");
value = [];
mfn(77, 11);
mfn.clear();
a.deep(value, [10, 88], "Clear all");
},
"Async": function (a, d) {
var mfn, fn, u = {}, value = [];
fn = function (x, y, cb) {
nextTick(function () {
cb(null, x + y);
});
return u;
};
mfn = memoize(fn, {
async: true,
dispose: function (val) {
value.push(val);
}
});
mfn(3, 7, function () {
mfn(5, 8, function () {
mfn(12, 4, function () {
a.deep(value, [], "Pre");
mfn.delete(5, 8);
a.deep(value, [13], "#1");
value = [];
mfn.delete(12, 4);
a.deep(value, [16], "#2");
value = [];
mfn(77, 11, function () {
mfn.clear();
a.deep(value, [10, 88], "Clear all");
d();
});
});
});
});
},
"Promise": function (a, d) {
var mfn, fn, value = [];
fn = function (x, y) {
return new Promise(function (res) {
res(x + y);
});
};
mfn = memoize(fn, {
promise: true,
dispose: function (val) {
value.push(val);
}
});
mfn(3, 7).done(function () {
mfn(5, 8).done(function () {
mfn(12, 4).done(
delay(function () {
a.deep(value, [], "Pre");
mfn.delete(5, 8);
a.deep(value, [13], "#1");
value = [];
mfn.delete(12, 4);
a.deep(value, [16], "#2");
value = [];
mfn(77, 11).done(
delay(function () {
mfn.clear();
a.deep(value, [10, 88], "Clear all");
d();
})
);
})
);
});
});
}
},
Primitive: {
"Sync": function (a) {
var mfn, fn, value = [];
fn = function (x, y) {
return x + y;
};
mfn = memoize(fn, {
dispose: function (val) {
value.push(val);
}
});
mfn(3, 7);
mfn(5, 8);
mfn(12, 4);
a.deep(value, [], "Pre");
mfn.delete(5, 8);
a.deep(value, [13], "#1");
value = [];
mfn.delete(12, 4);
a.deep(value, [16], "#2");
value = [];
mfn(77, 11);
mfn.clear();
a.deep(value, [10, 88], "Clear all");
},
"Ref counter": function (a) {
var mfn, fn, value = [];
fn = function (x, y) {
return x + y;
};
mfn = memoize(fn, {
refCounter: true,
dispose: function (val) {
value.push(val);
}
});
mfn(3, 7);
mfn(5, 8);
mfn(12, 4);
a.deep(value, [], "Pre");
mfn(5, 8);
mfn.deleteRef(5, 8);
a.deep(value, [], "Pre");
mfn.deleteRef(5, 8);
a.deep(value, [13], "#1");
value = [];
mfn.deleteRef(12, 4);
a.deep(value, [16], "#2");
value = [];
mfn(77, 11);
mfn.clear();
a.deep(value, [10, 88], "Clear all");
},
"Async": function (a, d) {
var mfn, fn, u = {}, value = [];
fn = function (x, y, cb) {
nextTick(function () {
cb(null, x + y);
});
return u;
};
mfn = memoize(fn, {
async: true,
dispose: function (val) {
value.push(val);
}
});
mfn(3, 7, function () {
mfn(5, 8, function () {
mfn(12, 4, function () {
a.deep(value, [], "Pre");
mfn.delete(5, 8);
a.deep(value, [13], "#1");
value = [];
mfn.delete(12, 4);
a.deep(value, [16], "#2");
value = [];
mfn(77, 11, function () {
mfn.clear();
a.deep(value, [10, 88], "Clear all");
d();
});
});
});
});
},
"Promise": function (a, d) {
var mfn, fn, value = [];
fn = function (x, y) {
return new Promise(function (res) {
res(x + y);
});
};
mfn = memoize(fn, {
promise: true,
dispose: function (val) {
value.push(val);
}
});
mfn(3, 7).done(function () {
mfn(5, 8).done(function () {
mfn(12, 4).done(
delay(function () {
a.deep(value, [], "Pre");
mfn.delete(5, 8);
a.deep(value, [13], "#1");
value = [];
mfn.delete(12, 4);
a.deep(value, [16], "#2");
value = [];
mfn(77, 11).done(
delay(function () {
mfn.clear();
a.deep(value, [10, 88], "Clear all");
d();
})
);
})
);
});
});
}
}
};
};

View File

@ -0,0 +1,948 @@
/* eslint max-lines: 0, id-length: 0, func-names: 0, handle-callback-err: 0, max-lines: 0,
no-unused-vars: 0, max-nested-callbacks: 0, no-shadow: 0, max-len: 0 */
"use strict";
var memoize = require("../..")
, nextTick = require("next-tick")
, delay = require("timers-ext/delay")
, Promise = require("plain-promise");
require("../../ext/async");
require("../../ext/promise");
module.exports = function () {
return {
Regular: {
Sync: function (a, d) {
var mfn,
fn,
i = 0;
fn = function (x, y) {
++i;
return x + y;
};
mfn = memoize(fn, { maxAge: 100 });
a(mfn(3, 7), 10, "Result #1");
a(i, 1, "Called #1");
a(mfn(3, 7), 10, "Result #2");
a(i, 1, "Called #2");
a(mfn(5, 8), 13, "Result B #1");
a(i, 2, "Called B #1");
a(mfn(3, 7), 10, "Result #3");
a(i, 2, "Called #3");
a(mfn(5, 8), 13, "Result B #2");
a(i, 2, "Called B #2");
setTimeout(function () {
a(mfn(3, 7), 10, "Result: Wait");
a(i, 2, "Called: Wait");
a(mfn(5, 8), 13, "Result: Wait B");
a(i, 2, "Called: Wait B");
a(mfn(9, 1), 10, "Result: C");
a(i, 3, "Called: C");
setTimeout(function () {
a(mfn(3, 7), 10, "Result: Wait After");
a(i, 4, "Called: Wait After");
a(mfn(5, 8), 13, "Result: Wait After B");
a(i, 5, "Called: Wait After B");
a(mfn(3, 7), 10, "Result: Wait After #2");
a(i, 5, "Called: Wait After #2");
a(mfn(5, 8), 13, "Result: Wait After B #2");
a(i, 5, "Called: Wait After B #2");
a(mfn(9, 1), 10, "Result: WiatC");
a(i, 5, "Called: Wait C");
d();
}, 90);
}, 20);
},
Promise: function (a, d) {
var mfn,
fn,
i = 0;
fn = function (x, y) {
return new Promise(function (res) {
++i;
res(x + y);
});
};
mfn = memoize(fn, { promise: true, maxAge: 100 });
mfn(3, 7).done(function (res) {
a(res, 10, "Result #1");
});
mfn(5, 8).done(function (res) {
a(res, 13, "Result #2");
});
mfn(3, 7).done(function (res) {
a(res, 10, "Result #3");
});
mfn(3, 7).done(function (res) {
a(res, 10, "Result #4");
});
mfn(5, 8).done(function (res) {
a(res, 13, "Result #5");
});
setTimeout(function () {
a(i, 2, "Called #2");
mfn(3, 7).done(function (res) {
a(res, 10, "Again: Result #1");
});
mfn(5, 8).done(function (res) {
a(res, 13, "Again: Result #2");
});
setTimeout(function () {
a(i, 2, "Again Called #2");
mfn(3, 7).done(function (res) {
a(res, 10, "Again: Result #1");
});
mfn(5, 8).done(function (res) {
a(res, 13, "Again: Result #2");
});
nextTick(function () {
a(i, 4, "Call After clear");
d();
});
}, 100);
}, 20);
},
Async: function (a, d) {
var mfn,
fn,
u = {},
i = 0;
fn = function (x, y, cb) {
nextTick(function () {
++i;
cb(null, x + y);
});
return u;
};
mfn = memoize(fn, { async: true, maxAge: 100 });
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #1");
}),
u,
"Initial"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #2");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Result B #1");
}),
u,
"Initial #2"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #3");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Result B #2");
}),
u,
"Initial #3"
);
setTimeout(function () {
a(i, 2, "Called #2");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Again B: Result");
}),
u,
"Again B: Initial"
);
setTimeout(function () {
a(i, 2, "Again Called #2");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Again B: Result");
}),
u,
"Again B: Initial"
);
nextTick(function () {
a(i, 4, "Call After clear");
d();
});
}, 100);
}, 20);
}
},
Primitive: {
Sync: function (a, d) {
var mfn,
fn,
i = 0;
fn = function (x, y) {
++i;
return x + y;
};
mfn = memoize(fn, { primitive: true, maxAge: 100 });
a(mfn(3, 7), 10, "Result #1");
a(i, 1, "Called #1");
a(mfn(3, 7), 10, "Result #2");
a(i, 1, "Called #2");
a(mfn(5, 8), 13, "Result B #1");
a(i, 2, "Called B #1");
a(mfn(3, 7), 10, "Result #3");
a(i, 2, "Called #3");
a(mfn(5, 8), 13, "Result B #2");
a(i, 2, "Called B #2");
setTimeout(function () {
a(mfn(3, 7), 10, "Result: Wait");
a(i, 2, "Called: Wait");
a(mfn(5, 8), 13, "Result: Wait B");
a(i, 2, "Called: Wait B");
setTimeout(function () {
a(mfn(3, 7), 10, "Result: Wait After");
a(i, 3, "Called: Wait After");
a(mfn(5, 8), 13, "Result: Wait After B");
a(i, 4, "Called: Wait After B");
a(mfn(3, 7), 10, "Result: Wait After #2");
a(i, 4, "Called: Wait After #2");
a(mfn(5, 8), 13, "Result: Wait After B #2");
a(i, 4, "Called: Wait After B #2");
d();
}, 100);
}, 20);
},
Async: function (a, d) {
var mfn,
fn,
u = {},
i = 0;
fn = function (x, y, cb) {
nextTick(function () {
++i;
cb(null, x + y);
});
return u;
};
mfn = memoize(fn, { async: true, primitive: true, maxAge: 100 });
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #1");
}),
u,
"Initial"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #2");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Result B #1");
}),
u,
"Initial #2"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #3");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Result B #2");
}),
u,
"Initial #3"
);
setTimeout(function () {
a(i, 2, "Called #2");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Again B: Result");
}),
u,
"Again B: Initial"
);
setTimeout(function () {
a(i, 2, "Again Called #2");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Again B: Result");
}),
u,
"Again B: Initial"
);
nextTick(function () {
a(i, 4, "Call After clear");
d();
});
}, 100);
}, 20);
},
Promise: function (a, d) {
var mfn,
fn,
i = 0;
fn = function (x, y, cb) {
return new Promise(function (res) {
++i;
res(x + y);
});
};
mfn = memoize(fn, { promise: true, primitive: true, maxAge: 100 });
mfn(3, 7).done(function (res) {
a.deep(res, 10, "Result #1");
});
mfn(3, 7).done(function (res) {
a.deep(res, 10, "Result #2");
});
mfn(5, 8).done(function (res) {
a.deep(res, 13, "Result B #1");
});
mfn(3, 7).done(function (res) {
a.deep(res, 10, "Result #3");
});
mfn(5, 8).done(function (res) {
a.deep(res, 13, "Result B #2");
});
setTimeout(function () {
a(i, 2, "Called #2");
mfn(3, 7).done(function (res) {
a.deep(res, 10, "Again: Result");
});
mfn(5, 8).done(function (res) {
a.deep(res, 13, "Again B: Result");
});
setTimeout(function () {
a(i, 2, "Again Called #2");
mfn(3, 7).done(function (res) {
a.deep(res, 10, "Again: Result");
});
mfn(5, 8).done(function (res) {
a.deep(res, 13, "Again B: Result");
});
nextTick(function () {
a(i, 4, "Call After clear");
d();
});
}, 100);
}, 20);
}
},
Refetch: {
Default: function (a, d) {
var mfn,
fn,
i = 0;
fn = function (x, y) {
++i;
return x + y;
};
mfn = memoize(fn, { maxAge: 600, preFetch: true });
a(mfn(3, 7), 10, "Result #1");
a(i, 1, "Called #1");
a(mfn(3, 7), 10, "Result #2");
a(i, 1, "Called #2");
a(mfn(5, 8), 13, "Result B #1");
a(i, 2, "Called B #1");
a(mfn(3, 7), 10, "Result #3");
a(i, 2, "Called #3");
a(mfn(5, 8), 13, "Result B #2");
a(i, 2, "Called B #2");
setTimeout(function () {
a(mfn(3, 7), 10, "Result: Wait");
a(i, 2, "Called: Wait");
a(mfn(5, 8), 13, "Result: Wait B");
a(i, 2, "Called: Wait B");
setTimeout(function () {
a(mfn(3, 7), 10, "Result: Wait After");
a(i, 2, "Called: Wait After");
a(mfn(5, 8), 13, "Result: Wait After B");
a(i, 2, "Called: Wait After B");
a(mfn(3, 7), 10, "Result: Wait After #2");
a(i, 2, "Called: Wait After #2");
a(mfn(5, 8), 13, "Result: Wait After B #2");
a(i, 2, "Called: Wait After B #2");
setTimeout(function () {
a(i, 4, "Called: After Refetch: Before");
a(mfn(3, 7), 10, "Result: After Refetch");
a(i, 4, "Called: After Refetch: After");
a(mfn(5, 8), 13, "Result: After Refetch B");
a(i, 4, "Called: After Refetch B: After");
setTimeout(function () {
a(mfn(3, 7), 10, "Result: After Refetch #2");
a(i, 4, "Called: After Refetch #2");
a(mfn(5, 8), 13, "Result: After Refetch #2 B");
a(i, 4, "Called: After Refetch #2 B");
a(mfn(3, 7), 10, "Result: After Refetch #3");
a(i, 4, "Called: After Refetch #3");
a(mfn(5, 8), 13, "Result: After Refetch #3 B");
a(i, 4, "Called: After Refetch #3 B");
d();
}, 200);
}, 200);
}, 200);
}, 300);
},
Async: function (a, d) {
var mfn,
fn,
i = 0;
fn = function (x, y, cb) {
++i;
setTimeout(function () {
cb(null, x + y);
}, 0);
};
mfn = memoize(fn, { maxAge: 600, preFetch: true, async: true });
mfn(3, 7, function (err, result) {
a(result, 10, "Result #1");
a(i, 1, "Called #1");
mfn(3, 7, function (err, result) {
a(result, 10, "Result #2");
a(i, 1, "Called #2");
mfn(5, 8, function (err, result) {
a(result, 13, "Result B #1");
a(i, 2, "Called B #1");
mfn(3, 7, function (err, result) {
a(result, 10, "Result #3");
a(i, 2, "Called #3");
mfn(5, 8, function (err, result) {
a(result, 13, "Result B #2");
a(i, 2, "Called B #2");
setTimeout(function () {
mfn(3, 7, function (err, result) {
a(result, 10, "Result: Wait");
a(i, 2, "Called: Wait");
mfn(5, 8, function (err, result) {
a(result, 13, "Result: Wait B");
a(i, 2, "Called: Wait B");
setTimeout(function () {
mfn(3, 7, function (err, result) {
a(result, 10, "Result: Wait After");
a(i, 2, "Called: Wait After");
mfn(5, 8, function (err, result) {
a(result, 13, "Result: Wait After B");
a(i, 3, "Called: Wait After B");
mfn(3, 7, function (err, result) {
a(
result,
10,
"Result: Wait After #2"
);
a(i, 4, "Called: Wait After #2");
mfn(5, 8, function (err, result) {
a(
result,
13,
"Result: Wait After B #2"
);
a(
i,
4,
"Called: Wait After B #2"
);
setTimeout(function () {
a(
i,
4,
"Called: After Refetch: Before"
);
mfn(3, 7, function (
err,
result
) {
a(
result,
10,
"Result: After Refetch"
);
a(
i,
4,
"Called: After Refetch: After"
);
mfn(5, 8, function (
err,
result
) {
a(
result,
13,
"Result: After Refetch B"
);
a(
i,
4,
"Called: After Refetch B: After"
);
setTimeout(
function () {
mfn(
3,
7,
function (
err,
result
) {
a(
result,
10,
"Result: After Refetch #2"
);
a(
i,
4,
"Called: After Refetch #2"
);
mfn(
5,
8,
function (
err,
result
) {
a(
result,
13,
"Result: After Refetch #2 B"
);
a(
i,
5,
"Called: After Refetch #2 B"
);
mfn(
3,
7,
function (
err,
result
) {
a(
result,
10,
"Result: After Refetch #3"
);
a(
i,
6,
"Called: After Refetch #3"
);
mfn(
5,
8,
function (
err,
result
) {
a(
result,
13,
"Result: After Refetch #3 B"
);
a(
i,
6,
"Called: After Refetch #3 B"
);
d();
}
);
}
);
}
);
}
);
},
200
);
});
});
}, 200);
});
});
});
});
}, 200);
});
});
}, 300);
});
});
});
});
});
},
Promise: function (a, d) {
var mfn,
fn,
i = 0;
fn = function (x, y) {
++i;
return new Promise(function (res) {
res(x + y);
});
};
mfn = memoize(fn, { maxAge: 600, preFetch: true, promise: true });
mfn(3, 7).done(function (result) {
a(result, 10, "Result #1");
a(i, 1, "Called #1");
mfn(3, 7).done(function (result) {
a(result, 10, "Result #2");
a(i, 1, "Called #2");
mfn(5, 8).done(function (result) {
a(result, 13, "Result B #1");
a(i, 2, "Called B #1");
mfn(3, 7).done(function (result) {
a(result, 10, "Result #3");
a(i, 2, "Called #3");
mfn(5, 8).done(function (result) {
a(result, 13, "Result B #2");
a(i, 2, "Called B #2");
setTimeout(function () {
mfn(3, 7).done(function (result) {
a(result, 10, "Result: Wait");
a(i, 2, "Called: Wait");
mfn(5, 8).done(function (result) {
a(result, 13, "Result: Wait B");
a(i, 2, "Called: Wait B");
setTimeout(function () {
mfn(3, 7).done(
delay(function (result) {
a(result, 10, "Result: Wait After");
a(i, 3, "Called: Wait After");
mfn(5, 8).done(
delay(function (result) {
a(
result,
13,
"Result: Wait After B"
);
a(i, 4, "Called: Wait After B");
mfn(3, 7).done(
delay(function (result) {
a(
result,
10,
"Result: Wait After #2"
);
a(
i,
4,
"Called: Wait After #2"
);
mfn(5, 8).done(function (
result
) {
a(
result,
13,
"Result: Wait After B #2"
);
a(
i,
4,
"Called: Wait After B #2"
);
setTimeout(
function () {
a(
i,
4,
"Called: After Refetch: Before"
);
mfn(
3,
7
).done(
function (
result
) {
a(
result,
10,
"Result: After Refetch"
);
a(
i,
4,
"Called: After Refetch: After"
);
mfn(
5,
8
).done(
function (
result
) {
a(
result,
13,
"Result: After Refetch B"
);
a(
i,
4,
"Called: After Refetch B: After"
);
setTimeout(
function () {
mfn(
3,
7
).done(
delay(
function (
result
) {
a(
result,
10,
"Result: After Refetch #2"
);
a(
i,
5,
"Called: After Refetch #2"
);
mfn(
5,
8
).done(
delay(
function (
result
) {
a(
result,
13,
"Result: After Refetch #2 B"
);
a(
i,
6,
"Called: After Refetch #2 B"
);
mfn(
3,
7
).done(
function (
result
) {
a(
result,
10,
"Result: After Refetch #3"
);
a(
i,
6,
"Called: After Refetch #3"
);
mfn(
5,
8
).done(
function (
result
) {
a(
result,
13,
"Result: After Refetch #3 B"
);
a(
i,
6,
"Called: After Refetch #3 B"
);
d();
}
);
}
);
},
0
)
);
},
0
)
);
},
200
);
}
);
}
);
},
200
);
});
})
);
}, 0)
);
}, 0)
);
}, 200);
});
});
}, 300);
});
});
});
});
});
},
Custom: function (a, d) {
var mfn,
fn,
i = 0;
fn = function (x, y) {
++i;
return x + y;
};
mfn = memoize(fn, { maxAge: 600, preFetch: 1 / 6 });
a(mfn(3, 7), 10, "Result #1");
a(i, 1, "Called #1");
a(mfn(3, 7), 10, "Result #2");
a(i, 1, "Called #2");
a(mfn(5, 8), 13, "Result B #1");
a(i, 2, "Called B #1");
a(mfn(3, 7), 10, "Result #3");
a(i, 2, "Called #3");
a(mfn(5, 8), 13, "Result B #2");
a(i, 2, "Called B #2");
setTimeout(function () {
a(mfn(3, 7), 10, "Result: Wait");
a(i, 2, "Called: Wait");
a(mfn(5, 8), 13, "Result: Wait B");
a(i, 2, "Called: Wait B");
setTimeout(function () {
a(mfn(3, 7), 10, "Result: Wait After");
a(i, 2, "Called: Wait After");
a(mfn(5, 8), 13, "Result: Wait After B");
a(i, 2, "Called: Wait After B");
a(mfn(3, 7), 10, "Result: Wait After #2");
a(i, 2, "Called: Wait After #2");
a(mfn(5, 8), 13, "Result: Wait After B #2");
a(i, 2, "Called: Wait After B #2");
setTimeout(function () {
a(i, 4, "Called: After Refetch: Before");
a(mfn(3, 7), 10, "Result: After Refetch");
a(i, 4, "Called: After Refetch: After");
a(mfn(5, 8), 13, "Result: After Refetch B");
a(i, 4, "Called: After Refetch B: After");
setTimeout(function () {
a(mfn(3, 7), 10, "Result: After Refetch #2");
a(i, 4, "Called: After Refetch #2");
a(mfn(5, 8), 13, "Result: After Refetch #2 B");
a(i, 4, "Called: After Refetch #2 B");
a(mfn(3, 7), 10, "Result: After Refetch #3");
a(i, 4, "Called: After Refetch #3");
a(mfn(5, 8), 13, "Result: After Refetch #3 B");
a(i, 4, "Called: After Refetch #3 B");
d();
}, 200);
}, 300);
}, 100);
}, 450);
}
}
};
};

1677
static/js/ketcher2/node_modules/memoizee/test/ext/max.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,285 @@
/* eslint id-length: 0, handle-callback-err: 0, no-undef: 0, no-unused-vars: 0, func-names: 0 */
"use strict";
var memoize = require("../..")
, nextTick = require("next-tick")
, Promise = require("plain-promise");
module.exports = function () {
return {
"Regular": {
Success: function (a, d) {
var mfn, fn, i = 0, invoked = 0;
fn = function (x, y) {
return new Promise(function (res) {
++i;
res(x + y);
});
};
mfn = memoize(fn, { promise: true });
mfn(3, 7).done(function (res) {
++invoked;
a(res, 10, "Result #1");
}, a.never);
mfn(3, 7).done(function (res) {
++invoked;
a(res, 10, "Result #2");
}, a.never);
mfn(5, 8).done(function (res) {
++invoked;
a(res, 13, "Result B #1");
}, a.never);
mfn(3, 7).done(function (res) {
++invoked;
a(res, 10, "Result #3");
}, a.never);
mfn(5, 8).done(function (res) {
++invoked;
a(res, 13, "Result B #2");
}, a.never);
setTimeout(function () {
a(i, 2, "Init Called");
a(invoked, 5, "Cb Called");
mfn(3, 7).done(function (res) {
++invoked;
a(res, 10, "Again: Result");
}, a.never);
mfn(5, 8).done(function (res) {
++invoked;
a(res, 13, "Again B: Result");
}, a.never);
setTimeout(function () {
a(i, 2, "Init Called #2");
a(invoked, 7, "Cb Called #2");
mfn.delete(3, 7);
mfn(3, 7).done(function (res) {
++invoked;
a(res, 10, "Again: Result");
}, a.never);
mfn(5, 8).done(function (res) {
++invoked;
a(res, 13, "Again B: Result");
}, a.never);
setTimeout(function () {
a(i, 3, "Init After delete");
a(invoked, 9, "Cb After delete");
d();
}, 10);
}, 10);
}, 10);
},
Error: function (a, d) {
var mfn, fn, i = 0, e = new Error("Test");
fn = function (x, y) {
++i;
return new Promise(function (res, rej) {
rej(e);
});
};
mfn = memoize(fn, { promise: "done", dispose: a.never });
mfn(3, 7).done(a.never, function (err) {
a(err, e, "Result #1");
});
mfn(5, 8).done(a.never, function (err) {
a(err, e, "Result B #2");
});
setTimeout(function () {
a(i, 2, "Called #2");
mfn(3, 7).done(a.never, function (err) {
a(err, e, "Again: Result");
});
mfn(5, 8).done(a.never, function (err) {
a(err, e, "Again B: Result");
});
setTimeout(function (err) {
a(i, 4, "Again Called #2");
d();
}, 10);
}, 10);
}
},
"Primitive": {
"Success": function (a, d) {
var mfn, fn, i = 0;
fn = function (x, y) {
return new Promise(function (res) {
++i;
res(x + y);
});
};
mfn = memoize(fn, { promise: true, primitive: true });
mfn(3, 7).done(function (res) {
a(res, 10, "Result #1");
}, a.never);
mfn(3, 7).done(function (res) {
a(res, 10, "Result #2");
}, a.never);
mfn(5, 8).done(function (res) {
a(res, 13, "Result B #1");
}, a.never);
mfn(3, 7).done(function (res) {
a(res, 10, "Result #3");
}, a.never);
mfn(5, 8).done(function (res) {
a(res, 13, "Result B #2");
}, a.never);
setTimeout(function () {
a(i, 2, "Called #2");
mfn(3, 7).done(function (res) {
a(res, 10, "Again: Result");
}, a.never);
mfn(5, 8).done(function (res) {
a(res, 13, "Again B: Result");
}, a.never);
setTimeout(function () {
a(i, 2, "Again Called #2");
mfn.delete(3, 7);
mfn(3, 7).done(function (res) {
a(res, 10, "Again: Result");
}, a.never);
mfn(5, 8).done(function (res) {
a(res, 13, "Again B: Result");
}, a.never);
setTimeout(function () {
a(i, 3, "Call After delete");
d();
}, 10);
}, 10);
}, 10);
},
"Error": function (a, d) {
var mfn, fn, i = 0, e = new Error("Test");
fn = function (x, y) {
return new Promise(function (res, rej) {
++i;
rej(e);
});
};
mfn = memoize(fn, { promise: "done", primitive: true });
mfn(3, 7).done(a.never, function (err) {
a(err, e, "Result #1");
});
mfn(5, 8).done(a.never, function (err) {
a(err, e, "Result B #2");
});
setTimeout(function () {
a(i, 2, "Called #2");
mfn(3, 7).done(a.never, function (err) {
a(err, e, "Again: Result");
});
mfn(5, 8).done(a.never, function (err) {
a(err, e, "Again B: Result");
});
setTimeout(function (err) {
a(i, 4, "Again Called #2");
d();
}, 10);
}, 10);
},
"Primitive null arg case": function (a, d) {
var mfn, x = {};
mfn = memoize(
function f(id) {
return new Promise(function (res) {
res(x);
});
},
{
promise: true,
primitive: true
}
);
mfn(null).done(function (res) {
a.deep(res, x, "Args");
d();
}, a.never);
}
},
"Sync Clear": function (a, d) {
var mfn, fn;
fn = function (x) {
return new Promise(function (res) {
nextTick(function () {
res(x);
});
});
};
mfn = memoize(fn, { promise: true });
mfn(1).done(function (res) {
a(res, 1, "First");
}, a.never);
mfn(2).done(function (res) {
a(res, 2, "Second");
d();
}, a.never);
},
"Sync Clear: Primitive": function (a, d) {
var mfn, fn;
fn = function (x) {
return new Promise(function (res) {
nextTick(function () {
res(x);
});
});
};
mfn = memoize(fn, { promise: true, primitive: true });
mfn(1).done(function (res) {
a(res, 1, "First");
}, a.never);
mfn(2).done(function (res) {
a(res, 2, "Second");
d();
}, a.never);
}
};
};

View File

@ -0,0 +1,380 @@
/* eslint max-lines: 0, id-length: 0, no-undef: 0 */
"use strict";
var memoize = require("../..")
, nextTick = require("next-tick")
, Promise = require("plain-promise");
module.exports = function () {
return {
"Regular": function (a) {
var i = 0
, fn = function (x, y, z) {
++i;
return x + y + z;
}
, mfn;
mfn = memoize(fn, { refCounter: true });
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.deleteRef(3, 5, 7), false, "Delete #1");
mfn(3, 5, 7);
a(mfn.deleteRef(3, 5, 7), false, "Delete #2");
mfn(3, 5, 7);
a(mfn.deleteRef(3, 5, 7), false, "Delete #3");
mfn(3, 5, 7);
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);
a(i, 2, "Restarted");
mfn(3, 5, 7);
a(i, 2, "Cached again");
},
"Regular: Async": function (a, d) {
var mfn, fn, u = {}, i = 0;
fn = function (x, y, cb) {
nextTick(function () {
++i;
cb(null, x + y);
});
return u;
};
mfn = memoize(fn, { async: true, refCounter: true });
a(mfn.deleteRef(3, 7), null, "Delete ref before");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #1");
}),
u,
"Initial"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #2");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Result B #1");
}),
u,
"Initial #2"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #3");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Result B #2");
}),
u,
"Initial #3"
);
nextTick(function () {
a(i, 2, "Called #2");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Again B: Result");
}),
u,
"Again B: Initial"
);
nextTick(function () {
a(i, 2, "Again Called #2");
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");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Again B: Result");
}),
u,
"Again B: Initial"
);
nextTick(function () {
a(i, 3, "Call After delete");
d();
});
});
});
},
"Regular: Promise": function (a, d) {
var mfn, fn, i = 0;
fn = function (x, y) {
++i;
return new Promise(function (res) {
res(x + y);
});
};
mfn = memoize(fn, { promise: true, refCounter: true });
a(mfn.deleteRef(3, 7), null, "Delete ref before");
mfn(3, 7).done(function (res) {
a(res, 10, "Result #1");
});
mfn(3, 7).done(function (res) {
a(res, 10, "Result #2");
});
mfn(5, 8).done(function (res) {
a(res, 13, "Result B #1");
});
mfn(3, 7).done(function (res) {
a(res, 10, "Result #3");
});
mfn(5, 8).done(function (res) {
a(res, 13, "Result B #2");
});
setTimeout(function () {
a(i, 2, "Called #2");
mfn(3, 7).done(function (res) {
a(res, 10, "Again: Result");
});
mfn(5, 8).done(function (res) {
a(res, 13, "Again B: Result");
});
setTimeout(function () {
a(i, 2, "Again Called #2");
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");
mfn(3, 7).done(function (res) {
a(res, 10, "Again: Result");
});
mfn(5, 8).done(function (res) {
a(res, 13, "Again B: Result");
});
setTimeout(function () {
a(i, 3, "Call After delete");
d();
}, 10);
}, 10);
}, 10);
},
"Primitive": function (a) {
var i = 0
, fn = function (x, y, z) {
++i;
return x + y + z;
}
, mfn;
mfn = memoize(fn, { primitive: true, refCounter: true });
a(mfn.deleteRef(3, 5, 7), null, "Delete before");
a(mfn(3, 5, 7), 15, "Initial");
a(mfn(3, 5, 7), 15, "Cache");
a(mfn.deleteRef(3, 5, 7), false, "Delete #1");
mfn(3, 5, 7);
a(mfn.deleteRef(3, 5, 7), false, "Delete #2");
mfn(3, 5, 7);
a(mfn.deleteRef(3, 5, 7), false, "Delete #3");
mfn(3, 5, 7);
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);
a(i, 2, "Restarted");
mfn(3, 5, 7);
a(i, 2, "Cached again");
},
"Primitive: Async": function (a, d) {
var mfn, fn, u = {}, i = 0;
fn = function (x, y, cb) {
nextTick(function () {
++i;
cb(null, x + y);
});
return u;
};
mfn = memoize(fn, { async: true, primitive: true, refCounter: true });
a(mfn.deleteRef(3, 7), null, "Delete ref before");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #1");
}),
u,
"Initial"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #2");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Result B #1");
}),
u,
"Initial #2"
);
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #3");
}),
u,
"Initial #2"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Result B #2");
}),
u,
"Initial #3"
);
nextTick(function () {
a(i, 2, "Called #2");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Again B: Result");
}),
u,
"Again B: Initial"
);
nextTick(function () {
a(i, 2, "Again Called #2");
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");
a(
mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Again: Result");
}),
u,
"Again: Initial"
);
a(
mfn(5, 8, function (err, res) {
a.deep([err, res], [null, 13], "Again B: Result");
}),
u,
"Again B: Initial"
);
nextTick(function () {
a(i, 3, "Call After delete");
d();
});
});
});
},
"Primitive: Promise": function (a, d) {
var mfn, fn, i = 0;
fn = function (x, y) {
++i;
return new Promise(function (res) {
res(x + y);
});
};
mfn = memoize(fn, { promise: true, primitive: true, refCounter: true });
a(mfn.deleteRef(3, 7), null, "Delete ref before");
mfn(3, 7).done(function (res) {
a(res, 10, "Result #1");
});
mfn(3, 7).done(function (res) {
a(res, 10, "Result #2");
});
mfn(5, 8).done(function (res) {
a(res, 13, "Result B #1");
});
mfn(3, 7).done(function (res) {
a(res, 10, "Result #3");
});
mfn(5, 8).done(function (res) {
a(res, 13, "Result B #2");
});
setTimeout(function () {
a(i, 2, "Called #2");
mfn(3, 7).done(function (res) {
a(res, 10, "Again: Result");
});
mfn(5, 8).done(function (res) {
a(res, 13, "Again B: Result");
});
setTimeout(function () {
a(i, 2, "Again Called #2");
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");
mfn(3, 7).done(function (res) {
a(res, 10, "Again: Result");
});
mfn(5, 8).done(function (res) {
a(res, 13, "Again B: Result");
});
setTimeout(function () {
a(i, 3, "Call After delete");
d();
}, 10);
}, 10);
}, 10);
}
};
};

2474
static/js/ketcher2/node_modules/memoizee/test/index.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,156 @@
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
"use strict";
var aFrom = require("es5-ext/array/from")
, memoize = require("../..");
module.exports = function () {
return {
"One arg": function (a) {
var i = 0
, fn = function (x) {
++i;
return x;
}
, mfn
, y = {
toString: function () {
return "foo";
}
};
mfn = memoize(fn, { primitive: true });
a(mfn(y), y, "#1");
a(mfn("foo"), y, "#2");
a(i, 1, "Called once");
},
"No args": function (a) {
var i = 0
, fn = function () {
++i;
return "foo";
}
, mfn
, y = {
toString: function () {
return "foo";
}
};
mfn = memoize(fn);
a(mfn._has(), false);
a(mfn(), "foo", "#1");
a(mfn._has(), true);
mfn();
a(i, 1, "Called once");
},
"Clear cache": function (a) {
var i = 0
, fn = function (x, y, z) {
++i;
return x + y + z;
}
, mfn
, y = {
toString: function () {
return "foo";
}
};
mfn = memoize(fn, { primitive: true });
a(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
a(i, 1, "Called once");
mfn.delete(
"foo",
{
toString: function () {
return "bar";
}
},
"zeta"
);
a(mfn(y, "bar", "zeta"), "foobarzeta", "#3");
a(i, 2, "Called twice");
},
"_get": function (a) {
var fn = function (x) {
return x;
}
, mfn;
mfn = memoize(fn);
a(mfn._get("foo"), undefined);
mfn("foo");
a(mfn._get("foo"), "foo");
},
"_has": function (a) {
var fn = function (x) {
return x;
}
, mfn;
mfn = memoize(fn);
a(mfn._has("foo"), false);
mfn("foo");
a(mfn._has("foo"), true);
},
"Circular": function (a) {
var i = 0, fn;
fn = memoize(function (x) {
if (++i < 2) fn(x);
});
a.throws(function () {
fn("foo");
}, "CIRCULAR_INVOCATION");
i = 0;
fn = memoize(function (x, y) {
if (++i < 2) fn(x, y);
});
a.throws(function () {
fn("foo", "bar");
}, "CIRCULAR_INVOCATION");
},
"Resolvers": function () {
var i = 0, fn, r;
fn = memoize(
function () {
++i;
return arguments;
},
{ length: 3, resolvers: [Boolean, String] }
);
return {
"No args": function (a) {
i = 0;
a.deep(aFrom(r = fn()), [false, "undefined"], "First");
a(fn(), r, "Second");
a(fn(), r, "Third");
a(i, 1, "Called once");
},
"One arg": function (a) {
var fn = memoize(
function (elo) {
++i;
return arguments;
},
{ resolvers: [Boolean] }
);
a.deep(aFrom(r = fn("elo")), [true], "First");
},
"Some Args": function (a) {
var x = {};
i = 0;
a.deep(aFrom(r = fn(0, 34, x, 45)), [false, "34", x, 45], "First");
a(fn(0, 34, x, 22), r, "Second");
a(fn(0, 34, x, false), r, "Third");
a(i, 1, "Called once");
return {
Other: function (a) {
a.deep(aFrom(r = fn(1, 34, x, 34)), [true, "34", x, 34], "Second");
a(fn(1, 34, x, 89), r, "Third");
a(i, 2, "Called once");
}
};
}
};
}
};
};

View File

@ -0,0 +1,50 @@
/* eslint id-length: 0 */
"use strict";
var d = require("d")
, memoize = require("../..");
require("../ext/dispose");
require("../ext/ref-counter");
module.exports = function (t, a) {
var value = [], obj = {};
t = t(memoize);
Object.defineProperties(
obj,
t({
someFn: d(
function (x, y) {
a(this, obj);
return x + y;
},
{
refCounter: true,
dispose: function (val) {
value.push(val);
}
}
)
})
);
obj = Object.create(obj);
obj.someFn(3, 7);
obj.someFn(5, 8);
obj.someFn(12, 4);
a.deep(value, [], "Pre");
obj.someFn(5, 8);
obj.someFn.deleteRef(5, 8);
a.deep(value, [], "Pre");
obj.someFn.deleteRef(5, 8);
a.deep(value, [13], "#1");
value = [];
obj.someFn.deleteRef(12, 4);
a.deep(value, [16], "#2");
value = [];
obj.someFn(77, 11);
obj.someFn.clear();
a.deep(value, [10, 88], "Clear");
};

View File

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

View File

@ -0,0 +1,10 @@
"use strict";
module.exports = function (t, a) {
a(t(1, 2), 1, "Options");
a(t(1, 2, true), 1, "Options: Async ");
a(t(undefined, 2), 2, "Function");
a(t(undefined, 2, true), 1, "Function: Async");
a(t(undefined, undefined, false), 1, "Unknown");
a(t(undefined, undefined, true), 1, "Unknown: async");
};

View File

@ -0,0 +1,9 @@
/* eslint no-empty-function: 0 */
"use strict";
module.exports = function (t, a) {
var fn = function () {}, resolved = t(fn);
a.deep(resolved, { get: fn, set: fn });
a.deep(t(resolved), { get: fn, set: fn });
};

View File

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

View File

@ -0,0 +1,53 @@
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
"use strict";
var memoize = require("../..");
require("../ext/dispose");
require("../ext/ref-counter");
module.exports = function (t, a) {
var value = [], obj = {}, memoized, count = 0, x, y, z;
t = t(memoize);
memoized = t(
function (arg, x, y) {
a(arg, obj);
return x + y;
},
{
refCounter: true,
dispose: function (val) {
value.push(val);
}
}
);
a(memoized(obj, 3, 7), 10);
a(memoized(obj, 5, 8), 13);
a(memoized(obj, 12, 4), 16);
a.deep(value, [], "Pre");
a(memoized(obj, 5, 8), 13);
memoized.deleteRef(obj, 5, 8);
a.deep(value, [], "Pre");
memoized.deleteRef(obj, 5, 8);
a.deep(value, [13], "#1");
value = [];
memoized.deleteRef(obj, 12, 4);
a.deep(value, [16], "#2");
value = [];
memoized(obj, 77, 11);
x = {};
y = {};
z = {};
memoized = t(function (arg) {
return ++count;
});
a(memoized(x), 1);
a(memoized(y), 2);
a(memoized(x), 1);
a(memoized(z), 3);
a(count, 3);
};

View File

@ -0,0 +1,48 @@
/* eslint id-length: 0 */
"use strict";
var d = require("d");
require("../ext/dispose");
require("../ext/ref-counter");
module.exports = function (t, a) {
var value = [], obj = {};
Object.defineProperties(
obj,
t({
someFn: d(
function (x, y) {
a(this, obj);
return x + y;
},
{
refCounter: true,
dispose: function (val) {
value.push(val);
}
}
)
})
);
obj = Object.create(obj);
obj.someFn(3, 7);
obj.someFn(5, 8);
obj.someFn(12, 4);
a.deep(value, [], "Pre");
obj.someFn(5, 8);
obj.someFn.deleteRef(5, 8);
a.deep(value, [], "Pre");
obj.someFn.deleteRef(5, 8);
a.deep(value, [13], "#1");
value = [];
obj.someFn.deleteRef(12, 4);
a.deep(value, [16], "#2");
value = [];
obj.someFn(77, 11);
obj.someFn.clear();
a.deep(value, [10, 88], "Clear all");
};

View File

@ -0,0 +1,45 @@
/* eslint id-length: 0 */
"use strict";
var d = require("d");
module.exports = function (t, a) {
var value = [], obj = {};
Object.defineProperties(
obj,
t({
someFn: d(
function (x, y) {
a(this, obj);
return x + y;
},
{
refCounter: true,
dispose: function (val) {
value.push(val);
}
}
)
})
);
obj = Object.create(obj);
obj.someFn(3, 7);
obj.someFn(5, 8);
obj.someFn(12, 4);
a.deep(value, [], "Pre");
obj.someFn(5, 8);
obj.someFn.deleteRef(5, 8);
a.deep(value, [], "Pre");
obj.someFn.deleteRef(5, 8);
a.deep(value, [13], "#1");
value = [];
obj.someFn.deleteRef(12, 4);
a.deep(value, [16], "#2");
value = [];
obj.someFn(77, 11);
obj.someFn.clear();
a.deep(value, [10, 88], "Clear all");
};

View File

@ -0,0 +1,62 @@
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
"use strict";
var memoize = require("../..");
module.exports = {
"": function (t, a) {
var i = 0
, fn = function (x) {
++i;
return x;
};
fn = memoize(fn);
return {
"No arg": function () {
i = 0;
a(fn(), undefined, "First");
a(fn(), undefined, "Second");
a(fn(), undefined, "Third");
a(i, 1, "Called once");
},
"Arg": function () {
var x = {};
i = 0;
a(fn(x, 8), x, "First");
a(fn(x, 4), x, "Second");
a(fn(x, 2), x, "Third");
a(i, 1, "Called once");
},
"Other Arg": function () {
var x = {};
i = 0;
a(fn(x, 2), x, "First");
a(fn(x, 9), x, "Second");
a(fn(x, 3), x, "Third");
a(i, 1, "Called once");
}
};
},
"Delete": function (a) {
var i = 0, fn, mfn, x = {};
fn = function (a, b, c) {
return a + ++i;
};
mfn = memoize(fn, { length: 1 });
a(mfn(3), 4, "Init");
a(mfn(4, x, 1), 6, "Init #2");
mfn.delete(4);
a(mfn(3, x, 1), 4, "Cached");
mfn(3, x, 1);
a(i, 2, "Pre clear");
mfn.delete(3, x, 1);
a(i, 2, "After clear");
a(mfn(3, x, 1), 6, "Reinit");
a(i, 3, "Reinit count");
a(mfn(3, x, 1), 6, "Reinit Cached");
a(i, 3, "Reinit count");
}
};

View File

@ -0,0 +1,98 @@
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
"use strict";
var memoize = require("../..");
module.exports = {
"": function (a) {
var i = 0
, fn = function (x, y, z) {
++i;
return [x, y, z];
}
, r;
fn = memoize(fn);
return {
"No args": function () {
i = 0;
a.deep(r = fn(), [undefined, undefined, undefined], "First");
a(fn(), r, "Second");
a(fn(), r, "Third");
a(i, 1, "Called once");
},
"Some Args": function () {
var x = {};
i = 0;
a.deep(r = fn(x, 8), [x, 8, undefined], "First");
a(fn(x, 8), r, "Second");
a(fn(x, 8), r, "Third");
a(i, 1, "Called once");
return {
Other: function () {
a.deep(r = fn(x, 5), [x, 5, undefined], "Second");
a(fn(x, 5), r, "Third");
a(i, 2, "Called once");
}
};
},
"Full stuff": function () {
var x = {};
i = 0;
a.deep(r = fn(x, 8, 23, 98), [x, 8, 23], "First");
a(fn(x, 8, 23, 43), r, "Second");
a(fn(x, 8, 23, 9), r, "Third");
a(i, 1, "Called once");
return {
Other: function () {
a.deep(r = fn(x, 23, 8, 13), [x, 23, 8], "Second");
a(fn(x, 23, 8, 22), r, "Third");
a(i, 2, "Called once");
}
};
}
};
},
"Delete": function (a) {
var i = 0, fn, mfn, x = {};
fn = function (a, b, c) {
return a + ++i;
};
mfn = memoize(fn);
a(mfn(3, x, 1), 4, "Init");
a(mfn(4, x, 1), 6, "Init #2");
mfn.delete(4, x, 1);
a(mfn(3, x, 1), 4, "Cached");
mfn(3, x, 1);
a(i, 2, "Pre clear");
mfn.delete(3, x, 1);
a(i, 2, "After clear");
a(mfn(3, x, 1), 6, "Reinit");
a(i, 3, "Reinit count");
a(mfn(3, x, 1), 6, "Reinit Cached");
a(i, 3, "Reinit count");
},
"Clear": function (a) {
var i = 0, fn, x = {};
fn = function () {
++i;
return arguments;
};
fn = memoize(fn, { length: 3 });
fn(1, x, 3);
fn(1, x, 4);
fn(1, x, 3);
fn(1, x, 4);
a(i, 2, "Pre clear");
fn.clear();
fn(1, x, 3);
fn(1, x, 4);
fn(1, x, 3);
fn(1, x, 4);
a(i, 4, "After clear");
}
};

View File

@ -0,0 +1,70 @@
/* eslint id-length: 0 */
"use strict";
var memoize = require("../..");
module.exports = {
"": function (a) {
var i = 0
, fn = function (x, y, z) {
++i;
return x + y + z;
}
, mfn
, y = {
toString: function () {
return "foo";
}
};
mfn = memoize(fn, { primitive: true });
a(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
a(i, 1, "Called once");
},
"Delete": function (a) {
var i = 0
, fn = function (x, y, z) {
++i;
return x + y + z;
}
, mfn
, y = {
toString: function () {
return "foo";
}
};
mfn = memoize(fn, { primitive: true });
a(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
a(i, 1, "Called once");
mfn.delete(
"foo",
{
toString: function () {
return "bar";
}
},
"zeta"
);
a(mfn(y, "bar", "zeta"), "foobarzeta", "#3");
a(i, 2, "Called twice");
},
"Clear": function (a) {
var i = 0, fn;
fn = memoize(function (x) {
if (++i < 2) fn(x);
});
a.throws(function () {
fn("foo");
}, "CIRCULAR_INVOCATION");
i = 0;
fn = memoize(function (x, y) {
if (++i < 2) fn(x, y);
});
a.throws(function () {
fn("foo", "bar");
}, "CIRCULAR_INVOCATION");
}
};

View File

@ -0,0 +1,66 @@
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
"use strict";
var aFrom = require("es5-ext/array/from")
, memoize = require("../..");
module.exports = function () {
return {
"": function (a) {
var i = 0
, fn = function () {
++i;
return arguments;
}
, r;
fn = memoize(fn, { length: false });
return {
"No args": function () {
i = 0;
a.deep(aFrom(r = fn()), [], "First");
a(fn(), r, "Second");
a(fn(), r, "Third");
a(i, 1, "Called once");
},
"Some Args": function () {
var x = {};
i = 0;
a.deep(aFrom(r = fn(x, 8)), [x, 8], "First");
a(fn(x, 8), r, "Second");
a(fn(x, 8), r, "Third");
a(i, 1, "Called once");
},
"Many args": function () {
var x = {};
i = 0;
a.deep(aFrom(r = fn(x, 8, 23, 98)), [x, 8, 23, 98], "First");
a(fn(x, 8, 23, 98), r, "Second");
a(fn(x, 8, 23, 98), r, "Third");
a(i, 1, "Called once");
}
};
},
"Delete": function (a) {
var i = 0, fn, mfn, x = {};
fn = function (a, b, c) {
return a + ++i;
};
mfn = memoize(fn, { length: false });
a(mfn(3, x, 1), 4, "Init");
a(mfn(4, x, 1), 6, "Init #2");
mfn.delete(4, x, 1);
a(mfn(3, x, 1), 4, "Cached");
mfn(3, x, 1);
a(i, 2, "Pre clear");
mfn.delete(3, x, 1);
a(i, 2, "After clear");
a(mfn(3, x, 1), 6, "Reinit");
a(i, 3, "Reinit count");
a(mfn(3, x, 1), 6, "Reinit Cached");
a(i, 3, "Reinit count");
}
};
};

View File

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

56
static/js/ketcher2/node_modules/memoizee/test/plain.js generated vendored Normal file
View File

@ -0,0 +1,56 @@
/* eslint id-length: 0 */
"use strict";
module.exports = function (t) {
return {
"": function (a) {
var i = 0
, fn = function (x) {
++i;
return x;
}
, mfn
, y = {
toString: function () {
return "foo";
}
};
mfn = t(fn, { primitive: true });
a(typeof mfn, "function", "Returns");
a(mfn.__memoized__, true, "Marked");
a(t(mfn), mfn, "Do not memoize memoized");
a(mfn(y), y, "#1");
a(mfn("foo"), y, "#2");
a(i, 1, "Called once");
},
"Clear cache": function (a) {
var i = 0
, fn = function (x, y, z) {
++i;
return x + y + z;
}
, mfn
, y = {
toString: function () {
return "foo";
}
};
mfn = t(fn, { primitive: true });
a(mfn(y, "bar", "zeta"), "foobarzeta", "#1");
a(mfn("foo", "bar", "zeta"), "foobarzeta", "#2");
a(i, 1, "Called once");
mfn.delete(
"foo",
{
toString: function () {
return "bar";
}
},
"zeta"
);
a(mfn(y, "bar", "zeta"), "foobarzeta", "#3");
a(i, 2, "Called twice");
}
};
};

View File

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

View File

@ -0,0 +1,50 @@
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
"use strict";
require("../ext/dispose");
require("../ext/ref-counter");
module.exports = function (t, a) {
var value = [], obj = {}, memoized, count = 0, x, y, z;
memoized = t(
function (arg, x, y) {
a(arg, obj);
return x + y;
},
{
refCounter: true,
dispose: function (val) {
value.push(val);
}
}
);
a(memoized(obj, 3, 7), 10);
a(memoized(obj, 5, 8), 13);
a(memoized(obj, 12, 4), 16);
a.deep(value, [], "Pre");
a(memoized(obj, 5, 8), 13);
memoized.deleteRef(obj, 5, 8);
a.deep(value, [], "Pre");
memoized.deleteRef(obj, 5, 8);
a.deep(value, [13], "#1");
value = [];
memoized.deleteRef(obj, 12, 4);
a.deep(value, [16], "#2");
value = [];
memoized(obj, 77, 11);
x = {};
y = {};
z = {};
memoized = t(function (arg) {
return ++count;
});
a(memoized(x), 1);
a(memoized(y), 2);
a(memoized(x), 1);
a(memoized(z), 3);
a(count, 3);
};

62
static/js/ketcher2/node_modules/memoizee/test/weak.js generated vendored Normal file
View File

@ -0,0 +1,62 @@
/* eslint id-length: 0, no-shadow: 0, no-unused-vars: 0 */
"use strict";
module.exports = function (t, a, d) {
var value = [], obj = {}, memoized, count = 0, x, y, z;
memoized = t(
function (arg, x, y) {
a(arg, obj);
return x + y;
},
{
refCounter: true,
dispose: function (val) {
value.push(val);
}
}
);
a(memoized(obj, 3, 7), 10);
a(memoized(obj, 5, 8), 13);
a(memoized(obj, 12, 4), 16);
a.deep(value, [], "Pre");
a(memoized(obj, 5, 8), 13);
memoized.deleteRef(obj, 5, 8);
a.deep(value, [], "Pre");
memoized.deleteRef(obj, 5, 8);
a.deep(value, [13], "#1");
value = [];
memoized.deleteRef(obj, 12, 4);
a.deep(value, [16], "#2");
value = [];
memoized(obj, 77, 11);
x = {};
y = {};
z = {};
memoized = t(function (arg) {
return ++count;
});
a(memoized(x), 1);
a(memoized(y), 2);
a(memoized(x), 1);
a(memoized(z), 3);
a(count, 3);
count = 0;
memoized = t(
function (arg) {
return ++count;
},
{ maxAge: 1 }
);
memoized(obj);
setTimeout(function () {
memoized(obj);
a(count, 2);
d();
}, 100);
};

View File

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

3
static/js/ketcher2/node_modules/memoizee/weak.js generated vendored Normal file
View File

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