fix: prevent asset conflicts between React and Grid.js versions

Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

7
node_modules/rememo/LICENSE.md generated vendored Normal file
View File

@@ -0,0 +1,7 @@
[The MIT License (MIT)](https://opensource.org/licenses/MIT)
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.

163
node_modules/rememo/README.md generated vendored Normal file
View File

@@ -0,0 +1,163 @@
# Rememo
Memoized selectors for Redux and other immutable object derivation.
## Usage
Rememo's default export is a function which accepts two arguments: the selector function whose return value is to be cached, and a second function which returns the reference or array of references upon which the selector's derivation depends. The return value is a new function which accepts the same arguments as the selector.
```js
import createSelector from 'rememo';
const getTasksByCompletion = createSelector(
// The expensive computation:
(state, isComplete) =>
state.todo.filter((task) => task.complete === isComplete),
// The reference(s) upon which the computation depends:
(state) => [state.todo]
);
// The selector will only calculate the return value once so long as the state
// `todo` reference remains the same
let completedTasks;
completedTasks = getTasksByCompletion(state, true); // Computed
completedTasks = getTasksByCompletion(state, true); // Returned from cache
```
## Installation
Rememo is published as an [npm](https://www.npmjs.com/) package:
```
npm install rememo
```
Browser-ready versions are available from [unpkg](https://unpkg.com/rememo/dist/rememo.min.js). The browser-ready version assigns itself on the global scope as `window.rememo`.
```html
<script src="https://unpkg.com/rememo/dist/rememo.min.js"></script>
<script>
var createSelector = window.rememo;
// ...
</script>
```
## API
Rememo's default export is a function:
```typescript
createSelector(
selector: (...args: any[]) => any,
getDependants?: (...args: any[]) => any[],
): (...args: any[]) => any
```
The returned function is a memoized selector with the following signature:
```typescript
memoizedSelector(source: object, ...args: any[]): any
```
It's expected that the first argument to the memoized function is the source from which the selector operates. It is ignored when considering whether the argument result has already been cached.
The memoized selector function includes two additional properties:
- `clear()`: When invoked, resets memoization cache.
- `getDependants(source: Object, ...args: any[])`: The dependants getter for the selector.
The `getDependants` property can be useful when creating selectors which compose other memoized selectors, in which case the dependants are the union of the two selectors' dependants:
```js
const getTasksByCompletion = createSelector(
(state, isComplete) =>
state.todo.filter((task) => task.complete === isComplete),
(state) => [state.todo]
);
const getTasksByCompletionForCurrentDate = createSelector(
(state, isComplete) =>
getTasksByCompletion(state, isComplete).filter(
(task) => task.date === state.currentDate
),
(state, isComplete) => [
...getTasksByCompletion.getDependants(state, isComplete),
state.currentDate,
]
);
```
## Motivation
While designed specifically for use with [Redux](http://redux.js.org/), Rememo is a simple pattern for efficiently deriving values from any immutable data object. Rememo takes advantage of Redux's [core principles](http://redux.js.org/docs/introduction/ThreePrinciples.html) of [data normalization](http://redux.js.org/docs/recipes/reducers/NormalizingStateShape.html) and [immutability](http://redux.js.org/docs/faq/ImmutableData.html). While tracking normalized data in a Redux store is beneficial for eliminating redudancy and reducing overall memory storage, in doing so it sacrifices conveniences that would otherwise make for a pleasant developer experience. It's for this reason that a selector pattern can be desirable. A selector is nothing more than a function which receives the current state and optionally a set of arguments to be used in determining the calculated value.
For example, consider the following state structure to describe a to-do list application:
```js
const state = {
todo: [
{ text: 'Go to the gym', complete: true },
{ text: 'Try to spend time in the sunlight', complete: false },
{ text: 'Laundry must be done', complete: true },
],
};
```
If we wanted to filter tasks by completion, we could write a simple function:
```js
function getTasksByCompletion(state, isComplete) {
return state.todo.filter((task) => task.complete === isComplete);
}
```
This works well enough and requires no additional tools, but you'll observe that the filtering we perform on the set of to-do tasks could become costly if we were to have thousands of tasks. And this is just a simple example; real-world use cases could involve far more expensive computation. Add to this the very real likelihood that our application might call this function many times even when our to-do set has not changed.
Furthermore, when used in combination with [`React.PureComponent`](https://reactjs.org/docs/react-api.html#reactpurecomponent) or [`react-redux`](https://github.com/reactjs/react-redux)'s `connect` — which creates pure components by default — it is advisable to pass unchanging object and array references as props on subsequent renders. A selector which returns a new reference on each invocation (as occurs with `Array#map` or `Array#filter`), your component will needlessly render even if the underlying data does not change.
This is where Rememo comes in: a Rememo selector will cache the resulting value so long as the references upon which it depends have not changed. This works particularly well for immutable data structures, where we can perform a trivial strict equality comparison (`===`) to determine whether state has changed. Without guaranteed immutability, equality can only be known by deeply traversing the object structure, an operation which in many cases is far more costly than the original computation.
In our above example, we know the value of the function will only change if the set of to-do's has changed. It's in Rememo's second argument that we describe this dependency:
```js
const getTasksByCompletion = createSelector(
(state, isComplete) =>
state.todo.filter((task) => task.complete === isComplete),
(state) => [state.todo]
);
```
Now we can call `getTasksByCompletion` as many times as we want without needlessly wasting time filtering tasks when the `todo` set has not changed.
## Testing
To simplify testing of memoized selectors, the function returned by `createSelector` includes a `clear` function:
```js
const getTasksByCompletion = require('../selector');
// Test licecycle management varies by runner. This example uses Mocha.
beforeEach(() => {
getTasksByCompletion.clear();
});
```
Alternatively, you can create separate references (exports) for your memoized and unmemoized selectors, then test only the unmemoized selector.
Refer to [Rememo's own tests](https://github.com/aduth/rememo/tree/master/test/rememo.js) as an example.
## FAQ
**How does this differ from [Reselect](https://github.com/reactjs/reselect), another selector memoization library?**
Reselect and Rememo largely share the same goals, but have slightly different implementation semantics. Reselect optimizes for function composition, requiring that you pass as arguments functions returning derived data of increasing specificity. Constrasting it to our to-do example above, with Reselect we would pass two arguments: a function which retrieves `todo` from the state object, and a second function which receives that set as an argument and performs the completeness filter. The distinction is not as obvious with a simple example like this one, and can be seen more clearly with examples in [Reselect's README](https://github.com/reactjs/reselect#readme).
Rememo instead encourages you to consider the derivation first-and-foremost without requiring you to build up the individual dependencies ahead of time. This is especially convenient if your computation depends on many disparate state paths, or if you choose not to memoize all selectors and would rather opt-in to caching at your own judgment. Composing selectors is still straight-forward in Rememo if you subscribe to the convention of passing `state` always as the first argument, since this enables your selectors to call upon other each other passing the complete state object.
## License
Copyright 2018-2022 Andrew Duthie
Released under the [MIT License](https://github.com/aduth/rememo/tree/master/LICENSE.md).

301
node_modules/rememo/dist/rememo.js generated vendored Normal file
View File

@@ -0,0 +1,301 @@
var rememo = (function () {
'use strict';
/** @typedef {(...args: any[]) => *[]} GetDependants */
/** @typedef {() => void} Clear */
/**
* @typedef {{
* getDependants: GetDependants,
* clear: Clear
* }} EnhancedSelector
*/
/**
* Internal cache entry.
*
* @typedef CacheNode
*
* @property {?CacheNode|undefined} [prev] Previous node.
* @property {?CacheNode|undefined} [next] Next node.
* @property {*[]} args Function arguments for cache entry.
* @property {*} val Function result.
*/
/**
* @typedef Cache
*
* @property {Clear} clear Function to clear cache.
* @property {boolean} [isUniqueByDependants] Whether dependants are valid in
* considering cache uniqueness. A cache is unique if dependents are all arrays
* or objects.
* @property {CacheNode?} [head] Cache head.
* @property {*[]} [lastDependants] Dependants from previous invocation.
*/
/**
* Arbitrary value used as key for referencing cache object in WeakMap tree.
*
* @type {{}}
*/
var LEAF_KEY = {};
/**
* Returns the first argument as the sole entry in an array.
*
* @template T
*
* @param {T} value Value to return.
*
* @return {[T]} Value returned as entry in array.
*/
function arrayOf(value) {
return [value];
}
/**
* Returns true if the value passed is object-like, or false otherwise. A value
* is object-like if it can support property assignment, e.g. object or array.
*
* @param {*} value Value to test.
*
* @return {boolean} Whether value is object-like.
*/
function isObjectLike(value) {
return !!value && 'object' === typeof value;
}
/**
* Creates and returns a new cache object.
*
* @return {Cache} Cache object.
*/
function createCache() {
/** @type {Cache} */
var cache = {
clear: function () {
cache.head = null;
},
};
return cache;
}
/**
* Returns true if entries within the two arrays are strictly equal by
* reference from a starting index.
*
* @param {*[]} a First array.
* @param {*[]} b Second array.
* @param {number} fromIndex Index from which to start comparison.
*
* @return {boolean} Whether arrays are shallowly equal.
*/
function isShallowEqual(a, b, fromIndex) {
var i;
if (a.length !== b.length) {
return false;
}
for (i = fromIndex; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
}
/**
* Returns a memoized selector function. The getDependants function argument is
* called before the memoized selector and is expected to return an immutable
* reference or array of references on which the selector depends for computing
* its own return value. The memoize cache is preserved only as long as those
* dependant references remain the same. If getDependants returns a different
* reference(s), the cache is cleared and the selector value regenerated.
*
* @template {(...args: *[]) => *} S
*
* @param {S} selector Selector function.
* @param {GetDependants=} getDependants Dependant getter returning an array of
* references used in cache bust consideration.
*/
function rememo (selector, getDependants) {
/** @type {WeakMap<*,*>} */
var rootCache;
/** @type {GetDependants} */
var normalizedGetDependants = getDependants ? getDependants : arrayOf;
/**
* Returns the cache for a given dependants array. When possible, a WeakMap
* will be used to create a unique cache for each set of dependants. This
* is feasible due to the nature of WeakMap in allowing garbage collection
* to occur on entries where the key object is no longer referenced. Since
* WeakMap requires the key to be an object, this is only possible when the
* dependant is object-like. The root cache is created as a hierarchy where
* each top-level key is the first entry in a dependants set, the value a
* WeakMap where each key is the next dependant, and so on. This continues
* so long as the dependants are object-like. If no dependants are object-
* like, then the cache is shared across all invocations.
*
* @see isObjectLike
*
* @param {*[]} dependants Selector dependants.
*
* @return {Cache} Cache object.
*/
function getCache(dependants) {
var caches = rootCache,
isUniqueByDependants = true,
i,
dependant,
map,
cache;
for (i = 0; i < dependants.length; i++) {
dependant = dependants[i];
// Can only compose WeakMap from object-like key.
if (!isObjectLike(dependant)) {
isUniqueByDependants = false;
break;
}
// Does current segment of cache already have a WeakMap?
if (caches.has(dependant)) {
// Traverse into nested WeakMap.
caches = caches.get(dependant);
} else {
// Create, set, and traverse into a new one.
map = new WeakMap();
caches.set(dependant, map);
caches = map;
}
}
// We use an arbitrary (but consistent) object as key for the last item
// in the WeakMap to serve as our running cache.
if (!caches.has(LEAF_KEY)) {
cache = createCache();
cache.isUniqueByDependants = isUniqueByDependants;
caches.set(LEAF_KEY, cache);
}
return caches.get(LEAF_KEY);
}
/**
* Resets root memoization cache.
*/
function clear() {
rootCache = new WeakMap();
}
/* eslint-disable jsdoc/check-param-names */
/**
* The augmented selector call, considering first whether dependants have
* changed before passing it to underlying memoize function.
*
* @param {*} source Source object for derivation.
* @param {...*} extraArgs Additional arguments to pass to selector.
*
* @return {*} Selector result.
*/
/* eslint-enable jsdoc/check-param-names */
function callSelector(/* source, ...extraArgs */) {
var len = arguments.length,
cache,
node,
i,
args,
dependants;
// Create copy of arguments (avoid leaking deoptimization).
args = new Array(len);
for (i = 0; i < len; i++) {
args[i] = arguments[i];
}
dependants = normalizedGetDependants.apply(null, args);
cache = getCache(dependants);
// If not guaranteed uniqueness by dependants (primitive type), shallow
// compare against last dependants and, if references have changed,
// destroy cache to recalculate result.
if (!cache.isUniqueByDependants) {
if (
cache.lastDependants &&
!isShallowEqual(dependants, cache.lastDependants, 0)
) {
cache.clear();
}
cache.lastDependants = dependants;
}
node = cache.head;
while (node) {
// Check whether node arguments match arguments
if (!isShallowEqual(node.args, args, 1)) {
node = node.next;
continue;
}
// At this point we can assume we've found a match
// Surface matched node to head if not already
if (node !== cache.head) {
// Adjust siblings to point to each other.
/** @type {CacheNode} */ (node.prev).next = node.next;
if (node.next) {
node.next.prev = node.prev;
}
node.next = cache.head;
node.prev = null;
/** @type {CacheNode} */ (cache.head).prev = node;
cache.head = node;
}
// Return immediately
return node.val;
}
// No cached value found. Continue to insertion phase:
node = /** @type {CacheNode} */ ({
// Generate the result from original function
val: selector.apply(null, args),
});
// Avoid including the source object in the cache.
args[0] = null;
node.args = args;
// Don't need to check whether node is already head, since it would
// have been returned above already if it was
// Shift existing head down list
if (cache.head) {
cache.head.prev = node;
node.next = cache.head;
}
cache.head = node;
return node.val;
}
callSelector.getDependants = normalizedGetDependants;
callSelector.clear = clear;
clear();
return /** @type {S & EnhancedSelector} */ (callSelector);
}
return rememo;
}());

1
node_modules/rememo/dist/rememo.min.js generated vendored Normal file
View File

@@ -0,0 +1 @@
var rememo=function(){"use strict";var e={};function n(e){return[e]}function t(e,n,t){var r;if(e.length!==n.length)return!1;for(r=t;r<e.length;r++)if(e[r]!==n[r])return!1;return!0}return function(r,a){var u,l=a||n;function p(n){var t,r,a,l,p,s=u,f=!0;for(t=0;t<n.length;t++){if(r=n[t],!(p=r)||"object"!=typeof p){f=!1;break}s.has(r)?s=s.get(r):(a=new WeakMap,s.set(r,a),s=a)}return s.has(e)||((l=function(){var e={clear:function(){e.head=null}};return e}()).isUniqueByDependants=f,s.set(e,l)),s.get(e)}function s(){u=new WeakMap}function f(){var e,n,a,u,s,f=arguments.length;for(u=new Array(f),a=0;a<f;a++)u[a]=arguments[a];for((e=p(s=l.apply(null,u))).isUniqueByDependants||(e.lastDependants&&!t(s,e.lastDependants,0)&&e.clear(),e.lastDependants=s),n=e.head;n;){if(t(n.args,u,1))return n!==e.head&&(n.prev.next=n.next,n.next&&(n.next.prev=n.prev),n.next=e.head,n.prev=null,e.head.prev=n,e.head=n),n.val;n=n.next}return n={val:r.apply(null,u)},u[0]=null,n.args=u,e.head&&(e.head.prev=n,n.next=e.head),e.head=n,n.val}return f.getDependants=l,f.clear=s,s(),f}}();

65
node_modules/rememo/package.json generated vendored Normal file
View File

@@ -0,0 +1,65 @@
{
"name": "rememo",
"type": "module",
"version": "4.0.2",
"description": "Memoized selectors for Redux and other immutable object derivation",
"main": "rememo.cjs",
"module": "rememo.js",
"types": "rememo.d.ts",
"exports": {
".": {
"import": "./rememo.js",
"require": "./rememo.cjs"
}
},
"files": [
"rememo.cjs",
"rememo.js",
"rememo.d.ts",
"dist"
],
"scripts": {
"test:lint": "eslint . --ignore-pattern dist",
"test:typecheck": "tsc",
"test:unit": "mocha",
"test": "npm-run-all --parallel test:*",
"build:bundle": "rollup -c",
"build:types": "tsc -p tsconfig.decl.json",
"build": "npm-run-all --parallel build:*",
"prepublishOnly": "npm run build"
},
"repository": {
"type": "git",
"url": "https://github.com/aduth/rememo.git"
},
"bugs": {
"url": "https://github.com/aduth/rememo/issues"
},
"author": {
"name": "Andrew Duthie",
"email": "andrew@andrewduthie.com",
"url": "http://andrewduthie.com"
},
"keywords": [
"redux",
"selector",
"selectors",
"memoize",
"memoization",
"cache"
],
"license": "MIT",
"devDependencies": {
"@aduth/eslint-config": "^4.4.1",
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jsdoc": "^39.3.6",
"eslint-plugin-prettier": "^4.2.1",
"mocha": "^10.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"rollup-plugin-terser": "^7.0.2",
"sinon": "^14.0.1",
"typescript": "^4.8.4"
}
}

298
node_modules/rememo/rememo.cjs generated vendored Normal file
View File

@@ -0,0 +1,298 @@
'use strict';
/** @typedef {(...args: any[]) => *[]} GetDependants */
/** @typedef {() => void} Clear */
/**
* @typedef {{
* getDependants: GetDependants,
* clear: Clear
* }} EnhancedSelector
*/
/**
* Internal cache entry.
*
* @typedef CacheNode
*
* @property {?CacheNode|undefined} [prev] Previous node.
* @property {?CacheNode|undefined} [next] Next node.
* @property {*[]} args Function arguments for cache entry.
* @property {*} val Function result.
*/
/**
* @typedef Cache
*
* @property {Clear} clear Function to clear cache.
* @property {boolean} [isUniqueByDependants] Whether dependants are valid in
* considering cache uniqueness. A cache is unique if dependents are all arrays
* or objects.
* @property {CacheNode?} [head] Cache head.
* @property {*[]} [lastDependants] Dependants from previous invocation.
*/
/**
* Arbitrary value used as key for referencing cache object in WeakMap tree.
*
* @type {{}}
*/
var LEAF_KEY = {};
/**
* Returns the first argument as the sole entry in an array.
*
* @template T
*
* @param {T} value Value to return.
*
* @return {[T]} Value returned as entry in array.
*/
function arrayOf(value) {
return [value];
}
/**
* Returns true if the value passed is object-like, or false otherwise. A value
* is object-like if it can support property assignment, e.g. object or array.
*
* @param {*} value Value to test.
*
* @return {boolean} Whether value is object-like.
*/
function isObjectLike(value) {
return !!value && 'object' === typeof value;
}
/**
* Creates and returns a new cache object.
*
* @return {Cache} Cache object.
*/
function createCache() {
/** @type {Cache} */
var cache = {
clear: function () {
cache.head = null;
},
};
return cache;
}
/**
* Returns true if entries within the two arrays are strictly equal by
* reference from a starting index.
*
* @param {*[]} a First array.
* @param {*[]} b Second array.
* @param {number} fromIndex Index from which to start comparison.
*
* @return {boolean} Whether arrays are shallowly equal.
*/
function isShallowEqual(a, b, fromIndex) {
var i;
if (a.length !== b.length) {
return false;
}
for (i = fromIndex; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
}
/**
* Returns a memoized selector function. The getDependants function argument is
* called before the memoized selector and is expected to return an immutable
* reference or array of references on which the selector depends for computing
* its own return value. The memoize cache is preserved only as long as those
* dependant references remain the same. If getDependants returns a different
* reference(s), the cache is cleared and the selector value regenerated.
*
* @template {(...args: *[]) => *} S
*
* @param {S} selector Selector function.
* @param {GetDependants=} getDependants Dependant getter returning an array of
* references used in cache bust consideration.
*/
function rememo (selector, getDependants) {
/** @type {WeakMap<*,*>} */
var rootCache;
/** @type {GetDependants} */
var normalizedGetDependants = getDependants ? getDependants : arrayOf;
/**
* Returns the cache for a given dependants array. When possible, a WeakMap
* will be used to create a unique cache for each set of dependants. This
* is feasible due to the nature of WeakMap in allowing garbage collection
* to occur on entries where the key object is no longer referenced. Since
* WeakMap requires the key to be an object, this is only possible when the
* dependant is object-like. The root cache is created as a hierarchy where
* each top-level key is the first entry in a dependants set, the value a
* WeakMap where each key is the next dependant, and so on. This continues
* so long as the dependants are object-like. If no dependants are object-
* like, then the cache is shared across all invocations.
*
* @see isObjectLike
*
* @param {*[]} dependants Selector dependants.
*
* @return {Cache} Cache object.
*/
function getCache(dependants) {
var caches = rootCache,
isUniqueByDependants = true,
i,
dependant,
map,
cache;
for (i = 0; i < dependants.length; i++) {
dependant = dependants[i];
// Can only compose WeakMap from object-like key.
if (!isObjectLike(dependant)) {
isUniqueByDependants = false;
break;
}
// Does current segment of cache already have a WeakMap?
if (caches.has(dependant)) {
// Traverse into nested WeakMap.
caches = caches.get(dependant);
} else {
// Create, set, and traverse into a new one.
map = new WeakMap();
caches.set(dependant, map);
caches = map;
}
}
// We use an arbitrary (but consistent) object as key for the last item
// in the WeakMap to serve as our running cache.
if (!caches.has(LEAF_KEY)) {
cache = createCache();
cache.isUniqueByDependants = isUniqueByDependants;
caches.set(LEAF_KEY, cache);
}
return caches.get(LEAF_KEY);
}
/**
* Resets root memoization cache.
*/
function clear() {
rootCache = new WeakMap();
}
/* eslint-disable jsdoc/check-param-names */
/**
* The augmented selector call, considering first whether dependants have
* changed before passing it to underlying memoize function.
*
* @param {*} source Source object for derivation.
* @param {...*} extraArgs Additional arguments to pass to selector.
*
* @return {*} Selector result.
*/
/* eslint-enable jsdoc/check-param-names */
function callSelector(/* source, ...extraArgs */) {
var len = arguments.length,
cache,
node,
i,
args,
dependants;
// Create copy of arguments (avoid leaking deoptimization).
args = new Array(len);
for (i = 0; i < len; i++) {
args[i] = arguments[i];
}
dependants = normalizedGetDependants.apply(null, args);
cache = getCache(dependants);
// If not guaranteed uniqueness by dependants (primitive type), shallow
// compare against last dependants and, if references have changed,
// destroy cache to recalculate result.
if (!cache.isUniqueByDependants) {
if (
cache.lastDependants &&
!isShallowEqual(dependants, cache.lastDependants, 0)
) {
cache.clear();
}
cache.lastDependants = dependants;
}
node = cache.head;
while (node) {
// Check whether node arguments match arguments
if (!isShallowEqual(node.args, args, 1)) {
node = node.next;
continue;
}
// At this point we can assume we've found a match
// Surface matched node to head if not already
if (node !== cache.head) {
// Adjust siblings to point to each other.
/** @type {CacheNode} */ (node.prev).next = node.next;
if (node.next) {
node.next.prev = node.prev;
}
node.next = cache.head;
node.prev = null;
/** @type {CacheNode} */ (cache.head).prev = node;
cache.head = node;
}
// Return immediately
return node.val;
}
// No cached value found. Continue to insertion phase:
node = /** @type {CacheNode} */ ({
// Generate the result from original function
val: selector.apply(null, args),
});
// Avoid including the source object in the cache.
args[0] = null;
node.args = args;
// Don't need to check whether node is already head, since it would
// have been returned above already if it was
// Shift existing head down list
if (cache.head) {
cache.head.prev = node;
node.next = cache.head;
}
cache.head = node;
return node.val;
}
callSelector.getDependants = normalizedGetDependants;
callSelector.clear = clear;
clear();
return /** @type {S & EnhancedSelector} */ (callSelector);
}
module.exports = rememo;

64
node_modules/rememo/rememo.d.ts generated vendored Normal file
View File

@@ -0,0 +1,64 @@
declare module "rememo" {
/**
* Returns a memoized selector function. The getDependants function argument is
* called before the memoized selector and is expected to return an immutable
* reference or array of references on which the selector depends for computing
* its own return value. The memoize cache is preserved only as long as those
* dependant references remain the same. If getDependants returns a different
* reference(s), the cache is cleared and the selector value regenerated.
*
* @template {(...args: *[]) => *} S
*
* @param {S} selector Selector function.
* @param {GetDependants=} getDependants Dependant getter returning an array of
* references used in cache bust consideration.
*/
export default function _default<S extends (...args: any[]) => any>(selector: S, getDependants?: GetDependants | undefined): S & EnhancedSelector;
export type GetDependants = (...args: any[]) => any[];
export type Clear = () => void;
export type EnhancedSelector = {
getDependants: GetDependants;
clear: Clear;
};
/**
* Internal cache entry.
*/
export type CacheNode = {
/**
* Previous node.
*/
prev?: (CacheNode | undefined) | null;
/**
* Next node.
*/
next?: (CacheNode | undefined) | null;
/**
* Function arguments for cache entry.
*/
args: any[];
/**
* Function result.
*/
val: any;
};
export type Cache = {
/**
* Function to clear cache.
*/
clear: Clear;
/**
* Whether dependants are valid in
* considering cache uniqueness. A cache is unique if dependents are all arrays
* or objects.
*/
isUniqueByDependants?: boolean | undefined;
/**
* Cache head.
*/
head?: CacheNode | null | undefined;
/**
* Dependants from previous invocation.
*/
lastDependants?: any[] | undefined;
};
}

296
node_modules/rememo/rememo.js generated vendored Normal file
View File

@@ -0,0 +1,296 @@
'use strict';
/** @typedef {(...args: any[]) => *[]} GetDependants */
/** @typedef {() => void} Clear */
/**
* @typedef {{
* getDependants: GetDependants,
* clear: Clear
* }} EnhancedSelector
*/
/**
* Internal cache entry.
*
* @typedef CacheNode
*
* @property {?CacheNode|undefined} [prev] Previous node.
* @property {?CacheNode|undefined} [next] Next node.
* @property {*[]} args Function arguments for cache entry.
* @property {*} val Function result.
*/
/**
* @typedef Cache
*
* @property {Clear} clear Function to clear cache.
* @property {boolean} [isUniqueByDependants] Whether dependants are valid in
* considering cache uniqueness. A cache is unique if dependents are all arrays
* or objects.
* @property {CacheNode?} [head] Cache head.
* @property {*[]} [lastDependants] Dependants from previous invocation.
*/
/**
* Arbitrary value used as key for referencing cache object in WeakMap tree.
*
* @type {{}}
*/
var LEAF_KEY = {};
/**
* Returns the first argument as the sole entry in an array.
*
* @template T
*
* @param {T} value Value to return.
*
* @return {[T]} Value returned as entry in array.
*/
function arrayOf(value) {
return [value];
}
/**
* Returns true if the value passed is object-like, or false otherwise. A value
* is object-like if it can support property assignment, e.g. object or array.
*
* @param {*} value Value to test.
*
* @return {boolean} Whether value is object-like.
*/
function isObjectLike(value) {
return !!value && 'object' === typeof value;
}
/**
* Creates and returns a new cache object.
*
* @return {Cache} Cache object.
*/
function createCache() {
/** @type {Cache} */
var cache = {
clear: function () {
cache.head = null;
},
};
return cache;
}
/**
* Returns true if entries within the two arrays are strictly equal by
* reference from a starting index.
*
* @param {*[]} a First array.
* @param {*[]} b Second array.
* @param {number} fromIndex Index from which to start comparison.
*
* @return {boolean} Whether arrays are shallowly equal.
*/
function isShallowEqual(a, b, fromIndex) {
var i;
if (a.length !== b.length) {
return false;
}
for (i = fromIndex; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
}
/**
* Returns a memoized selector function. The getDependants function argument is
* called before the memoized selector and is expected to return an immutable
* reference or array of references on which the selector depends for computing
* its own return value. The memoize cache is preserved only as long as those
* dependant references remain the same. If getDependants returns a different
* reference(s), the cache is cleared and the selector value regenerated.
*
* @template {(...args: *[]) => *} S
*
* @param {S} selector Selector function.
* @param {GetDependants=} getDependants Dependant getter returning an array of
* references used in cache bust consideration.
*/
export default function (selector, getDependants) {
/** @type {WeakMap<*,*>} */
var rootCache;
/** @type {GetDependants} */
var normalizedGetDependants = getDependants ? getDependants : arrayOf;
/**
* Returns the cache for a given dependants array. When possible, a WeakMap
* will be used to create a unique cache for each set of dependants. This
* is feasible due to the nature of WeakMap in allowing garbage collection
* to occur on entries where the key object is no longer referenced. Since
* WeakMap requires the key to be an object, this is only possible when the
* dependant is object-like. The root cache is created as a hierarchy where
* each top-level key is the first entry in a dependants set, the value a
* WeakMap where each key is the next dependant, and so on. This continues
* so long as the dependants are object-like. If no dependants are object-
* like, then the cache is shared across all invocations.
*
* @see isObjectLike
*
* @param {*[]} dependants Selector dependants.
*
* @return {Cache} Cache object.
*/
function getCache(dependants) {
var caches = rootCache,
isUniqueByDependants = true,
i,
dependant,
map,
cache;
for (i = 0; i < dependants.length; i++) {
dependant = dependants[i];
// Can only compose WeakMap from object-like key.
if (!isObjectLike(dependant)) {
isUniqueByDependants = false;
break;
}
// Does current segment of cache already have a WeakMap?
if (caches.has(dependant)) {
// Traverse into nested WeakMap.
caches = caches.get(dependant);
} else {
// Create, set, and traverse into a new one.
map = new WeakMap();
caches.set(dependant, map);
caches = map;
}
}
// We use an arbitrary (but consistent) object as key for the last item
// in the WeakMap to serve as our running cache.
if (!caches.has(LEAF_KEY)) {
cache = createCache();
cache.isUniqueByDependants = isUniqueByDependants;
caches.set(LEAF_KEY, cache);
}
return caches.get(LEAF_KEY);
}
/**
* Resets root memoization cache.
*/
function clear() {
rootCache = new WeakMap();
}
/* eslint-disable jsdoc/check-param-names */
/**
* The augmented selector call, considering first whether dependants have
* changed before passing it to underlying memoize function.
*
* @param {*} source Source object for derivation.
* @param {...*} extraArgs Additional arguments to pass to selector.
*
* @return {*} Selector result.
*/
/* eslint-enable jsdoc/check-param-names */
function callSelector(/* source, ...extraArgs */) {
var len = arguments.length,
cache,
node,
i,
args,
dependants;
// Create copy of arguments (avoid leaking deoptimization).
args = new Array(len);
for (i = 0; i < len; i++) {
args[i] = arguments[i];
}
dependants = normalizedGetDependants.apply(null, args);
cache = getCache(dependants);
// If not guaranteed uniqueness by dependants (primitive type), shallow
// compare against last dependants and, if references have changed,
// destroy cache to recalculate result.
if (!cache.isUniqueByDependants) {
if (
cache.lastDependants &&
!isShallowEqual(dependants, cache.lastDependants, 0)
) {
cache.clear();
}
cache.lastDependants = dependants;
}
node = cache.head;
while (node) {
// Check whether node arguments match arguments
if (!isShallowEqual(node.args, args, 1)) {
node = node.next;
continue;
}
// At this point we can assume we've found a match
// Surface matched node to head if not already
if (node !== cache.head) {
// Adjust siblings to point to each other.
/** @type {CacheNode} */ (node.prev).next = node.next;
if (node.next) {
node.next.prev = node.prev;
}
node.next = cache.head;
node.prev = null;
/** @type {CacheNode} */ (cache.head).prev = node;
cache.head = node;
}
// Return immediately
return node.val;
}
// No cached value found. Continue to insertion phase:
node = /** @type {CacheNode} */ ({
// Generate the result from original function
val: selector.apply(null, args),
});
// Avoid including the source object in the cache.
args[0] = null;
node.args = args;
// Don't need to check whether node is already head, since it would
// have been returned above already if it was
// Shift existing head down list
if (cache.head) {
cache.head.prev = node;
node.next = cache.head;
}
cache.head = node;
return node.val;
}
callSelector.getDependants = normalizedGetDependants;
callSelector.clear = clear;
clear();
return /** @type {S & EnhancedSelector} */ (callSelector);
}