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>
49 lines
1.9 KiB
JavaScript
49 lines
1.9 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */
|
|
|
|
/**
|
|
* Creates a middleware handling resolvers cache invalidation.
|
|
*
|
|
* @param {WPDataRegistry} registry Registry for which to create the middleware.
|
|
* @param {string} storeName Name of the store for which to create the middleware.
|
|
*
|
|
* @return {Function} Middleware function.
|
|
*/
|
|
const createResolversCacheMiddleware = (registry, storeName) => () => next => action => {
|
|
const resolvers = registry.select(storeName).getCachedResolvers();
|
|
const resolverEntries = Object.entries(resolvers);
|
|
resolverEntries.forEach(([selectorName, resolversByArgs]) => {
|
|
const resolver = registry.stores[storeName]?.resolvers?.[selectorName];
|
|
if (!resolver || !resolver.shouldInvalidate) {
|
|
return;
|
|
}
|
|
resolversByArgs.forEach((value, args) => {
|
|
// Works around a bug in `EquivalentKeyMap` where `map.delete` merely sets an entry value
|
|
// to `undefined` and `map.forEach` then iterates also over these orphaned entries.
|
|
if (value === undefined) {
|
|
return;
|
|
}
|
|
|
|
// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.
|
|
// If the value is "finished" or "error" it means this resolver has finished its resolution which means we need
|
|
// to invalidate it, if it's true it means it's inflight and the invalidation is not necessary.
|
|
if (value.status !== 'finished' && value.status !== 'error') {
|
|
return;
|
|
}
|
|
if (!resolver.shouldInvalidate(action, ...args)) {
|
|
return;
|
|
}
|
|
|
|
// Trigger cache invalidation
|
|
registry.dispatch(storeName).invalidateResolution(selectorName, args);
|
|
});
|
|
});
|
|
return next(action);
|
|
};
|
|
var _default = exports.default = createResolversCacheMiddleware;
|
|
//# sourceMappingURL=resolvers-cache-middleware.js.map
|