author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1 |
/******/ (() => { // webpackBootstrap |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2 |
/******/ "use strict"; |
19 | 3 |
/******/ var __webpack_modules__ = ({ |
4 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
5 |
/***/ 66: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
6 |
/***/ ((module) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
7 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
9 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
10 |
var isMergeableObject = function isMergeableObject(value) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
11 |
return isNonNullObject(value) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
12 |
&& !isSpecial(value) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
13 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
14 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
15 |
function isNonNullObject(value) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
16 |
return !!value && typeof value === 'object' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
17 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
18 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
19 |
function isSpecial(value) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
20 |
var stringValue = Object.prototype.toString.call(value); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
21 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
22 |
return stringValue === '[object RegExp]' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
23 |
|| stringValue === '[object Date]' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
24 |
|| isReactElement(value) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
25 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
26 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
27 |
// see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
28 |
var canUseSymbol = typeof Symbol === 'function' && Symbol.for; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
29 |
var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
30 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
31 |
function isReactElement(value) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
32 |
return value.$$typeof === REACT_ELEMENT_TYPE |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
34 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
35 |
function emptyTarget(val) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
36 |
return Array.isArray(val) ? [] : {} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
37 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
38 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
39 |
function cloneUnlessOtherwiseSpecified(value, options) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
40 |
return (options.clone !== false && options.isMergeableObject(value)) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
41 |
? deepmerge(emptyTarget(value), value, options) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
42 |
: value |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
43 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
44 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
45 |
function defaultArrayMerge(target, source, options) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
46 |
return target.concat(source).map(function(element) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
47 |
return cloneUnlessOtherwiseSpecified(element, options) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
48 |
}) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
49 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
50 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
51 |
function getMergeFunction(key, options) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
52 |
if (!options.customMerge) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
53 |
return deepmerge |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
54 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
55 |
var customMerge = options.customMerge(key); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
56 |
return typeof customMerge === 'function' ? customMerge : deepmerge |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
57 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
58 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
59 |
function getEnumerableOwnPropertySymbols(target) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
60 |
return Object.getOwnPropertySymbols |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
61 |
? Object.getOwnPropertySymbols(target).filter(function(symbol) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
62 |
return Object.propertyIsEnumerable.call(target, symbol) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
63 |
}) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
64 |
: [] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
65 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
66 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
67 |
function getKeys(target) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
68 |
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
69 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
70 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
71 |
function propertyIsOnObject(object, property) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
72 |
try { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
73 |
return property in object |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
74 |
} catch(_) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
75 |
return false |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
76 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
77 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
78 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
79 |
// Protects from prototype poisoning and unexpected merging up the prototype chain. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
80 |
function propertyIsUnsafe(target, key) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
81 |
return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
82 |
&& !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
83 |
&& Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
84 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
85 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
86 |
function mergeObject(target, source, options) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
87 |
var destination = {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
88 |
if (options.isMergeableObject(target)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
89 |
getKeys(target).forEach(function(key) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
90 |
destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
91 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
92 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
93 |
getKeys(source).forEach(function(key) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
94 |
if (propertyIsUnsafe(target, key)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
95 |
return |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
96 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
97 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
98 |
if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
99 |
destination[key] = getMergeFunction(key, options)(target[key], source[key], options); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
100 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
101 |
destination[key] = cloneUnlessOtherwiseSpecified(source[key], options); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
102 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
103 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
104 |
return destination |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
105 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
106 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
107 |
function deepmerge(target, source, options) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
108 |
options = options || {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
109 |
options.arrayMerge = options.arrayMerge || defaultArrayMerge; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
110 |
options.isMergeableObject = options.isMergeableObject || isMergeableObject; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
111 |
// cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge() |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
112 |
// implementations can use it. The caller may not replace it. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
113 |
options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
114 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
115 |
var sourceIsArray = Array.isArray(source); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
116 |
var targetIsArray = Array.isArray(target); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
117 |
var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
118 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
119 |
if (!sourceAndTargetTypesMatch) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
120 |
return cloneUnlessOtherwiseSpecified(source, options) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
121 |
} else if (sourceIsArray) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
122 |
return options.arrayMerge(target, source, options) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
123 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
124 |
return mergeObject(target, source, options) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
125 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
126 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
127 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
128 |
deepmerge.all = function deepmergeAll(array, options) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
129 |
if (!Array.isArray(array)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
130 |
throw new Error('first argument should be an array') |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
131 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
132 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
133 |
return array.reduce(function(prev, next) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
134 |
return deepmerge(prev, next, options) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
135 |
}, {}) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
136 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
137 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
138 |
var deepmerge_1 = deepmerge; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
139 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
140 |
module.exports = deepmerge_1; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
141 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
142 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
143 |
/***/ }), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
144 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
145 |
/***/ 3249: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
146 |
/***/ ((module) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
147 |
|
9 | 148 |
|
149 |
||
150 |
function _typeof(obj) { |
|
151 |
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { |
|
152 |
_typeof = function (obj) { |
|
153 |
return typeof obj; |
|
154 |
}; |
|
155 |
} else { |
|
156 |
_typeof = function (obj) { |
|
157 |
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; |
|
158 |
}; |
|
159 |
} |
|
160 |
||
161 |
return _typeof(obj); |
|
162 |
} |
|
163 |
||
164 |
function _classCallCheck(instance, Constructor) { |
|
165 |
if (!(instance instanceof Constructor)) { |
|
166 |
throw new TypeError("Cannot call a class as a function"); |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
function _defineProperties(target, props) { |
|
171 |
for (var i = 0; i < props.length; i++) { |
|
172 |
var descriptor = props[i]; |
|
173 |
descriptor.enumerable = descriptor.enumerable || false; |
|
174 |
descriptor.configurable = true; |
|
175 |
if ("value" in descriptor) descriptor.writable = true; |
|
176 |
Object.defineProperty(target, descriptor.key, descriptor); |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
function _createClass(Constructor, protoProps, staticProps) { |
|
181 |
if (protoProps) _defineProperties(Constructor.prototype, protoProps); |
|
182 |
if (staticProps) _defineProperties(Constructor, staticProps); |
|
183 |
return Constructor; |
|
184 |
} |
|
185 |
||
186 |
/** |
|
187 |
* Given an instance of EquivalentKeyMap, returns its internal value pair tuple |
|
188 |
* for a key, if one exists. The tuple members consist of the last reference |
|
189 |
* value for the key (used in efficient subsequent lookups) and the value |
|
190 |
* assigned for the key at the leaf node. |
|
191 |
* |
|
192 |
* @param {EquivalentKeyMap} instance EquivalentKeyMap instance. |
|
193 |
* @param {*} key The key for which to return value pair. |
|
194 |
* |
|
195 |
* @return {?Array} Value pair, if exists. |
|
196 |
*/ |
|
197 |
function getValuePair(instance, key) { |
|
198 |
var _map = instance._map, |
|
199 |
_arrayTreeMap = instance._arrayTreeMap, |
|
200 |
_objectTreeMap = instance._objectTreeMap; // Map keeps a reference to the last object-like key used to set the |
|
201 |
// value, which can be used to shortcut immediately to the value. |
|
202 |
||
203 |
if (_map.has(key)) { |
|
204 |
return _map.get(key); |
|
205 |
} // Sort keys to ensure stable retrieval from tree. |
|
206 |
||
207 |
||
208 |
var properties = Object.keys(key).sort(); // Tree by type to avoid conflicts on numeric object keys, empty value. |
|
209 |
||
210 |
var map = Array.isArray(key) ? _arrayTreeMap : _objectTreeMap; |
|
211 |
||
212 |
for (var i = 0; i < properties.length; i++) { |
|
213 |
var property = properties[i]; |
|
214 |
map = map.get(property); |
|
215 |
||
216 |
if (map === undefined) { |
|
217 |
return; |
|
218 |
} |
|
219 |
||
220 |
var propertyValue = key[property]; |
|
221 |
map = map.get(propertyValue); |
|
222 |
||
223 |
if (map === undefined) { |
|
224 |
return; |
|
225 |
} |
|
226 |
} |
|
227 |
||
228 |
var valuePair = map.get('_ekm_value'); |
|
229 |
||
230 |
if (!valuePair) { |
|
231 |
return; |
|
232 |
} // If reached, it implies that an object-like key was set with another |
|
233 |
// reference, so delete the reference and replace with the current. |
|
234 |
||
235 |
||
236 |
_map.delete(valuePair[0]); |
|
237 |
||
238 |
valuePair[0] = key; |
|
239 |
map.set('_ekm_value', valuePair); |
|
240 |
||
241 |
_map.set(key, valuePair); |
|
242 |
||
243 |
return valuePair; |
|
244 |
} |
|
245 |
/** |
|
246 |
* Variant of a Map object which enables lookup by equivalent (deeply equal) |
|
247 |
* object and array keys. |
|
248 |
*/ |
|
249 |
||
250 |
||
251 |
var EquivalentKeyMap = |
|
252 |
/*#__PURE__*/ |
|
253 |
function () { |
|
254 |
/** |
|
255 |
* Constructs a new instance of EquivalentKeyMap. |
|
256 |
* |
|
257 |
* @param {Iterable.<*>} iterable Initial pair of key, value for map. |
|
258 |
*/ |
|
259 |
function EquivalentKeyMap(iterable) { |
|
260 |
_classCallCheck(this, EquivalentKeyMap); |
|
261 |
||
262 |
this.clear(); |
|
263 |
||
264 |
if (iterable instanceof EquivalentKeyMap) { |
|
265 |
// Map#forEach is only means of iterating with support for IE11. |
|
266 |
var iterablePairs = []; |
|
267 |
iterable.forEach(function (value, key) { |
|
268 |
iterablePairs.push([key, value]); |
|
269 |
}); |
|
270 |
iterable = iterablePairs; |
|
271 |
} |
|
272 |
||
273 |
if (iterable != null) { |
|
274 |
for (var i = 0; i < iterable.length; i++) { |
|
275 |
this.set(iterable[i][0], iterable[i][1]); |
|
276 |
} |
|
277 |
} |
|
278 |
} |
|
279 |
/** |
|
280 |
* Accessor property returning the number of elements. |
|
281 |
* |
|
282 |
* @return {number} Number of elements. |
|
283 |
*/ |
|
284 |
||
285 |
||
286 |
_createClass(EquivalentKeyMap, [{ |
|
287 |
key: "set", |
|
288 |
||
289 |
/** |
|
290 |
* Add or update an element with a specified key and value. |
|
291 |
* |
|
292 |
* @param {*} key The key of the element to add. |
|
293 |
* @param {*} value The value of the element to add. |
|
294 |
* |
|
295 |
* @return {EquivalentKeyMap} Map instance. |
|
296 |
*/ |
|
297 |
value: function set(key, value) { |
|
298 |
// Shortcut non-object-like to set on internal Map. |
|
299 |
if (key === null || _typeof(key) !== 'object') { |
|
300 |
this._map.set(key, value); |
|
301 |
||
302 |
return this; |
|
303 |
} // Sort keys to ensure stable assignment into tree. |
|
304 |
||
305 |
||
306 |
var properties = Object.keys(key).sort(); |
|
307 |
var valuePair = [key, value]; // Tree by type to avoid conflicts on numeric object keys, empty value. |
|
308 |
||
309 |
var map = Array.isArray(key) ? this._arrayTreeMap : this._objectTreeMap; |
|
310 |
||
311 |
for (var i = 0; i < properties.length; i++) { |
|
312 |
var property = properties[i]; |
|
313 |
||
314 |
if (!map.has(property)) { |
|
315 |
map.set(property, new EquivalentKeyMap()); |
|
316 |
} |
|
317 |
||
318 |
map = map.get(property); |
|
319 |
var propertyValue = key[property]; |
|
320 |
||
321 |
if (!map.has(propertyValue)) { |
|
322 |
map.set(propertyValue, new EquivalentKeyMap()); |
|
323 |
} |
|
324 |
||
325 |
map = map.get(propertyValue); |
|
326 |
} // If an _ekm_value exists, there was already an equivalent key. Before |
|
327 |
// overriding, ensure that the old key reference is removed from map to |
|
328 |
// avoid memory leak of accumulating equivalent keys. This is, in a |
|
329 |
// sense, a poor man's WeakMap, while still enabling iterability. |
|
330 |
||
331 |
||
332 |
var previousValuePair = map.get('_ekm_value'); |
|
333 |
||
334 |
if (previousValuePair) { |
|
335 |
this._map.delete(previousValuePair[0]); |
|
336 |
} |
|
337 |
||
338 |
map.set('_ekm_value', valuePair); |
|
339 |
||
340 |
this._map.set(key, valuePair); |
|
341 |
||
342 |
return this; |
|
343 |
} |
|
344 |
/** |
|
345 |
* Returns a specified element. |
|
346 |
* |
|
347 |
* @param {*} key The key of the element to return. |
|
348 |
* |
|
349 |
* @return {?*} The element associated with the specified key or undefined |
|
350 |
* if the key can't be found. |
|
351 |
*/ |
|
352 |
||
353 |
}, { |
|
354 |
key: "get", |
|
355 |
value: function get(key) { |
|
356 |
// Shortcut non-object-like to get from internal Map. |
|
357 |
if (key === null || _typeof(key) !== 'object') { |
|
358 |
return this._map.get(key); |
|
359 |
} |
|
360 |
||
361 |
var valuePair = getValuePair(this, key); |
|
362 |
||
363 |
if (valuePair) { |
|
364 |
return valuePair[1]; |
|
365 |
} |
|
366 |
} |
|
367 |
/** |
|
368 |
* Returns a boolean indicating whether an element with the specified key |
|
369 |
* exists or not. |
|
370 |
* |
|
371 |
* @param {*} key The key of the element to test for presence. |
|
372 |
* |
|
373 |
* @return {boolean} Whether an element with the specified key exists. |
|
374 |
*/ |
|
375 |
||
376 |
}, { |
|
377 |
key: "has", |
|
378 |
value: function has(key) { |
|
379 |
if (key === null || _typeof(key) !== 'object') { |
|
380 |
return this._map.has(key); |
|
381 |
} // Test on the _presence_ of the pair, not its value, as even undefined |
|
382 |
// can be a valid member value for a key. |
|
383 |
||
384 |
||
385 |
return getValuePair(this, key) !== undefined; |
|
386 |
} |
|
387 |
/** |
|
388 |
* Removes the specified element. |
|
389 |
* |
|
390 |
* @param {*} key The key of the element to remove. |
|
391 |
* |
|
392 |
* @return {boolean} Returns true if an element existed and has been |
|
393 |
* removed, or false if the element does not exist. |
|
394 |
*/ |
|
395 |
||
396 |
}, { |
|
397 |
key: "delete", |
|
398 |
value: function _delete(key) { |
|
399 |
if (!this.has(key)) { |
|
400 |
return false; |
|
401 |
} // This naive implementation will leave orphaned child trees. A better |
|
402 |
// implementation should traverse and remove orphans. |
|
403 |
||
404 |
||
405 |
this.set(key, undefined); |
|
406 |
return true; |
|
407 |
} |
|
408 |
/** |
|
409 |
* Executes a provided function once per each key/value pair, in insertion |
|
410 |
* order. |
|
411 |
* |
|
412 |
* @param {Function} callback Function to execute for each element. |
|
413 |
* @param {*} thisArg Value to use as `this` when executing |
|
414 |
* `callback`. |
|
415 |
*/ |
|
416 |
||
417 |
}, { |
|
418 |
key: "forEach", |
|
419 |
value: function forEach(callback) { |
|
420 |
var _this = this; |
|
421 |
||
422 |
var thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this; |
|
423 |
||
424 |
this._map.forEach(function (value, key) { |
|
425 |
// Unwrap value from object-like value pair. |
|
426 |
if (key !== null && _typeof(key) === 'object') { |
|
427 |
value = value[1]; |
|
428 |
} |
|
429 |
||
430 |
callback.call(thisArg, value, key, _this); |
|
431 |
}); |
|
432 |
} |
|
433 |
/** |
|
434 |
* Removes all elements. |
|
435 |
*/ |
|
436 |
||
437 |
}, { |
|
438 |
key: "clear", |
|
439 |
value: function clear() { |
|
440 |
this._map = new Map(); |
|
441 |
this._arrayTreeMap = new Map(); |
|
442 |
this._objectTreeMap = new Map(); |
|
443 |
} |
|
444 |
}, { |
|
445 |
key: "size", |
|
446 |
get: function get() { |
|
447 |
return this._map.size; |
|
448 |
} |
|
449 |
}]); |
|
450 |
||
451 |
return EquivalentKeyMap; |
|
452 |
}(); |
|
453 |
||
454 |
module.exports = EquivalentKeyMap; |
|
455 |
||
456 |
||
19 | 457 |
/***/ }) |
458 |
||
459 |
/******/ }); |
|
460 |
/************************************************************************/ |
|
461 |
/******/ // The module cache |
|
462 |
/******/ var __webpack_module_cache__ = {}; |
|
463 |
/******/ |
|
464 |
/******/ // The require function |
|
465 |
/******/ function __webpack_require__(moduleId) { |
|
466 |
/******/ // Check if module is in cache |
|
467 |
/******/ var cachedModule = __webpack_module_cache__[moduleId]; |
|
468 |
/******/ if (cachedModule !== undefined) { |
|
469 |
/******/ return cachedModule.exports; |
|
470 |
/******/ } |
|
471 |
/******/ // Create a new module (and put it into the cache) |
|
472 |
/******/ var module = __webpack_module_cache__[moduleId] = { |
|
473 |
/******/ // no module.id needed |
|
474 |
/******/ // no module.loaded needed |
|
475 |
/******/ exports: {} |
|
476 |
/******/ }; |
|
477 |
/******/ |
|
478 |
/******/ // Execute the module function |
|
479 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
|
480 |
/******/ |
|
481 |
/******/ // Return the exports of the module |
|
482 |
/******/ return module.exports; |
|
483 |
/******/ } |
|
484 |
/******/ |
|
485 |
/************************************************************************/ |
|
486 |
/******/ /* webpack/runtime/compat get default export */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
487 |
/******/ (() => { |
19 | 488 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
489 |
/******/ __webpack_require__.n = (module) => { |
19 | 490 |
/******/ var getter = module && module.__esModule ? |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
491 |
/******/ () => (module['default']) : |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
492 |
/******/ () => (module); |
19 | 493 |
/******/ __webpack_require__.d(getter, { a: getter }); |
494 |
/******/ return getter; |
|
495 |
/******/ }; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
496 |
/******/ })(); |
19 | 497 |
/******/ |
498 |
/******/ /* webpack/runtime/define property getters */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
499 |
/******/ (() => { |
19 | 500 |
/******/ // define getter functions for harmony exports |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
501 |
/******/ __webpack_require__.d = (exports, definition) => { |
19 | 502 |
/******/ for(var key in definition) { |
503 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
|
504 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
|
505 |
/******/ } |
|
506 |
/******/ } |
|
507 |
/******/ }; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
508 |
/******/ })(); |
19 | 509 |
/******/ |
510 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
511 |
/******/ (() => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
512 |
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
513 |
/******/ })(); |
19 | 514 |
/******/ |
515 |
/******/ /* webpack/runtime/make namespace object */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
516 |
/******/ (() => { |
19 | 517 |
/******/ // define __esModule on exports |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
518 |
/******/ __webpack_require__.r = (exports) => { |
19 | 519 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
520 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
|
521 |
/******/ } |
|
522 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
|
523 |
/******/ }; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
524 |
/******/ })(); |
19 | 525 |
/******/ |
526 |
/************************************************************************/ |
|
527 |
var __webpack_exports__ = {}; |
|
16 | 528 |
// ESM COMPAT FLAG |
529 |
__webpack_require__.r(__webpack_exports__); |
|
530 |
||
531 |
// EXPORTS |
|
19 | 532 |
__webpack_require__.d(__webpack_exports__, { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
533 |
AsyncModeProvider: () => (/* reexport */ async_mode_provider_context), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
534 |
RegistryConsumer: () => (/* reexport */ RegistryConsumer), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
535 |
RegistryProvider: () => (/* reexport */ context), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
536 |
combineReducers: () => (/* binding */ build_module_combineReducers), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
537 |
controls: () => (/* reexport */ controls), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
538 |
createReduxStore: () => (/* reexport */ createReduxStore), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
539 |
createRegistry: () => (/* reexport */ createRegistry), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
540 |
createRegistryControl: () => (/* reexport */ createRegistryControl), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
541 |
createRegistrySelector: () => (/* reexport */ createRegistrySelector), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
542 |
createSelector: () => (/* reexport */ rememo), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
543 |
dispatch: () => (/* reexport */ dispatch_dispatch), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
544 |
plugins: () => (/* reexport */ plugins_namespaceObject), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
545 |
register: () => (/* binding */ register), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
546 |
registerGenericStore: () => (/* binding */ registerGenericStore), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
547 |
registerStore: () => (/* binding */ registerStore), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
548 |
resolveSelect: () => (/* binding */ build_module_resolveSelect), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
549 |
select: () => (/* reexport */ select_select), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
550 |
subscribe: () => (/* binding */ subscribe), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
551 |
suspendSelect: () => (/* binding */ suspendSelect), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
552 |
use: () => (/* binding */ use), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
553 |
useDispatch: () => (/* reexport */ use_dispatch), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
554 |
useRegistry: () => (/* reexport */ useRegistry), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
555 |
useSelect: () => (/* reexport */ useSelect), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
556 |
useSuspenseSelect: () => (/* reexport */ useSuspenseSelect), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
557 |
withDispatch: () => (/* reexport */ with_dispatch), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
558 |
withRegistry: () => (/* reexport */ with_registry), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
559 |
withSelect: () => (/* reexport */ with_select) |
19 | 560 |
}); |
18 | 561 |
|
562 |
// NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/redux-store/metadata/selectors.js |
|
16 | 563 |
var selectors_namespaceObject = {}; |
564 |
__webpack_require__.r(selectors_namespaceObject); |
|
19 | 565 |
__webpack_require__.d(selectors_namespaceObject, { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
566 |
countSelectorsByStatus: () => (countSelectorsByStatus), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
567 |
getCachedResolvers: () => (getCachedResolvers), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
568 |
getIsResolving: () => (getIsResolving), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
569 |
getResolutionError: () => (getResolutionError), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
570 |
getResolutionState: () => (getResolutionState), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
571 |
hasFinishedResolution: () => (hasFinishedResolution), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
572 |
hasResolutionFailed: () => (hasResolutionFailed), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
573 |
hasResolvingSelectors: () => (hasResolvingSelectors), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
574 |
hasStartedResolution: () => (hasStartedResolution), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
575 |
isResolving: () => (isResolving) |
19 | 576 |
}); |
16 | 577 |
|
18 | 578 |
// NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/redux-store/metadata/actions.js |
16 | 579 |
var actions_namespaceObject = {}; |
580 |
__webpack_require__.r(actions_namespaceObject); |
|
19 | 581 |
__webpack_require__.d(actions_namespaceObject, { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
582 |
failResolution: () => (failResolution), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
583 |
failResolutions: () => (failResolutions), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
584 |
finishResolution: () => (finishResolution), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
585 |
finishResolutions: () => (finishResolutions), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
586 |
invalidateResolution: () => (invalidateResolution), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
587 |
invalidateResolutionForStore: () => (invalidateResolutionForStore), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
588 |
invalidateResolutionForStoreSelector: () => (invalidateResolutionForStoreSelector), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
589 |
startResolution: () => (startResolution), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
590 |
startResolutions: () => (startResolutions) |
19 | 591 |
}); |
16 | 592 |
|
593 |
// NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/plugins/index.js |
|
594 |
var plugins_namespaceObject = {}; |
|
595 |
__webpack_require__.r(plugins_namespaceObject); |
|
19 | 596 |
__webpack_require__.d(plugins_namespaceObject, { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
597 |
persistence: () => (persistence) |
19 | 598 |
}); |
16 | 599 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
600 |
;// external ["wp","deprecated"] |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
601 |
const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; |
19 | 602 |
var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
603 |
;// ./node_modules/redux/dist/redux.mjs |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
604 |
// src/utils/formatProdErrorMessage.ts |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
605 |
function formatProdErrorMessage(code) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
606 |
return `Minified Redux error #${code}; visit https://redux.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `; |
18 | 607 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
608 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
609 |
// src/utils/symbol-observable.ts |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
610 |
var $$observable = /* @__PURE__ */ (() => typeof Symbol === "function" && Symbol.observable || "@@observable")(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
611 |
var symbol_observable_default = $$observable; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
612 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
613 |
// src/utils/actionTypes.ts |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
614 |
var randomString = () => Math.random().toString(36).substring(7).split("").join("."); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
615 |
var ActionTypes = { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
616 |
INIT: `@@redux/INIT${/* @__PURE__ */ randomString()}`, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
617 |
REPLACE: `@@redux/REPLACE${/* @__PURE__ */ randomString()}`, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
618 |
PROBE_UNKNOWN_ACTION: () => `@@redux/PROBE_UNKNOWN_ACTION${randomString()}` |
16 | 619 |
}; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
620 |
var actionTypes_default = ActionTypes; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
621 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
622 |
// src/utils/isPlainObject.ts |
16 | 623 |
function isPlainObject(obj) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
624 |
if (typeof obj !== "object" || obj === null) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
625 |
return false; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
626 |
let proto = obj; |
16 | 627 |
while (Object.getPrototypeOf(proto) !== null) { |
628 |
proto = Object.getPrototypeOf(proto); |
|
629 |
} |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
630 |
return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null; |
16 | 631 |
} |
632 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
633 |
// src/utils/kindOf.ts |
18 | 634 |
function miniKindOf(val) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
635 |
if (val === void 0) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
636 |
return "undefined"; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
637 |
if (val === null) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
638 |
return "null"; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
639 |
const type = typeof val; |
18 | 640 |
switch (type) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
641 |
case "boolean": |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
642 |
case "string": |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
643 |
case "number": |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
644 |
case "symbol": |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
645 |
case "function": { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
646 |
return type; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
647 |
} |
18 | 648 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
649 |
if (Array.isArray(val)) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
650 |
return "array"; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
651 |
if (isDate(val)) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
652 |
return "date"; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
653 |
if (isError(val)) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
654 |
return "error"; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
655 |
const constructorName = ctorName(val); |
18 | 656 |
switch (constructorName) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
657 |
case "Symbol": |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
658 |
case "Promise": |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
659 |
case "WeakMap": |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
660 |
case "WeakSet": |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
661 |
case "Map": |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
662 |
case "Set": |
18 | 663 |
return constructorName; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
664 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
665 |
return Object.prototype.toString.call(val).slice(8, -1).toLowerCase().replace(/\s/g, ""); |
18 | 666 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
667 |
function ctorName(val) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
668 |
return typeof val.constructor === "function" ? val.constructor.name : null; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
669 |
} |
18 | 670 |
function isError(val) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
671 |
return val instanceof Error || typeof val.message === "string" && val.constructor && typeof val.constructor.stackTraceLimit === "number"; |
18 | 672 |
} |
673 |
function isDate(val) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
674 |
if (val instanceof Date) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
675 |
return true; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
676 |
return typeof val.toDateString === "function" && typeof val.getDate === "function" && typeof val.setDate === "function"; |
18 | 677 |
} |
678 |
function kindOf(val) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
679 |
let typeOfVal = typeof val; |
18 | 680 |
if (false) {} |
681 |
return typeOfVal; |
|
682 |
} |
|
683 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
684 |
// src/createStore.ts |
19 | 685 |
function createStore(reducer, preloadedState, enhancer) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
686 |
if (typeof reducer !== "function") { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
687 |
throw new Error( true ? formatProdErrorMessage(2) : 0); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
688 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
689 |
if (typeof preloadedState === "function" && typeof enhancer === "function" || typeof enhancer === "function" && typeof arguments[3] === "function") { |
19 | 690 |
throw new Error( true ? formatProdErrorMessage(0) : 0); |
16 | 691 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
692 |
if (typeof preloadedState === "function" && typeof enhancer === "undefined") { |
16 | 693 |
enhancer = preloadedState; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
694 |
preloadedState = void 0; |
16 | 695 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
696 |
if (typeof enhancer !== "undefined") { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
697 |
if (typeof enhancer !== "function") { |
19 | 698 |
throw new Error( true ? formatProdErrorMessage(1) : 0); |
16 | 699 |
} |
19 | 700 |
return enhancer(createStore)(reducer, preloadedState); |
16 | 701 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
702 |
let currentReducer = reducer; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
703 |
let currentState = preloadedState; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
704 |
let currentListeners = /* @__PURE__ */ new Map(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
705 |
let nextListeners = currentListeners; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
706 |
let listenerIdCounter = 0; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
707 |
let isDispatching = false; |
16 | 708 |
function ensureCanMutateNextListeners() { |
709 |
if (nextListeners === currentListeners) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
710 |
nextListeners = /* @__PURE__ */ new Map(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
711 |
currentListeners.forEach((listener, key) => { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
712 |
nextListeners.set(key, listener); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
713 |
}); |
16 | 714 |
} |
715 |
} |
|
716 |
function getState() { |
|
717 |
if (isDispatching) { |
|
19 | 718 |
throw new Error( true ? formatProdErrorMessage(3) : 0); |
16 | 719 |
} |
720 |
return currentState; |
|
721 |
} |
|
722 |
function subscribe(listener) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
723 |
if (typeof listener !== "function") { |
19 | 724 |
throw new Error( true ? formatProdErrorMessage(4) : 0); |
16 | 725 |
} |
726 |
if (isDispatching) { |
|
19 | 727 |
throw new Error( true ? formatProdErrorMessage(5) : 0); |
16 | 728 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
729 |
let isSubscribed = true; |
16 | 730 |
ensureCanMutateNextListeners(); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
731 |
const listenerId = listenerIdCounter++; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
732 |
nextListeners.set(listenerId, listener); |
16 | 733 |
return function unsubscribe() { |
734 |
if (!isSubscribed) { |
|
735 |
return; |
|
736 |
} |
|
737 |
if (isDispatching) { |
|
19 | 738 |
throw new Error( true ? formatProdErrorMessage(6) : 0); |
16 | 739 |
} |
740 |
isSubscribed = false; |
|
741 |
ensureCanMutateNextListeners(); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
742 |
nextListeners.delete(listenerId); |
16 | 743 |
currentListeners = null; |
744 |
}; |
|
745 |
} |
|
746 |
function dispatch(action) { |
|
747 |
if (!isPlainObject(action)) { |
|
19 | 748 |
throw new Error( true ? formatProdErrorMessage(7) : 0); |
16 | 749 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
750 |
if (typeof action.type === "undefined") { |
19 | 751 |
throw new Error( true ? formatProdErrorMessage(8) : 0); |
16 | 752 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
753 |
if (typeof action.type !== "string") { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
754 |
throw new Error( true ? formatProdErrorMessage(17) : 0); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
755 |
} |
16 | 756 |
if (isDispatching) { |
19 | 757 |
throw new Error( true ? formatProdErrorMessage(9) : 0); |
16 | 758 |
} |
759 |
try { |
|
760 |
isDispatching = true; |
|
761 |
currentState = currentReducer(currentState, action); |
|
762 |
} finally { |
|
763 |
isDispatching = false; |
|
764 |
} |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
765 |
const listeners = currentListeners = nextListeners; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
766 |
listeners.forEach((listener) => { |
16 | 767 |
listener(); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
768 |
}); |
16 | 769 |
return action; |
770 |
} |
|
771 |
function replaceReducer(nextReducer) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
772 |
if (typeof nextReducer !== "function") { |
19 | 773 |
throw new Error( true ? formatProdErrorMessage(10) : 0); |
16 | 774 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
775 |
currentReducer = nextReducer; |
16 | 776 |
dispatch({ |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
777 |
type: actionTypes_default.REPLACE |
16 | 778 |
}); |
779 |
} |
|
780 |
function observable() { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
781 |
const outerSubscribe = subscribe; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
782 |
return { |
16 | 783 |
/** |
784 |
* The minimal observable subscription method. |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
785 |
* @param observer Any object that can be used as an observer. |
16 | 786 |
* The observer object should have a `next` method. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
787 |
* @returns An object with an `unsubscribe` method that can |
16 | 788 |
* be used to unsubscribe the observable from the store, and prevent further |
789 |
* emission of values from the observable. |
|
790 |
*/ |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
791 |
subscribe(observer) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
792 |
if (typeof observer !== "object" || observer === null) { |
19 | 793 |
throw new Error( true ? formatProdErrorMessage(11) : 0); |
16 | 794 |
} |
795 |
function observeState() { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
796 |
const observerAsObserver = observer; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
797 |
if (observerAsObserver.next) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
798 |
observerAsObserver.next(getState()); |
16 | 799 |
} |
800 |
} |
|
801 |
observeState(); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
802 |
const unsubscribe = outerSubscribe(observeState); |
16 | 803 |
return { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
804 |
unsubscribe |
16 | 805 |
}; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
806 |
}, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
807 |
[symbol_observable_default]() { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
808 |
return this; |
16 | 809 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
810 |
}; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
811 |
} |
16 | 812 |
dispatch({ |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
813 |
type: actionTypes_default.INIT |
16 | 814 |
}); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
815 |
const store = { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
816 |
dispatch, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
817 |
subscribe, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
818 |
getState, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
819 |
replaceReducer, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
820 |
[symbol_observable_default]: observable |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
821 |
}; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
822 |
return store; |
16 | 823 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
824 |
function legacy_createStore(reducer, preloadedState, enhancer) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
825 |
return createStore(reducer, preloadedState, enhancer); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
826 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
827 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
828 |
// src/utils/warning.ts |
16 | 829 |
function warning(message) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
830 |
if (typeof console !== "undefined" && typeof console.error === "function") { |
16 | 831 |
console.error(message); |
832 |
} |
|
833 |
try { |
|
834 |
throw new Error(message); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
835 |
} catch (e) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
836 |
} |
16 | 837 |
} |
838 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
839 |
// src/combineReducers.ts |
16 | 840 |
function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
841 |
const reducerKeys = Object.keys(reducers); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
842 |
const argumentName = action && action.type === actionTypes_default.INIT ? "preloadedState argument passed to createStore" : "previous state received by the reducer"; |
16 | 843 |
if (reducerKeys.length === 0) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
844 |
return "Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers."; |
16 | 845 |
} |
846 |
if (!isPlainObject(inputState)) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
847 |
return `The ${argumentName} has unexpected type of "${kindOf(inputState)}". Expected argument to be an object with the following keys: "${reducerKeys.join('", "')}"`; |
16 | 848 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
849 |
const unexpectedKeys = Object.keys(inputState).filter((key) => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
850 |
unexpectedKeys.forEach((key) => { |
16 | 851 |
unexpectedKeyCache[key] = true; |
852 |
}); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
853 |
if (action && action.type === actionTypes_default.REPLACE) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
854 |
return; |
16 | 855 |
if (unexpectedKeys.length > 0) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
856 |
return `Unexpected ${unexpectedKeys.length > 1 ? "keys" : "key"} "${unexpectedKeys.join('", "')}" found in ${argumentName}. Expected to find one of the known reducer keys instead: "${reducerKeys.join('", "')}". Unexpected keys will be ignored.`; |
16 | 857 |
} |
858 |
} |
|
859 |
function assertReducerShape(reducers) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
860 |
Object.keys(reducers).forEach((key) => { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
861 |
const reducer = reducers[key]; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
862 |
const initialState = reducer(void 0, { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
863 |
type: actionTypes_default.INIT |
16 | 864 |
}); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
865 |
if (typeof initialState === "undefined") { |
19 | 866 |
throw new Error( true ? formatProdErrorMessage(12) : 0); |
16 | 867 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
868 |
if (typeof reducer(void 0, { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
869 |
type: actionTypes_default.PROBE_UNKNOWN_ACTION() |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
870 |
}) === "undefined") { |
19 | 871 |
throw new Error( true ? formatProdErrorMessage(13) : 0); |
16 | 872 |
} |
873 |
}); |
|
874 |
} |
|
875 |
function combineReducers(reducers) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
876 |
const reducerKeys = Object.keys(reducers); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
877 |
const finalReducers = {}; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
878 |
for (let i = 0; i < reducerKeys.length; i++) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
879 |
const key = reducerKeys[i]; |
16 | 880 |
if (false) {} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
881 |
if (typeof reducers[key] === "function") { |
16 | 882 |
finalReducers[key] = reducers[key]; |
883 |
} |
|
884 |
} |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
885 |
const finalReducerKeys = Object.keys(finalReducers); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
886 |
let unexpectedKeyCache; |
16 | 887 |
if (false) {} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
888 |
let shapeAssertionError; |
16 | 889 |
try { |
890 |
assertReducerShape(finalReducers); |
|
891 |
} catch (e) { |
|
892 |
shapeAssertionError = e; |
|
893 |
} |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
894 |
return function combination(state = {}, action) { |
16 | 895 |
if (shapeAssertionError) { |
896 |
throw shapeAssertionError; |
|
897 |
} |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
898 |
if (false) {} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
899 |
let hasChanged = false; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
900 |
const nextState = {}; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
901 |
for (let i = 0; i < finalReducerKeys.length; i++) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
902 |
const key = finalReducerKeys[i]; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
903 |
const reducer = finalReducers[key]; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
904 |
const previousStateForKey = state[key]; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
905 |
const nextStateForKey = reducer(previousStateForKey, action); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
906 |
if (typeof nextStateForKey === "undefined") { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
907 |
const actionType = action && action.type; |
19 | 908 |
throw new Error( true ? formatProdErrorMessage(14) : 0); |
16 | 909 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
910 |
nextState[key] = nextStateForKey; |
16 | 911 |
hasChanged = hasChanged || nextStateForKey !== previousStateForKey; |
912 |
} |
|
913 |
hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length; |
|
914 |
return hasChanged ? nextState : state; |
|
915 |
}; |
|
916 |
} |
|
917 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
918 |
// src/bindActionCreators.ts |
16 | 919 |
function bindActionCreator(actionCreator, dispatch) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
920 |
return function(...args) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
921 |
return dispatch(actionCreator.apply(this, args)); |
16 | 922 |
}; |
923 |
} |
|
924 |
function bindActionCreators(actionCreators, dispatch) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
925 |
if (typeof actionCreators === "function") { |
16 | 926 |
return bindActionCreator(actionCreators, dispatch); |
927 |
} |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
928 |
if (typeof actionCreators !== "object" || actionCreators === null) { |
19 | 929 |
throw new Error( true ? formatProdErrorMessage(16) : 0); |
16 | 930 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
931 |
const boundActionCreators = {}; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
932 |
for (const key in actionCreators) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
933 |
const actionCreator = actionCreators[key]; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
934 |
if (typeof actionCreator === "function") { |
16 | 935 |
boundActionCreators[key] = bindActionCreator(actionCreator, dispatch); |
936 |
} |
|
937 |
} |
|
938 |
return boundActionCreators; |
|
939 |
} |
|
940 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
941 |
// src/compose.ts |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
942 |
function compose(...funcs) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
943 |
if (funcs.length === 0) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
944 |
return (arg) => arg; |
16 | 945 |
} |
946 |
if (funcs.length === 1) { |
|
947 |
return funcs[0]; |
|
948 |
} |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
949 |
return funcs.reduce((a, b) => (...args) => a(b(...args))); |
16 | 950 |
} |
951 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
952 |
// src/applyMiddleware.ts |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
953 |
function applyMiddleware(...middlewares) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
954 |
return (createStore2) => (reducer, preloadedState) => { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
955 |
const store = createStore2(reducer, preloadedState); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
956 |
let dispatch = () => { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
957 |
throw new Error( true ? formatProdErrorMessage(15) : 0); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
958 |
}; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
959 |
const middlewareAPI = { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
960 |
getState: store.getState, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
961 |
dispatch: (action, ...args) => dispatch(action, ...args) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
962 |
}; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
963 |
const chain = middlewares.map((middleware) => middleware(middlewareAPI)); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
964 |
dispatch = compose(...chain)(store.dispatch); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
965 |
return { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
966 |
...store, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
967 |
dispatch |
16 | 968 |
}; |
969 |
}; |
|
970 |
} |
|
971 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
972 |
// src/utils/isAction.ts |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
973 |
function isAction(action) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
974 |
return isPlainObject(action) && "type" in action && typeof action.type === "string"; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
975 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
976 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
977 |
//# sourceMappingURL=redux.mjs.map |
18 | 978 |
// EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
979 |
var equivalent_key_map = __webpack_require__(3249); |
18 | 980 |
var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
981 |
;// external ["wp","reduxRoutine"] |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
982 |
const external_wp_reduxRoutine_namespaceObject = window["wp"]["reduxRoutine"]; |
19 | 983 |
var external_wp_reduxRoutine_default = /*#__PURE__*/__webpack_require__.n(external_wp_reduxRoutine_namespaceObject); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
984 |
;// external ["wp","compose"] |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
985 |
const external_wp_compose_namespaceObject = window["wp"]["compose"]; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
986 |
;// ./node_modules/@wordpress/data/build-module/redux-store/combine-reducers.js |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
987 |
function combine_reducers_combineReducers(reducers) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
988 |
const keys = Object.keys(reducers); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
989 |
return function combinedReducer(state = {}, action) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
990 |
const nextState = {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
991 |
let hasChanged = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
992 |
for (const key of keys) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
993 |
const reducer = reducers[key]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
994 |
const prevStateForKey = state[key]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
995 |
const nextStateForKey = reducer(prevStateForKey, action); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
996 |
nextState[key] = nextStateForKey; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
997 |
hasChanged = hasChanged || nextStateForKey !== prevStateForKey; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
998 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
999 |
return hasChanged ? nextState : state; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1000 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1001 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1002 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1003 |
;// ./node_modules/@wordpress/data/build-module/factory.js |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1004 |
/** |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1005 |
* Internal dependencies |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1006 |
*/ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1007 |
|
18 | 1008 |
/** |
1009 |
* Creates a selector function that takes additional curried argument with the |
|
1010 |
* registry `select` function. While a regular selector has signature |
|
1011 |
* ```js |
|
1012 |
* ( state, ...selectorArgs ) => ( result ) |
|
1013 |
* ``` |
|
1014 |
* that allows to select data from the store's `state`, a registry selector |
|
1015 |
* has signature: |
|
1016 |
* ```js |
|
1017 |
* ( select ) => ( state, ...selectorArgs ) => ( result ) |
|
1018 |
* ``` |
|
1019 |
* that supports also selecting from other registered stores. |
|
1020 |
* |
|
1021 |
* @example |
|
1022 |
* ```js |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1023 |
* import { store as coreStore } from '@wordpress/core-data'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1024 |
* import { store as editorStore } from '@wordpress/editor'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1025 |
* |
18 | 1026 |
* const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1027 |
* return select( editorStore ).getCurrentPostId(); |
18 | 1028 |
* } ); |
1029 |
* |
|
1030 |
* const getPostEdits = createRegistrySelector( ( select ) => ( state ) => { |
|
1031 |
* // calling another registry selector just like any other function |
|
1032 |
* const postType = getCurrentPostType( state ); |
|
1033 |
* const postId = getCurrentPostId( state ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1034 |
* return select( coreStore ).getEntityRecordEdits( 'postType', postType, postId ); |
18 | 1035 |
* } ); |
1036 |
* ``` |
|
1037 |
* |
|
1038 |
* Note how the `getCurrentPostId` selector can be called just like any other function, |
|
1039 |
* (it works even inside a regular non-registry selector) and we don't need to pass the |
|
1040 |
* registry as argument. The registry binding happens automatically when registering the selector |
|
1041 |
* with a store. |
|
1042 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1043 |
* @param registrySelector Function receiving a registry `select` |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1044 |
* function and returning a state selector. |
18 | 1045 |
* |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1046 |
* @return Registry selector that can be registered with a store. |
18 | 1047 |
*/ |
1048 |
function createRegistrySelector(registrySelector) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1049 |
const selectorsByRegistry = new WeakMap(); |
19 | 1050 |
// Create a selector function that is bound to the registry referenced by `selector.registry` |
18 | 1051 |
// and that has the same API as a regular selector. Binding it in such a way makes it |
1052 |
// possible to call the selector directly from another selector. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1053 |
const wrappedSelector = (...args) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1054 |
let selector = selectorsByRegistry.get(wrappedSelector.registry); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1055 |
// We want to make sure the cache persists even when new registry |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1056 |
// instances are created. For example patterns create their own editors |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1057 |
// with their own core/block-editor stores, so we should keep track of |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1058 |
// the cache for each registry instance. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1059 |
if (!selector) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1060 |
selector = registrySelector(wrappedSelector.registry.select); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1061 |
selectorsByRegistry.set(wrappedSelector.registry, selector); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1062 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1063 |
return selector(...args); |
19 | 1064 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1065 |
|
18 | 1066 |
/** |
1067 |
* Flag indicating that the selector is a registry selector that needs the correct registry |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1068 |
* reference to be assigned to `selector.registry` to make it work correctly. |
18 | 1069 |
* be mapped as a registry selector. |
1070 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1071 |
wrappedSelector.isRegistrySelector = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1072 |
return wrappedSelector; |
18 | 1073 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1074 |
|
18 | 1075 |
/** |
1076 |
* Creates a control function that takes additional curried argument with the `registry` object. |
|
1077 |
* While a regular control has signature |
|
1078 |
* ```js |
|
1079 |
* ( action ) => ( iteratorOrPromise ) |
|
1080 |
* ``` |
|
1081 |
* where the control works with the `action` that it's bound to, a registry control has signature: |
|
1082 |
* ```js |
|
1083 |
* ( registry ) => ( action ) => ( iteratorOrPromise ) |
|
1084 |
* ``` |
|
1085 |
* A registry control is typically used to select data or dispatch an action to a registered |
|
1086 |
* store. |
|
1087 |
* |
|
1088 |
* When registering a control created with `createRegistryControl` with a store, the store |
|
1089 |
* knows which calling convention to use when executing the control. |
|
1090 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1091 |
* @param registryControl Function receiving a registry object and returning a control. |
18 | 1092 |
* |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1093 |
* @return Registry control that can be registered with a store. |
18 | 1094 |
*/ |
1095 |
function createRegistryControl(registryControl) { |
|
1096 |
registryControl.isRegistryControl = true; |
|
1097 |
return registryControl; |
|
1098 |
} |
|
1099 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1100 |
;// ./node_modules/@wordpress/data/build-module/controls.js |
19 | 1101 |
/** |
18 | 1102 |
* Internal dependencies |
1103 |
*/ |
|
1104 |
||
19 | 1105 |
|
1106 |
/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */ |
|
1107 |
||
18 | 1108 |
const SELECT = '@@data/SELECT'; |
1109 |
const RESOLVE_SELECT = '@@data/RESOLVE_SELECT'; |
|
1110 |
const DISPATCH = '@@data/DISPATCH'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1111 |
function isObject(object) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1112 |
return object !== null && typeof object === 'object'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1113 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1114 |
|
18 | 1115 |
/** |
1116 |
* Dispatches a control action for triggering a synchronous registry select. |
|
1117 |
* |
|
1118 |
* Note: This control synchronously returns the current selector value, triggering the |
|
1119 |
* resolution, but not waiting for it. |
|
1120 |
* |
|
19 | 1121 |
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store |
1122 |
* @param {string} selectorName The name of the selector. |
|
1123 |
* @param {Array} args Arguments for the selector. |
|
18 | 1124 |
* |
1125 |
* @example |
|
1126 |
* ```js |
|
1127 |
* import { controls } from '@wordpress/data'; |
|
1128 |
* |
|
1129 |
* // Action generator using `select`. |
|
1130 |
* export function* myAction() { |
|
1131 |
* const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' ); |
|
1132 |
* // Do stuff with the result from the `select`. |
|
1133 |
* } |
|
1134 |
* ``` |
|
1135 |
* |
|
1136 |
* @return {Object} The control descriptor. |
|
1137 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1138 |
function controls_select(storeNameOrDescriptor, selectorName, ...args) { |
18 | 1139 |
return { |
1140 |
type: SELECT, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1141 |
storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor, |
18 | 1142 |
selectorName, |
1143 |
args |
|
1144 |
}; |
|
1145 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1146 |
|
18 | 1147 |
/** |
1148 |
* Dispatches a control action for triggering and resolving a registry select. |
|
1149 |
* |
|
1150 |
* Note: when this control action is handled, it automatically considers |
|
1151 |
* selectors that may have a resolver. In such case, it will return a `Promise` that resolves |
|
1152 |
* after the selector finishes resolving, with the final result value. |
|
1153 |
* |
|
19 | 1154 |
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store |
1155 |
* @param {string} selectorName The name of the selector |
|
1156 |
* @param {Array} args Arguments for the selector. |
|
18 | 1157 |
* |
1158 |
* @example |
|
1159 |
* ```js |
|
1160 |
* import { controls } from '@wordpress/data'; |
|
1161 |
* |
|
1162 |
* // Action generator using resolveSelect |
|
1163 |
* export function* myAction() { |
|
1164 |
* const isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' ); |
|
1165 |
* // do stuff with the result from the select. |
|
1166 |
* } |
|
1167 |
* ``` |
|
1168 |
* |
|
1169 |
* @return {Object} The control descriptor. |
|
1170 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1171 |
function resolveSelect(storeNameOrDescriptor, selectorName, ...args) { |
18 | 1172 |
return { |
1173 |
type: RESOLVE_SELECT, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1174 |
storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor, |
18 | 1175 |
selectorName, |
1176 |
args |
|
1177 |
}; |
|
1178 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1179 |
|
18 | 1180 |
/** |
1181 |
* Dispatches a control action for triggering a registry dispatch. |
|
1182 |
* |
|
19 | 1183 |
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store |
1184 |
* @param {string} actionName The name of the action to dispatch |
|
1185 |
* @param {Array} args Arguments for the dispatch action. |
|
18 | 1186 |
* |
1187 |
* @example |
|
1188 |
* ```js |
|
1189 |
* import { controls } from '@wordpress/data-controls'; |
|
1190 |
* |
|
1191 |
* // Action generator using dispatch |
|
1192 |
* export function* myAction() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1193 |
* yield controls.dispatch( 'core/editor', 'togglePublishSidebar' ); |
18 | 1194 |
* // do some other things. |
1195 |
* } |
|
1196 |
* ``` |
|
1197 |
* |
|
1198 |
* @return {Object} The control descriptor. |
|
1199 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1200 |
function dispatch(storeNameOrDescriptor, actionName, ...args) { |
18 | 1201 |
return { |
1202 |
type: DISPATCH, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1203 |
storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor, |
18 | 1204 |
actionName, |
1205 |
args |
|
1206 |
}; |
|
1207 |
} |
|
19 | 1208 |
const controls = { |
18 | 1209 |
select: controls_select, |
19 | 1210 |
resolveSelect, |
1211 |
dispatch |
|
18 | 1212 |
}; |
1213 |
const builtinControls = { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1214 |
[SELECT]: createRegistryControl(registry => ({ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1215 |
storeKey, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1216 |
selectorName, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1217 |
args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1218 |
}) => registry.select(storeKey)[selectorName](...args)), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1219 |
[RESOLVE_SELECT]: createRegistryControl(registry => ({ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1220 |
storeKey, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1221 |
selectorName, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1222 |
args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1223 |
}) => { |
18 | 1224 |
const method = registry.select(storeKey)[selectorName].hasResolver ? 'resolveSelect' : 'select'; |
1225 |
return registry[method](storeKey)[selectorName](...args); |
|
1226 |
}), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1227 |
[DISPATCH]: createRegistryControl(registry => ({ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1228 |
storeKey, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1229 |
actionName, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1230 |
args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1231 |
}) => registry.dispatch(storeKey)[actionName](...args)) |
18 | 1232 |
}; |
16 | 1233 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1234 |
;// external ["wp","privateApis"] |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1235 |
const external_wp_privateApis_namespaceObject = window["wp"]["privateApis"]; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1236 |
;// ./node_modules/@wordpress/data/build-module/lock-unlock.js |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1237 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1238 |
* WordPress dependencies |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1239 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1240 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1241 |
const { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1242 |
lock, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1243 |
unlock |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1244 |
} = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/data'); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1245 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1246 |
;// ./node_modules/is-promise/index.mjs |
19 | 1247 |
function isPromise(obj) { |
1248 |
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; |
|
1249 |
} |
|
1250 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1251 |
;// ./node_modules/@wordpress/data/build-module/promise-middleware.js |
16 | 1252 |
/** |
1253 |
* External dependencies |
|
1254 |
*/ |
|
1255 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1256 |
|
16 | 1257 |
/** |
1258 |
* Simplest possible promise redux middleware. |
|
1259 |
* |
|
19 | 1260 |
* @type {import('redux').Middleware} |
16 | 1261 |
*/ |
18 | 1262 |
const promiseMiddleware = () => next => action => { |
19 | 1263 |
if (isPromise(action)) { |
18 | 1264 |
return action.then(resolvedAction => { |
1265 |
if (resolvedAction) { |
|
1266 |
return next(resolvedAction); |
|
16 | 1267 |
} |
18 | 1268 |
}); |
1269 |
} |
|
1270 |
return next(action); |
|
16 | 1271 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1272 |
/* harmony default export */ const promise_middleware = (promiseMiddleware); |
19 | 1273 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1274 |
;// ./node_modules/@wordpress/data/build-module/resolvers-cache-middleware.js |
16 | 1275 |
/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */ |
1276 |
||
1277 |
/** |
|
1278 |
* Creates a middleware handling resolvers cache invalidation. |
|
1279 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1280 |
* @param {WPDataRegistry} registry Registry for which to create the middleware. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1281 |
* @param {string} storeName Name of the store for which to create the middleware. |
16 | 1282 |
* |
1283 |
* @return {Function} Middleware function. |
|
1284 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1285 |
const createResolversCacheMiddleware = (registry, storeName) => () => next => action => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1286 |
const resolvers = registry.select(storeName).getCachedResolvers(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1287 |
const resolverEntries = Object.entries(resolvers); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1288 |
resolverEntries.forEach(([selectorName, resolversByArgs]) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1289 |
const resolver = registry.stores[storeName]?.resolvers?.[selectorName]; |
18 | 1290 |
if (!resolver || !resolver.shouldInvalidate) { |
1291 |
return; |
|
1292 |
} |
|
1293 |
resolversByArgs.forEach((value, args) => { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1294 |
// Works around a bug in `EquivalentKeyMap` where `map.delete` merely sets an entry value |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1295 |
// to `undefined` and `map.forEach` then iterates also over these orphaned entries. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1296 |
if (value === undefined) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1297 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1298 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1299 |
|
18 | 1300 |
// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector. |
19 | 1301 |
// If the value is "finished" or "error" it means this resolver has finished its resolution which means we need |
1302 |
// to invalidate it, if it's true it means it's inflight and the invalidation is not necessary. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1303 |
if (value.status !== 'finished' && value.status !== 'error') { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1304 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1305 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1306 |
if (!resolver.shouldInvalidate(action, ...args)) { |
18 | 1307 |
return; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1308 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1309 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1310 |
// Trigger cache invalidation |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1311 |
registry.dispatch(storeName).invalidateResolution(selectorName, args); |
18 | 1312 |
}); |
1313 |
}); |
|
1314 |
return next(action); |
|
1315 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1316 |
/* harmony default export */ const resolvers_cache_middleware = (createResolversCacheMiddleware); |
18 | 1317 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1318 |
;// ./node_modules/@wordpress/data/build-module/redux-store/thunk-middleware.js |
18 | 1319 |
function createThunkMiddleware(args) { |
1320 |
return () => next => action => { |
|
1321 |
if (typeof action === 'function') { |
|
1322 |
return action(args); |
|
1323 |
} |
|
1324 |
return next(action); |
|
16 | 1325 |
}; |
18 | 1326 |
} |
1327 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1328 |
;// ./node_modules/@wordpress/data/build-module/redux-store/metadata/utils.js |
19 | 1329 |
/** |
1330 |
* External dependencies |
|
1331 |
*/ |
|
1332 |
||
16 | 1333 |
/** |
1334 |
* Higher-order reducer creator which creates a combined reducer object, keyed |
|
1335 |
* by a property on the action object. |
|
1336 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1337 |
* @param actionProperty Action property by which to key object. |
19 | 1338 |
* @return Higher-order reducer. |
16 | 1339 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1340 |
const onSubKey = actionProperty => reducer => (state = {}, action) => { |
18 | 1341 |
// Retrieve subkey from action. Do not track if undefined; useful for cases |
1342 |
// where reducer is scoped by action shape. |
|
1343 |
const key = action[actionProperty]; |
|
1344 |
if (key === undefined) { |
|
1345 |
return state; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1346 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1347 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1348 |
// Avoid updating state if unchanged. Note that this also accounts for a |
18 | 1349 |
// reducer which returns undefined on a key which is not yet tracked. |
1350 |
const nextKeyState = reducer(state[key], action); |
|
1351 |
if (nextKeyState === state[key]) { |
|
1352 |
return state; |
|
1353 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1354 |
return { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1355 |
...state, |
18 | 1356 |
[key]: nextKeyState |
16 | 1357 |
}; |
1358 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1359 |
|
19 | 1360 |
/** |
1361 |
* Normalize selector argument array by defaulting `undefined` value to an empty array |
|
1362 |
* and removing trailing `undefined` values. |
|
1363 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1364 |
* @param args Selector argument array |
19 | 1365 |
* @return Normalized state key array |
1366 |
*/ |
|
1367 |
function selectorArgsToStateKey(args) { |
|
1368 |
if (args === undefined || args === null) { |
|
1369 |
return []; |
|
1370 |
} |
|
1371 |
const len = args.length; |
|
1372 |
let idx = len; |
|
1373 |
while (idx > 0 && args[idx - 1] === undefined) { |
|
1374 |
idx--; |
|
1375 |
} |
|
1376 |
return idx === len ? args : args.slice(0, idx); |
|
1377 |
} |
|
1378 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1379 |
;// ./node_modules/@wordpress/data/build-module/redux-store/metadata/reducer.js |
16 | 1380 |
/** |
1381 |
* External dependencies |
|
1382 |
*/ |
|
1383 |
||
1384 |
/** |
|
1385 |
* Internal dependencies |
|
1386 |
*/ |
|
1387 |
||
1388 |
/** |
|
1389 |
* Reducer function returning next state for selector resolution of |
|
1390 |
* subkeys, object form: |
|
1391 |
* |
|
1392 |
* selectorName -> EquivalentKeyMap<Array,boolean> |
|
1393 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1394 |
const subKeysIsResolved = onSubKey('selectorName')((state = new (equivalent_key_map_default())(), action) => { |
16 | 1395 |
switch (action.type) { |
1396 |
case 'START_RESOLUTION': |
|
19 | 1397 |
{ |
1398 |
const nextState = new (equivalent_key_map_default())(state); |
|
1399 |
nextState.set(selectorArgsToStateKey(action.args), { |
|
1400 |
status: 'resolving' |
|
1401 |
}); |
|
1402 |
return nextState; |
|
1403 |
} |
|
16 | 1404 |
case 'FINISH_RESOLUTION': |
1405 |
{ |
|
19 | 1406 |
const nextState = new (equivalent_key_map_default())(state); |
1407 |
nextState.set(selectorArgsToStateKey(action.args), { |
|
1408 |
status: 'finished' |
|
1409 |
}); |
|
1410 |
return nextState; |
|
1411 |
} |
|
1412 |
case 'FAIL_RESOLUTION': |
|
1413 |
{ |
|
1414 |
const nextState = new (equivalent_key_map_default())(state); |
|
1415 |
nextState.set(selectorArgsToStateKey(action.args), { |
|
1416 |
status: 'error', |
|
1417 |
error: action.error |
|
1418 |
}); |
|
16 | 1419 |
return nextState; |
1420 |
} |
|
18 | 1421 |
case 'START_RESOLUTIONS': |
19 | 1422 |
{ |
1423 |
const nextState = new (equivalent_key_map_default())(state); |
|
1424 |
for (const resolutionArgs of action.args) { |
|
1425 |
nextState.set(selectorArgsToStateKey(resolutionArgs), { |
|
1426 |
status: 'resolving' |
|
1427 |
}); |
|
1428 |
} |
|
1429 |
return nextState; |
|
1430 |
} |
|
18 | 1431 |
case 'FINISH_RESOLUTIONS': |
1432 |
{ |
|
19 | 1433 |
const nextState = new (equivalent_key_map_default())(state); |
18 | 1434 |
for (const resolutionArgs of action.args) { |
19 | 1435 |
nextState.set(selectorArgsToStateKey(resolutionArgs), { |
1436 |
status: 'finished' |
|
1437 |
}); |
|
18 | 1438 |
} |
1439 |
return nextState; |
|
1440 |
} |
|
19 | 1441 |
case 'FAIL_RESOLUTIONS': |
1442 |
{ |
|
1443 |
const nextState = new (equivalent_key_map_default())(state); |
|
1444 |
action.args.forEach((resolutionArgs, idx) => { |
|
1445 |
const resolutionState = { |
|
1446 |
status: 'error', |
|
1447 |
error: undefined |
|
1448 |
}; |
|
1449 |
const error = action.errors[idx]; |
|
1450 |
if (error) { |
|
1451 |
resolutionState.error = error; |
|
1452 |
} |
|
1453 |
nextState.set(selectorArgsToStateKey(resolutionArgs), resolutionState); |
|
1454 |
}); |
|
1455 |
return nextState; |
|
1456 |
} |
|
16 | 1457 |
case 'INVALIDATE_RESOLUTION': |
1458 |
{ |
|
19 | 1459 |
const nextState = new (equivalent_key_map_default())(state); |
1460 |
nextState.delete(selectorArgsToStateKey(action.args)); |
|
18 | 1461 |
return nextState; |
16 | 1462 |
} |
1463 |
} |
|
1464 |
return state; |
|
1465 |
}); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1466 |
|
16 | 1467 |
/** |
1468 |
* Reducer function returning next state for selector resolution, object form: |
|
1469 |
* |
|
1470 |
* selectorName -> EquivalentKeyMap<Array, boolean> |
|
1471 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1472 |
* @param state Current state. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1473 |
* @param action Dispatched action. |
19 | 1474 |
* |
1475 |
* @return Next state. |
|
16 | 1476 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1477 |
const isResolved = (state = {}, action) => { |
16 | 1478 |
switch (action.type) { |
1479 |
case 'INVALIDATE_RESOLUTION_FOR_STORE': |
|
1480 |
return {}; |
|
1481 |
case 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR': |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1482 |
{ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1483 |
if (action.selectorName in state) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1484 |
const { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1485 |
[action.selectorName]: removedSelector, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1486 |
...restState |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1487 |
} = state; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1488 |
return restState; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1489 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1490 |
return state; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1491 |
} |
16 | 1492 |
case 'START_RESOLUTION': |
1493 |
case 'FINISH_RESOLUTION': |
|
19 | 1494 |
case 'FAIL_RESOLUTION': |
18 | 1495 |
case 'START_RESOLUTIONS': |
1496 |
case 'FINISH_RESOLUTIONS': |
|
19 | 1497 |
case 'FAIL_RESOLUTIONS': |
16 | 1498 |
case 'INVALIDATE_RESOLUTION': |
1499 |
return subKeysIsResolved(state, action); |
|
1500 |
} |
|
1501 |
return state; |
|
1502 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1503 |
/* harmony default export */ const metadata_reducer = (isResolved); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1504 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1505 |
;// ./node_modules/rememo/rememo.js |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1506 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1507 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1508 |
/** @typedef {(...args: any[]) => *[]} GetDependants */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1509 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1510 |
/** @typedef {() => void} Clear */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1511 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1512 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1513 |
* @typedef {{ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1514 |
* getDependants: GetDependants, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1515 |
* clear: Clear |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1516 |
* }} EnhancedSelector |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1517 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1518 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1519 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1520 |
* Internal cache entry. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1521 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1522 |
* @typedef CacheNode |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1523 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1524 |
* @property {?CacheNode|undefined} [prev] Previous node. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1525 |
* @property {?CacheNode|undefined} [next] Next node. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1526 |
* @property {*[]} args Function arguments for cache entry. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1527 |
* @property {*} val Function result. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1528 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1529 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1530 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1531 |
* @typedef Cache |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1532 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1533 |
* @property {Clear} clear Function to clear cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1534 |
* @property {boolean} [isUniqueByDependants] Whether dependants are valid in |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1535 |
* considering cache uniqueness. A cache is unique if dependents are all arrays |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1536 |
* or objects. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1537 |
* @property {CacheNode?} [head] Cache head. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1538 |
* @property {*[]} [lastDependants] Dependants from previous invocation. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1539 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1540 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1541 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1542 |
* Arbitrary value used as key for referencing cache object in WeakMap tree. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1543 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1544 |
* @type {{}} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1545 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1546 |
var LEAF_KEY = {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1547 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1548 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1549 |
* Returns the first argument as the sole entry in an array. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1550 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1551 |
* @template T |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1552 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1553 |
* @param {T} value Value to return. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1554 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1555 |
* @return {[T]} Value returned as entry in array. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1556 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1557 |
function arrayOf(value) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1558 |
return [value]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1559 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1560 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1561 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1562 |
* Returns true if the value passed is object-like, or false otherwise. A value |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1563 |
* is object-like if it can support property assignment, e.g. object or array. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1564 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1565 |
* @param {*} value Value to test. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1566 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1567 |
* @return {boolean} Whether value is object-like. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1568 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1569 |
function isObjectLike(value) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1570 |
return !!value && 'object' === typeof value; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1571 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1572 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1573 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1574 |
* Creates and returns a new cache object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1575 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1576 |
* @return {Cache} Cache object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1577 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1578 |
function createCache() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1579 |
/** @type {Cache} */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1580 |
var cache = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1581 |
clear: function () { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1582 |
cache.head = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1583 |
}, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1584 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1585 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1586 |
return cache; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1587 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1588 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1589 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1590 |
* Returns true if entries within the two arrays are strictly equal by |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1591 |
* reference from a starting index. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1592 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1593 |
* @param {*[]} a First array. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1594 |
* @param {*[]} b Second array. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1595 |
* @param {number} fromIndex Index from which to start comparison. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1596 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1597 |
* @return {boolean} Whether arrays are shallowly equal. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1598 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1599 |
function isShallowEqual(a, b, fromIndex) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1600 |
var i; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1601 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1602 |
if (a.length !== b.length) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1603 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1604 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1605 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1606 |
for (i = fromIndex; i < a.length; i++) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1607 |
if (a[i] !== b[i]) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1608 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1609 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1610 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1611 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1612 |
return true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1613 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1614 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1615 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1616 |
* Returns a memoized selector function. The getDependants function argument is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1617 |
* called before the memoized selector and is expected to return an immutable |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1618 |
* reference or array of references on which the selector depends for computing |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1619 |
* its own return value. The memoize cache is preserved only as long as those |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1620 |
* dependant references remain the same. If getDependants returns a different |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1621 |
* reference(s), the cache is cleared and the selector value regenerated. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1622 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1623 |
* @template {(...args: *[]) => *} S |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1624 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1625 |
* @param {S} selector Selector function. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1626 |
* @param {GetDependants=} getDependants Dependant getter returning an array of |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1627 |
* references used in cache bust consideration. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1628 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1629 |
/* harmony default export */ function rememo(selector, getDependants) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1630 |
/** @type {WeakMap<*,*>} */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1631 |
var rootCache; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1632 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1633 |
/** @type {GetDependants} */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1634 |
var normalizedGetDependants = getDependants ? getDependants : arrayOf; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1635 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1636 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1637 |
* Returns the cache for a given dependants array. When possible, a WeakMap |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1638 |
* will be used to create a unique cache for each set of dependants. This |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1639 |
* is feasible due to the nature of WeakMap in allowing garbage collection |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1640 |
* to occur on entries where the key object is no longer referenced. Since |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1641 |
* WeakMap requires the key to be an object, this is only possible when the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1642 |
* dependant is object-like. The root cache is created as a hierarchy where |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1643 |
* each top-level key is the first entry in a dependants set, the value a |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1644 |
* WeakMap where each key is the next dependant, and so on. This continues |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1645 |
* so long as the dependants are object-like. If no dependants are object- |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1646 |
* like, then the cache is shared across all invocations. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1647 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1648 |
* @see isObjectLike |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1649 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1650 |
* @param {*[]} dependants Selector dependants. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1651 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1652 |
* @return {Cache} Cache object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1653 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1654 |
function getCache(dependants) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1655 |
var caches = rootCache, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1656 |
isUniqueByDependants = true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1657 |
i, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1658 |
dependant, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1659 |
map, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1660 |
cache; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1661 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1662 |
for (i = 0; i < dependants.length; i++) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1663 |
dependant = dependants[i]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1664 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1665 |
// Can only compose WeakMap from object-like key. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1666 |
if (!isObjectLike(dependant)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1667 |
isUniqueByDependants = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1668 |
break; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1669 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1670 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1671 |
// Does current segment of cache already have a WeakMap? |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1672 |
if (caches.has(dependant)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1673 |
// Traverse into nested WeakMap. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1674 |
caches = caches.get(dependant); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1675 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1676 |
// Create, set, and traverse into a new one. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1677 |
map = new WeakMap(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1678 |
caches.set(dependant, map); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1679 |
caches = map; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1680 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1681 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1682 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1683 |
// We use an arbitrary (but consistent) object as key for the last item |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1684 |
// in the WeakMap to serve as our running cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1685 |
if (!caches.has(LEAF_KEY)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1686 |
cache = createCache(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1687 |
cache.isUniqueByDependants = isUniqueByDependants; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1688 |
caches.set(LEAF_KEY, cache); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1689 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1690 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1691 |
return caches.get(LEAF_KEY); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1692 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1693 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1694 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1695 |
* Resets root memoization cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1696 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1697 |
function clear() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1698 |
rootCache = new WeakMap(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1699 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1700 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1701 |
/* eslint-disable jsdoc/check-param-names */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1702 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1703 |
* The augmented selector call, considering first whether dependants have |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1704 |
* changed before passing it to underlying memoize function. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1705 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1706 |
* @param {*} source Source object for derivation. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1707 |
* @param {...*} extraArgs Additional arguments to pass to selector. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1708 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1709 |
* @return {*} Selector result. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1710 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1711 |
/* eslint-enable jsdoc/check-param-names */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1712 |
function callSelector(/* source, ...extraArgs */) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1713 |
var len = arguments.length, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1714 |
cache, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1715 |
node, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1716 |
i, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1717 |
args, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1718 |
dependants; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1719 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1720 |
// Create copy of arguments (avoid leaking deoptimization). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1721 |
args = new Array(len); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1722 |
for (i = 0; i < len; i++) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1723 |
args[i] = arguments[i]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1724 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1725 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1726 |
dependants = normalizedGetDependants.apply(null, args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1727 |
cache = getCache(dependants); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1728 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1729 |
// If not guaranteed uniqueness by dependants (primitive type), shallow |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1730 |
// compare against last dependants and, if references have changed, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1731 |
// destroy cache to recalculate result. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1732 |
if (!cache.isUniqueByDependants) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1733 |
if ( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1734 |
cache.lastDependants && |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1735 |
!isShallowEqual(dependants, cache.lastDependants, 0) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1736 |
) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1737 |
cache.clear(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1738 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1739 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1740 |
cache.lastDependants = dependants; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1741 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1742 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1743 |
node = cache.head; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1744 |
while (node) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1745 |
// Check whether node arguments match arguments |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1746 |
if (!isShallowEqual(node.args, args, 1)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1747 |
node = node.next; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1748 |
continue; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1749 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1750 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1751 |
// At this point we can assume we've found a match |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1752 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1753 |
// Surface matched node to head if not already |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1754 |
if (node !== cache.head) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1755 |
// Adjust siblings to point to each other. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1756 |
/** @type {CacheNode} */ (node.prev).next = node.next; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1757 |
if (node.next) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1758 |
node.next.prev = node.prev; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1759 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1760 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1761 |
node.next = cache.head; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1762 |
node.prev = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1763 |
/** @type {CacheNode} */ (cache.head).prev = node; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1764 |
cache.head = node; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1765 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1766 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1767 |
// Return immediately |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1768 |
return node.val; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1769 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1770 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1771 |
// No cached value found. Continue to insertion phase: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1772 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1773 |
node = /** @type {CacheNode} */ ({ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1774 |
// Generate the result from original function |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1775 |
val: selector.apply(null, args), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1776 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1777 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1778 |
// Avoid including the source object in the cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1779 |
args[0] = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1780 |
node.args = args; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1781 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1782 |
// Don't need to check whether node is already head, since it would |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1783 |
// have been returned above already if it was |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1784 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1785 |
// Shift existing head down list |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1786 |
if (cache.head) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1787 |
cache.head.prev = node; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1788 |
node.next = cache.head; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1789 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1790 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1791 |
cache.head = node; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1792 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1793 |
return node.val; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1794 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1795 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1796 |
callSelector.getDependants = normalizedGetDependants; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1797 |
callSelector.clear = clear; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1798 |
clear(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1799 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1800 |
return /** @type {S & EnhancedSelector} */ (callSelector); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1801 |
} |
18 | 1802 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1803 |
;// ./node_modules/@wordpress/data/build-module/redux-store/metadata/selectors.js |
16 | 1804 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1805 |
* WordPress dependencies |
16 | 1806 |
*/ |
1807 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1808 |
|
16 | 1809 |
/** |
19 | 1810 |
* Internal dependencies |
1811 |
*/ |
|
1812 |
||
1813 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1814 |
|
19 | 1815 |
/** @typedef {Record<string, import('./reducer').State>} State */ |
1816 |
/** @typedef {import('./reducer').StateValue} StateValue */ |
|
1817 |
/** @typedef {import('./reducer').Status} Status */ |
|
1818 |
||
1819 |
/** |
|
1820 |
* Returns the raw resolution state value for a given selector name, |
|
1821 |
* and arguments set. May be undefined if the selector has never been resolved |
|
1822 |
* or not resolved for the given set of arguments, otherwise true or false for |
|
1823 |
* resolution started and completed respectively. |
|
1824 |
* |
|
1825 |
* @param {State} state Data state. |
|
1826 |
* @param {string} selectorName Selector name. |
|
1827 |
* @param {unknown[]?} args Arguments passed to selector. |
|
1828 |
* |
|
1829 |
* @return {StateValue|undefined} isResolving value. |
|
1830 |
*/ |
|
1831 |
function getResolutionState(state, selectorName, args) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1832 |
const map = state[selectorName]; |
19 | 1833 |
if (!map) { |
1834 |
return; |
|
1835 |
} |
|
1836 |
return map.get(selectorArgsToStateKey(args)); |
|
1837 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1838 |
|
19 | 1839 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1840 |
* Returns an `isResolving`-like value for a given selector name and arguments set. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1841 |
* Its value is either `undefined` if the selector has never been resolved or has been |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1842 |
* invalidated, or a `true`/`false` boolean value if the resolution is in progress or |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1843 |
* has finished, respectively. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1844 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1845 |
* This is a legacy selector that was implemented when the "raw" internal data had |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1846 |
* this `undefined | boolean` format. Nowadays the internal value is an object that |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1847 |
* can be retrieved with `getResolutionState`. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1848 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1849 |
* @deprecated |
16 | 1850 |
* |
19 | 1851 |
* @param {State} state Data state. |
1852 |
* @param {string} selectorName Selector name. |
|
1853 |
* @param {unknown[]?} args Arguments passed to selector. |
|
1854 |
* |
|
1855 |
* @return {boolean | undefined} isResolving value. |
|
16 | 1856 |
*/ |
1857 |
function getIsResolving(state, selectorName, args) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1858 |
external_wp_deprecated_default()('wp.data.select( store ).getIsResolving', { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1859 |
since: '6.6', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1860 |
version: '6.8', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1861 |
alternative: 'wp.data.select( store ).getResolutionState' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1862 |
}); |
19 | 1863 |
const resolutionState = getResolutionState(state, selectorName, args); |
1864 |
return resolutionState && resolutionState.status === 'resolving'; |
|
16 | 1865 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1866 |
|
16 | 1867 |
/** |
1868 |
* Returns true if resolution has already been triggered for a given |
|
1869 |
* selector name, and arguments set. |
|
1870 |
* |
|
19 | 1871 |
* @param {State} state Data state. |
1872 |
* @param {string} selectorName Selector name. |
|
1873 |
* @param {unknown[]?} args Arguments passed to selector. |
|
16 | 1874 |
* |
1875 |
* @return {boolean} Whether resolution has been triggered. |
|
1876 |
*/ |
|
19 | 1877 |
function hasStartedResolution(state, selectorName, args) { |
1878 |
return getResolutionState(state, selectorName, args) !== undefined; |
|
16 | 1879 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1880 |
|
16 | 1881 |
/** |
1882 |
* Returns true if resolution has completed for a given selector |
|
1883 |
* name, and arguments set. |
|
1884 |
* |
|
19 | 1885 |
* @param {State} state Data state. |
1886 |
* @param {string} selectorName Selector name. |
|
1887 |
* @param {unknown[]?} args Arguments passed to selector. |
|
16 | 1888 |
* |
1889 |
* @return {boolean} Whether resolution has completed. |
|
1890 |
*/ |
|
19 | 1891 |
function hasFinishedResolution(state, selectorName, args) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1892 |
const status = getResolutionState(state, selectorName, args)?.status; |
19 | 1893 |
return status === 'finished' || status === 'error'; |
1894 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1895 |
|
19 | 1896 |
/** |
1897 |
* Returns true if resolution has failed for a given selector |
|
1898 |
* name, and arguments set. |
|
1899 |
* |
|
1900 |
* @param {State} state Data state. |
|
1901 |
* @param {string} selectorName Selector name. |
|
1902 |
* @param {unknown[]?} args Arguments passed to selector. |
|
1903 |
* |
|
1904 |
* @return {boolean} Has resolution failed |
|
1905 |
*/ |
|
1906 |
function hasResolutionFailed(state, selectorName, args) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1907 |
return getResolutionState(state, selectorName, args)?.status === 'error'; |
19 | 1908 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1909 |
|
19 | 1910 |
/** |
1911 |
* Returns the resolution error for a given selector name, and arguments set. |
|
1912 |
* Note it may be of an Error type, but may also be null, undefined, or anything else |
|
1913 |
* that can be `throw`-n. |
|
1914 |
* |
|
1915 |
* @param {State} state Data state. |
|
1916 |
* @param {string} selectorName Selector name. |
|
1917 |
* @param {unknown[]?} args Arguments passed to selector. |
|
1918 |
* |
|
1919 |
* @return {Error|unknown} Last resolution error |
|
1920 |
*/ |
|
1921 |
function getResolutionError(state, selectorName, args) { |
|
1922 |
const resolutionState = getResolutionState(state, selectorName, args); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1923 |
return resolutionState?.status === 'error' ? resolutionState.error : null; |
16 | 1924 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1925 |
|
16 | 1926 |
/** |
1927 |
* Returns true if resolution has been triggered but has not yet completed for |
|
1928 |
* a given selector name, and arguments set. |
|
1929 |
* |
|
19 | 1930 |
* @param {State} state Data state. |
1931 |
* @param {string} selectorName Selector name. |
|
1932 |
* @param {unknown[]?} args Arguments passed to selector. |
|
16 | 1933 |
* |
1934 |
* @return {boolean} Whether resolution is in progress. |
|
1935 |
*/ |
|
19 | 1936 |
function isResolving(state, selectorName, args) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1937 |
return getResolutionState(state, selectorName, args)?.status === 'resolving'; |
16 | 1938 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1939 |
|
16 | 1940 |
/** |
1941 |
* Returns the list of the cached resolvers. |
|
1942 |
* |
|
19 | 1943 |
* @param {State} state Data state. |
1944 |
* |
|
1945 |
* @return {State} Resolvers mapped by args and selectorName. |
|
16 | 1946 |
*/ |
1947 |
function getCachedResolvers(state) { |
|
1948 |
return state; |
|
1949 |
} |
|
1950 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1951 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1952 |
* Whether the store has any currently resolving selectors. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1953 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1954 |
* @param {State} state Data state. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1955 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1956 |
* @return {boolean} True if one or more selectors are resolving, false otherwise. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1957 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1958 |
function hasResolvingSelectors(state) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1959 |
return Object.values(state).some(selectorState => |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1960 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1961 |
* This uses the internal `_map` property of `EquivalentKeyMap` for |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1962 |
* optimization purposes, since the `EquivalentKeyMap` implementation |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1963 |
* does not support a `.values()` implementation. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1964 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1965 |
* @see https://github.com/aduth/equivalent-key-map |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1966 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1967 |
Array.from(selectorState._map.values()).some(resolution => resolution[1]?.status === 'resolving')); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1968 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1969 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1970 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1971 |
* Retrieves the total number of selectors, grouped per status. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1972 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1973 |
* @param {State} state Data state. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1974 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1975 |
* @return {Object} Object, containing selector totals by status. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1976 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1977 |
const countSelectorsByStatus = rememo(state => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1978 |
const selectorsByStatus = {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1979 |
Object.values(state).forEach(selectorState => |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1980 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1981 |
* This uses the internal `_map` property of `EquivalentKeyMap` for |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1982 |
* optimization purposes, since the `EquivalentKeyMap` implementation |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1983 |
* does not support a `.values()` implementation. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1984 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1985 |
* @see https://github.com/aduth/equivalent-key-map |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1986 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1987 |
Array.from(selectorState._map.values()).forEach(resolution => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1988 |
var _resolution$1$status; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1989 |
const currentStatus = (_resolution$1$status = resolution[1]?.status) !== null && _resolution$1$status !== void 0 ? _resolution$1$status : 'error'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1990 |
if (!selectorsByStatus[currentStatus]) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1991 |
selectorsByStatus[currentStatus] = 0; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1992 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1993 |
selectorsByStatus[currentStatus]++; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1994 |
})); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1995 |
return selectorsByStatus; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1996 |
}, state => [state]); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1997 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1998 |
;// ./node_modules/@wordpress/data/build-module/redux-store/metadata/actions.js |
16 | 1999 |
/** |
2000 |
* Returns an action object used in signalling that selector resolution has |
|
2001 |
* started. |
|
2002 |
* |
|
19 | 2003 |
* @param {string} selectorName Name of selector for which resolver triggered. |
2004 |
* @param {unknown[]} args Arguments to associate for uniqueness. |
|
2005 |
* |
|
2006 |
* @return {{ type: 'START_RESOLUTION', selectorName: string, args: unknown[] }} Action object. |
|
16 | 2007 |
*/ |
2008 |
function startResolution(selectorName, args) { |
|
2009 |
return { |
|
2010 |
type: 'START_RESOLUTION', |
|
18 | 2011 |
selectorName, |
2012 |
args |
|
16 | 2013 |
}; |
2014 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2015 |
|
16 | 2016 |
/** |
2017 |
* Returns an action object used in signalling that selector resolution has |
|
2018 |
* completed. |
|
2019 |
* |
|
19 | 2020 |
* @param {string} selectorName Name of selector for which resolver triggered. |
2021 |
* @param {unknown[]} args Arguments to associate for uniqueness. |
|
2022 |
* |
|
2023 |
* @return {{ type: 'FINISH_RESOLUTION', selectorName: string, args: unknown[] }} Action object. |
|
16 | 2024 |
*/ |
2025 |
function finishResolution(selectorName, args) { |
|
2026 |
return { |
|
2027 |
type: 'FINISH_RESOLUTION', |
|
18 | 2028 |
selectorName, |
2029 |
args |
|
2030 |
}; |
|
2031 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2032 |
|
18 | 2033 |
/** |
19 | 2034 |
* Returns an action object used in signalling that selector resolution has |
2035 |
* failed. |
|
2036 |
* |
|
2037 |
* @param {string} selectorName Name of selector for which resolver triggered. |
|
2038 |
* @param {unknown[]} args Arguments to associate for uniqueness. |
|
2039 |
* @param {Error|unknown} error The error that caused the failure. |
|
2040 |
* |
|
2041 |
* @return {{ type: 'FAIL_RESOLUTION', selectorName: string, args: unknown[], error: Error|unknown }} Action object. |
|
2042 |
*/ |
|
2043 |
function failResolution(selectorName, args, error) { |
|
2044 |
return { |
|
2045 |
type: 'FAIL_RESOLUTION', |
|
2046 |
selectorName, |
|
2047 |
args, |
|
2048 |
error |
|
2049 |
}; |
|
2050 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2051 |
|
19 | 2052 |
/** |
18 | 2053 |
* Returns an action object used in signalling that a batch of selector resolutions has |
2054 |
* started. |
|
2055 |
* |
|
19 | 2056 |
* @param {string} selectorName Name of selector for which resolver triggered. |
2057 |
* @param {unknown[][]} args Array of arguments to associate for uniqueness, each item |
|
2058 |
* is associated to a resolution. |
|
2059 |
* |
|
2060 |
* @return {{ type: 'START_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object. |
|
18 | 2061 |
*/ |
2062 |
function startResolutions(selectorName, args) { |
|
2063 |
return { |
|
2064 |
type: 'START_RESOLUTIONS', |
|
2065 |
selectorName, |
|
2066 |
args |
|
2067 |
}; |
|
2068 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2069 |
|
18 | 2070 |
/** |
2071 |
* Returns an action object used in signalling that a batch of selector resolutions has |
|
2072 |
* completed. |
|
2073 |
* |
|
19 | 2074 |
* @param {string} selectorName Name of selector for which resolver triggered. |
2075 |
* @param {unknown[][]} args Array of arguments to associate for uniqueness, each item |
|
2076 |
* is associated to a resolution. |
|
2077 |
* |
|
2078 |
* @return {{ type: 'FINISH_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object. |
|
18 | 2079 |
*/ |
2080 |
function finishResolutions(selectorName, args) { |
|
2081 |
return { |
|
2082 |
type: 'FINISH_RESOLUTIONS', |
|
2083 |
selectorName, |
|
2084 |
args |
|
16 | 2085 |
}; |
2086 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2087 |
|
16 | 2088 |
/** |
19 | 2089 |
* Returns an action object used in signalling that a batch of selector resolutions has |
2090 |
* completed and at least one of them has failed. |
|
2091 |
* |
|
2092 |
* @param {string} selectorName Name of selector for which resolver triggered. |
|
2093 |
* @param {unknown[]} args Array of arguments to associate for uniqueness, each item |
|
2094 |
* is associated to a resolution. |
|
2095 |
* @param {(Error|unknown)[]} errors Array of errors to associate for uniqueness, each item |
|
2096 |
* is associated to a resolution. |
|
2097 |
* @return {{ type: 'FAIL_RESOLUTIONS', selectorName: string, args: unknown[], errors: Array<Error|unknown> }} Action object. |
|
2098 |
*/ |
|
2099 |
function failResolutions(selectorName, args, errors) { |
|
2100 |
return { |
|
2101 |
type: 'FAIL_RESOLUTIONS', |
|
2102 |
selectorName, |
|
2103 |
args, |
|
2104 |
errors |
|
2105 |
}; |
|
2106 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2107 |
|
19 | 2108 |
/** |
16 | 2109 |
* Returns an action object used in signalling that we should invalidate the resolution cache. |
2110 |
* |
|
19 | 2111 |
* @param {string} selectorName Name of selector for which resolver should be invalidated. |
2112 |
* @param {unknown[]} args Arguments to associate for uniqueness. |
|
2113 |
* |
|
2114 |
* @return {{ type: 'INVALIDATE_RESOLUTION', selectorName: string, args: any[] }} Action object. |
|
16 | 2115 |
*/ |
2116 |
function invalidateResolution(selectorName, args) { |
|
2117 |
return { |
|
2118 |
type: 'INVALIDATE_RESOLUTION', |
|
18 | 2119 |
selectorName, |
2120 |
args |
|
16 | 2121 |
}; |
2122 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2123 |
|
16 | 2124 |
/** |
2125 |
* Returns an action object used in signalling that the resolution |
|
2126 |
* should be invalidated. |
|
2127 |
* |
|
19 | 2128 |
* @return {{ type: 'INVALIDATE_RESOLUTION_FOR_STORE' }} Action object. |
16 | 2129 |
*/ |
2130 |
function invalidateResolutionForStore() { |
|
2131 |
return { |
|
2132 |
type: 'INVALIDATE_RESOLUTION_FOR_STORE' |
|
2133 |
}; |
|
2134 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2135 |
|
16 | 2136 |
/** |
2137 |
* Returns an action object used in signalling that the resolution cache for a |
|
2138 |
* given selectorName should be invalidated. |
|
2139 |
* |
|
2140 |
* @param {string} selectorName Name of selector for which all resolvers should |
|
2141 |
* be invalidated. |
|
2142 |
* |
|
19 | 2143 |
* @return {{ type: 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR', selectorName: string }} Action object. |
16 | 2144 |
*/ |
2145 |
function invalidateResolutionForStoreSelector(selectorName) { |
|
2146 |
return { |
|
2147 |
type: 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR', |
|
18 | 2148 |
selectorName |
16 | 2149 |
}; |
2150 |
} |
|
2151 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2152 |
;// ./node_modules/@wordpress/data/build-module/redux-store/index.js |
16 | 2153 |
/** |
2154 |
* External dependencies |
|
2155 |
*/ |
|
2156 |
||
2157 |
||
2158 |
||
2159 |
/** |
|
2160 |
* WordPress dependencies |
|
2161 |
*/ |
|
2162 |
||
2163 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2164 |
|
16 | 2165 |
/** |
2166 |
* Internal dependencies |
|
2167 |
*/ |
|
2168 |
||
2169 |
||
2170 |
||
2171 |
||
2172 |
||
2173 |
||
18 | 2174 |
|
2175 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2176 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2177 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2178 |
|
19 | 2179 |
/** @typedef {import('../types').DataRegistry} DataRegistry */ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2180 |
/** @typedef {import('../types').ListenerFunction} ListenerFunction */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2181 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2182 |
* @typedef {import('../types').StoreDescriptor<C>} StoreDescriptor |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2183 |
* @template {import('../types').AnyConfig} C |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2184 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2185 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2186 |
* @typedef {import('../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2187 |
* @template State |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2188 |
* @template {Record<string,import('../types').ActionCreator>} Actions |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2189 |
* @template Selectors |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2190 |
*/ |
19 | 2191 |
|
2192 |
const trimUndefinedValues = array => { |
|
2193 |
const result = [...array]; |
|
2194 |
for (let i = result.length - 1; i >= 0; i--) { |
|
2195 |
if (result[i] === undefined) { |
|
2196 |
result.splice(i, 1); |
|
2197 |
} |
|
2198 |
} |
|
2199 |
return result; |
|
2200 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2201 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2202 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2203 |
* Creates a new object with the same keys, but with `callback()` called as |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2204 |
* a transformer function on each of the values. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2205 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2206 |
* @param {Object} obj The object to transform. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2207 |
* @param {Function} callback The function to transform each object value. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2208 |
* @return {Array} Transformed object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2209 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2210 |
const mapValues = (obj, callback) => Object.fromEntries(Object.entries(obj !== null && obj !== void 0 ? obj : {}).map(([key, value]) => [key, callback(value, key)])); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2211 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2212 |
// Convert non serializable types to plain objects |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2213 |
const devToolsReplacer = (key, state) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2214 |
if (state instanceof Map) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2215 |
return Object.fromEntries(state); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2216 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2217 |
if (state instanceof window.HTMLElement) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2218 |
return null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2219 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2220 |
return state; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2221 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2222 |
|
16 | 2223 |
/** |
18 | 2224 |
* Create a cache to track whether resolvers started running or not. |
16 | 2225 |
* |
18 | 2226 |
* @return {Object} Resolvers Cache. |
16 | 2227 |
*/ |
18 | 2228 |
function createResolversCache() { |
2229 |
const cache = {}; |
|
2230 |
return { |
|
2231 |
isRunning(selectorName, args) { |
|
19 | 2232 |
return cache[selectorName] && cache[selectorName].get(trimUndefinedValues(args)); |
18 | 2233 |
}, |
2234 |
clear(selectorName, args) { |
|
2235 |
if (cache[selectorName]) { |
|
19 | 2236 |
cache[selectorName].delete(trimUndefinedValues(args)); |
16 | 2237 |
} |
18 | 2238 |
}, |
2239 |
markAsRunning(selectorName, args) { |
|
2240 |
if (!cache[selectorName]) { |
|
19 | 2241 |
cache[selectorName] = new (equivalent_key_map_default())(); |
16 | 2242 |
} |
19 | 2243 |
cache[selectorName].set(trimUndefinedValues(args), true); |
18 | 2244 |
} |
16 | 2245 |
}; |
18 | 2246 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2247 |
function createBindingCache(bind) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2248 |
const cache = new WeakMap(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2249 |
return { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2250 |
get(item, itemName) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2251 |
let boundItem = cache.get(item); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2252 |
if (!boundItem) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2253 |
boundItem = bind(item, itemName); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2254 |
cache.set(item, boundItem); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2255 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2256 |
return boundItem; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2257 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2258 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2259 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2260 |
|
18 | 2261 |
/** |
19 | 2262 |
* Creates a data store descriptor for the provided Redux store configuration containing |
18 | 2263 |
* properties describing reducer, actions, selectors, controls and resolvers. |
2264 |
* |
|
2265 |
* @example |
|
2266 |
* ```js |
|
2267 |
* import { createReduxStore } from '@wordpress/data'; |
|
2268 |
* |
|
2269 |
* const store = createReduxStore( 'demo', { |
|
2270 |
* reducer: ( state = 'OK' ) => state, |
|
2271 |
* selectors: { |
|
2272 |
* getValue: ( state ) => state, |
|
2273 |
* }, |
|
2274 |
* } ); |
|
2275 |
* ``` |
|
2276 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2277 |
* @template State |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2278 |
* @template {Record<string,import('../types').ActionCreator>} Actions |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2279 |
* @template Selectors |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2280 |
* @param {string} key Unique namespace identifier. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2281 |
* @param {ReduxStoreConfig<State,Actions,Selectors>} options Registered store options, with properties |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2282 |
* describing reducer, actions, selectors, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2283 |
* and resolvers. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2284 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2285 |
* @return {StoreDescriptor<ReduxStoreConfig<State,Actions,Selectors>>} Store Object. |
18 | 2286 |
*/ |
2287 |
function createReduxStore(key, options) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2288 |
const privateActions = {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2289 |
const privateSelectors = {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2290 |
const privateRegistrationFunctions = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2291 |
privateActions, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2292 |
registerPrivateActions: actions => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2293 |
Object.assign(privateActions, actions); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2294 |
}, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2295 |
privateSelectors, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2296 |
registerPrivateSelectors: selectors => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2297 |
Object.assign(privateSelectors, selectors); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2298 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2299 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2300 |
const storeDescriptor = { |
18 | 2301 |
name: key, |
2302 |
instantiate: registry => { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2303 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2304 |
* Stores listener functions registered with `subscribe()`. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2305 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2306 |
* When functions register to listen to store changes with |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2307 |
* `subscribe()` they get added here. Although Redux offers |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2308 |
* its own `subscribe()` function directly, by wrapping the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2309 |
* subscription in this store instance it's possible to |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2310 |
* optimize checking if the state has changed before calling |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2311 |
* each listener. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2312 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2313 |
* @type {Set<ListenerFunction>} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2314 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2315 |
const listeners = new Set(); |
18 | 2316 |
const reducer = options.reducer; |
2317 |
const thunkArgs = { |
|
2318 |
registry, |
|
2319 |
get dispatch() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2320 |
return thunkActions; |
18 | 2321 |
}, |
2322 |
get select() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2323 |
return thunkSelectors; |
18 | 2324 |
}, |
2325 |
get resolveSelect() { |
|
2326 |
return getResolveSelectors(); |
|
2327 |
} |
|
2328 |
}; |
|
2329 |
const store = instantiateReduxStore(key, options, registry, thunkArgs); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2330 |
// Expose the private registration functions on the store |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2331 |
// so they can be copied to a sub registry in registry.js. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2332 |
lock(store, privateRegistrationFunctions); |
18 | 2333 |
const resolversCache = createResolversCache(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2334 |
function bindAction(action) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2335 |
return (...args) => Promise.resolve(store.dispatch(action(...args))); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2336 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2337 |
const actions = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2338 |
...mapValues(actions_namespaceObject, bindAction), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2339 |
...mapValues(options.actions, bindAction) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2340 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2341 |
const boundPrivateActions = createBindingCache(bindAction); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2342 |
const allActions = new Proxy(() => {}, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2343 |
get: (target, prop) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2344 |
const privateAction = privateActions[prop]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2345 |
return privateAction ? boundPrivateActions.get(privateAction, prop) : actions[prop]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2346 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2347 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2348 |
const thunkActions = new Proxy(allActions, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2349 |
apply: (target, thisArg, [action]) => store.dispatch(action) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2350 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2351 |
lock(actions, allActions); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2352 |
const resolvers = options.resolvers ? mapResolvers(options.resolvers) : {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2353 |
function bindSelector(selector, selectorName) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2354 |
if (selector.isRegistrySelector) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2355 |
selector.registry = registry; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2356 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2357 |
const boundSelector = (...args) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2358 |
args = normalize(selector, args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2359 |
const state = store.__unstableOriginalGetState(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2360 |
// Before calling the selector, switch to the correct |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2361 |
// registry. |
18 | 2362 |
if (selector.isRegistrySelector) { |
2363 |
selector.registry = registry; |
|
2364 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2365 |
return selector(state.root, ...args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2366 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2367 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2368 |
// Expose normalization method on the bound selector |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2369 |
// in order that it can be called when fulfilling |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2370 |
// the resolver. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2371 |
boundSelector.__unstableNormalizeArgs = selector.__unstableNormalizeArgs; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2372 |
const resolver = resolvers[selectorName]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2373 |
if (!resolver) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2374 |
boundSelector.hasResolver = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2375 |
return boundSelector; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2376 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2377 |
return mapSelectorWithResolver(boundSelector, selectorName, resolver, store, resolversCache); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2378 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2379 |
function bindMetadataSelector(metaDataSelector) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2380 |
const boundSelector = (...args) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2381 |
const state = store.__unstableOriginalGetState(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2382 |
const originalSelectorName = args && args[0]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2383 |
const originalSelectorArgs = args && args[1]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2384 |
const targetSelector = options?.selectors?.[originalSelectorName]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2385 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2386 |
// Normalize the arguments passed to the target selector. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2387 |
if (originalSelectorName && targetSelector) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2388 |
args[1] = normalize(targetSelector, originalSelectorArgs); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2389 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2390 |
return metaDataSelector(state.metadata, ...args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2391 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2392 |
boundSelector.hasResolver = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2393 |
return boundSelector; |
16 | 2394 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2395 |
const selectors = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2396 |
...mapValues(selectors_namespaceObject, bindMetadataSelector), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2397 |
...mapValues(options.selectors, bindSelector) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2398 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2399 |
const boundPrivateSelectors = createBindingCache(bindSelector); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2400 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2401 |
// Pre-bind the private selectors that have been registered by the time of |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2402 |
// instantiation, so that registry selectors are bound to the registry. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2403 |
for (const [selectorName, selector] of Object.entries(privateSelectors)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2404 |
boundPrivateSelectors.get(selector, selectorName); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2405 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2406 |
const allSelectors = new Proxy(() => {}, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2407 |
get: (target, prop) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2408 |
const privateSelector = privateSelectors[prop]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2409 |
return privateSelector ? boundPrivateSelectors.get(privateSelector, prop) : selectors[prop]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2410 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2411 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2412 |
const thunkSelectors = new Proxy(allSelectors, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2413 |
apply: (target, thisArg, [selector]) => selector(store.__unstableOriginalGetState()) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2414 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2415 |
lock(selectors, allSelectors); |
18 | 2416 |
const resolveSelectors = mapResolveSelectors(selectors, store); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2417 |
const suspendSelectors = mapSuspendSelectors(selectors, store); |
18 | 2418 |
const getSelectors = () => selectors; |
2419 |
const getActions = () => actions; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2420 |
const getResolveSelectors = () => resolveSelectors; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2421 |
const getSuspendSelectors = () => suspendSelectors; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2422 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2423 |
// We have some modules monkey-patching the store object |
18 | 2424 |
// It's wrong to do so but until we refactor all of our effects to controls |
2425 |
// We need to keep the same "store" instance here. |
|
2426 |
store.__unstableOriginalGetState = store.getState; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2427 |
store.getState = () => store.__unstableOriginalGetState().root; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2428 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2429 |
// Customize subscribe behavior to call listeners only on effective change, |
18 | 2430 |
// not on every dispatch. |
2431 |
const subscribe = store && (listener => { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2432 |
listeners.add(listener); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2433 |
return () => listeners.delete(listener); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2434 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2435 |
let lastState = store.__unstableOriginalGetState(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2436 |
store.subscribe(() => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2437 |
const state = store.__unstableOriginalGetState(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2438 |
const hasChanged = state !== lastState; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2439 |
lastState = state; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2440 |
if (hasChanged) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2441 |
for (const listener of listeners) { |
18 | 2442 |
listener(); |
2443 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2444 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2445 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2446 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2447 |
// This can be simplified to just { subscribe, getSelectors, getActions } |
18 | 2448 |
// Once we remove the use function. |
2449 |
return { |
|
2450 |
reducer, |
|
2451 |
store, |
|
2452 |
actions, |
|
2453 |
selectors, |
|
2454 |
resolvers, |
|
2455 |
getSelectors, |
|
2456 |
getResolveSelectors, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2457 |
getSuspendSelectors, |
18 | 2458 |
getActions, |
2459 |
subscribe |
|
2460 |
}; |
|
2461 |
} |
|
16 | 2462 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2463 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2464 |
// Expose the private registration functions on the store |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2465 |
// descriptor. That's a natural choice since that's where the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2466 |
// public actions and selectors are stored . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2467 |
lock(storeDescriptor, privateRegistrationFunctions); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2468 |
return storeDescriptor; |
16 | 2469 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2470 |
|
16 | 2471 |
/** |
2472 |
* Creates a redux store for a namespace. |
|
2473 |
* |
|
19 | 2474 |
* @param {string} key Unique namespace identifier. |
2475 |
* @param {Object} options Registered store options, with properties |
|
2476 |
* describing reducer, actions, selectors, |
|
2477 |
* and resolvers. |
|
2478 |
* @param {DataRegistry} registry Registry reference. |
|
2479 |
* @param {Object} thunkArgs Argument object for the thunk middleware. |
|
16 | 2480 |
* @return {Object} Newly created redux store. |
2481 |
*/ |
|
18 | 2482 |
function instantiateReduxStore(key, options, registry, thunkArgs) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2483 |
const controls = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2484 |
...options.controls, |
18 | 2485 |
...builtinControls |
2486 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2487 |
const normalizedControls = mapValues(controls, control => control.isRegistryControl ? control(registry) : control); |
19 | 2488 |
const middlewares = [resolvers_cache_middleware(registry, key), promise_middleware, external_wp_reduxRoutine_default()(normalizedControls), createThunkMiddleware(thunkArgs)]; |
18 | 2489 |
const enhancers = [applyMiddleware(...middlewares)]; |
16 | 2490 |
if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) { |
2491 |
enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION__({ |
|
2492 |
name: key, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2493 |
instanceId: key, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2494 |
serialize: { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2495 |
replacer: devToolsReplacer |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2496 |
} |
16 | 2497 |
})); |
2498 |
} |
|
18 | 2499 |
const { |
2500 |
reducer, |
|
2501 |
initialState |
|
2502 |
} = options; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2503 |
const enhancedReducer = combine_reducers_combineReducers({ |
16 | 2504 |
metadata: metadata_reducer, |
2505 |
root: reducer |
|
2506 |
}); |
|
19 | 2507 |
return createStore(enhancedReducer, { |
16 | 2508 |
root: initialState |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2509 |
}, (0,external_wp_compose_namespaceObject.compose)(enhancers)); |
16 | 2510 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2511 |
|
18 | 2512 |
/** |
2513 |
* Maps selectors to functions that return a resolution promise for them |
|
2514 |
* |
|
2515 |
* @param {Object} selectors Selectors to map. |
|
2516 |
* @param {Object} store The redux store the selectors select from. |
|
19 | 2517 |
* |
2518 |
* @return {Object} Selectors mapped to their resolution functions. |
|
18 | 2519 |
*/ |
2520 |
function mapResolveSelectors(selectors, store) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2521 |
const { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2522 |
getIsResolving, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2523 |
hasStartedResolution, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2524 |
hasFinishedResolution, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2525 |
hasResolutionFailed, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2526 |
isResolving, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2527 |
getCachedResolvers, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2528 |
getResolutionState, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2529 |
getResolutionError, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2530 |
hasResolvingSelectors, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2531 |
countSelectorsByStatus, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2532 |
...storeSelectors |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2533 |
} = selectors; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2534 |
return mapValues(storeSelectors, (selector, selectorName) => { |
19 | 2535 |
// If the selector doesn't have a resolver, just convert the return value |
2536 |
// (including exceptions) to a Promise, no additional extra behavior is needed. |
|
2537 |
if (!selector.hasResolver) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2538 |
return async (...args) => selector.apply(null, args); |
18 | 2539 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2540 |
return (...args) => { |
19 | 2541 |
return new Promise((resolve, reject) => { |
2542 |
const hasFinished = () => selectors.hasFinishedResolution(selectorName, args); |
|
2543 |
const finalize = result => { |
|
2544 |
const hasFailed = selectors.hasResolutionFailed(selectorName, args); |
|
2545 |
if (hasFailed) { |
|
2546 |
const error = selectors.getResolutionError(selectorName, args); |
|
2547 |
reject(error); |
|
2548 |
} else { |
|
2549 |
resolve(result); |
|
2550 |
} |
|
2551 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2552 |
const getResult = () => selector.apply(null, args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2553 |
// Trigger the selector (to trigger the resolver) |
19 | 2554 |
const result = getResult(); |
2555 |
if (hasFinished()) { |
|
2556 |
return finalize(result); |
|
2557 |
} |
|
2558 |
const unsubscribe = store.subscribe(() => { |
|
2559 |
if (hasFinished()) { |
|
2560 |
unsubscribe(); |
|
2561 |
finalize(getResult()); |
|
2562 |
} |
|
2563 |
}); |
|
2564 |
}); |
|
2565 |
}; |
|
2566 |
}); |
|
16 | 2567 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2568 |
|
16 | 2569 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2570 |
* Maps selectors to functions that throw a suspense promise if not yet resolved. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2571 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2572 |
* @param {Object} selectors Selectors to map. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2573 |
* @param {Object} store The redux store the selectors select from. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2574 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2575 |
* @return {Object} Selectors mapped to their suspense functions. |
16 | 2576 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2577 |
function mapSuspendSelectors(selectors, store) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2578 |
return mapValues(selectors, (selector, selectorName) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2579 |
// Selector without a resolver doesn't have any extra suspense behavior. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2580 |
if (!selector.hasResolver) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2581 |
return selector; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2582 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2583 |
return (...args) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2584 |
const result = selector.apply(null, args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2585 |
if (selectors.hasFinishedResolution(selectorName, args)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2586 |
if (selectors.hasResolutionFailed(selectorName, args)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2587 |
throw selectors.getResolutionError(selectorName, args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2588 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2589 |
return result; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2590 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2591 |
throw new Promise(resolve => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2592 |
const unsubscribe = store.subscribe(() => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2593 |
if (selectors.hasFinishedResolution(selectorName, args)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2594 |
resolve(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2595 |
unsubscribe(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2596 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2597 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2598 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2599 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2600 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2601 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2602 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2603 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2604 |
* Convert resolvers to a normalized form, an object with `fulfill` method and |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2605 |
* optional methods like `isFulfilled`. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2606 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2607 |
* @param {Object} resolvers Resolver to convert |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2608 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2609 |
function mapResolvers(resolvers) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2610 |
return mapValues(resolvers, resolver => { |
18 | 2611 |
if (resolver.fulfill) { |
2612 |
return resolver; |
|
2613 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2614 |
return { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2615 |
...resolver, |
19 | 2616 |
// Copy the enumerable properties of the resolver function. |
2617 |
fulfill: resolver // Add the fulfill method. |
|
18 | 2618 |
}; |
16 | 2619 |
}); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2620 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2621 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2622 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2623 |
* Returns a selector with a matched resolver. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2624 |
* Resolvers are side effects invoked once per argument set of a given selector call, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2625 |
* used in ensuring that the data needs for the selector are satisfied. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2626 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2627 |
* @param {Object} selector The selector function to be bound. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2628 |
* @param {string} selectorName The selector name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2629 |
* @param {Object} resolver Resolver to call. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2630 |
* @param {Object} store The redux store to which the resolvers should be mapped. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2631 |
* @param {Object} resolversCache Resolvers Cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2632 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2633 |
function mapSelectorWithResolver(selector, selectorName, resolver, store, resolversCache) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2634 |
function fulfillSelector(args) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2635 |
const state = store.getState(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2636 |
if (resolversCache.isRunning(selectorName, args) || typeof resolver.isFulfilled === 'function' && resolver.isFulfilled(state, ...args)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2637 |
return; |
16 | 2638 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2639 |
const { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2640 |
metadata |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2641 |
} = store.__unstableOriginalGetState(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2642 |
if (hasStartedResolution(metadata, selectorName, args)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2643 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2644 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2645 |
resolversCache.markAsRunning(selectorName, args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2646 |
setTimeout(async () => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2647 |
resolversCache.clear(selectorName, args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2648 |
store.dispatch(startResolution(selectorName, args)); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2649 |
try { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2650 |
const action = resolver.fulfill(...args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2651 |
if (action) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2652 |
await store.dispatch(action); |
18 | 2653 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2654 |
store.dispatch(finishResolution(selectorName, args)); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2655 |
} catch (error) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2656 |
store.dispatch(failResolution(selectorName, args, error)); |
16 | 2657 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2658 |
}, 0); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2659 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2660 |
const selectorResolver = (...args) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2661 |
args = normalize(selector, args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2662 |
fulfillSelector(args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2663 |
return selector(...args); |
16 | 2664 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2665 |
selectorResolver.hasResolver = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2666 |
return selectorResolver; |
16 | 2667 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2668 |
|
16 | 2669 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2670 |
* Applies selector's normalization function to the given arguments |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2671 |
* if it exists. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2672 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2673 |
* @param {Object} selector The selector potentially with a normalization method property. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2674 |
* @param {Array} args selector arguments to normalize. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2675 |
* @return {Array} Potentially normalized arguments. |
16 | 2676 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2677 |
function normalize(selector, args) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2678 |
if (selector.__unstableNormalizeArgs && typeof selector.__unstableNormalizeArgs === 'function' && args?.length) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2679 |
return selector.__unstableNormalizeArgs(args); |
18 | 2680 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2681 |
return args; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2682 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2683 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2684 |
;// ./node_modules/@wordpress/data/build-module/store/index.js |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2685 |
const coreDataStore = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2686 |
name: 'core/data', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2687 |
instantiate(registry) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2688 |
const getCoreDataSelector = selectorName => (key, ...args) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2689 |
return registry.select(key)[selectorName](...args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2690 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2691 |
const getCoreDataAction = actionName => (key, ...args) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2692 |
return registry.dispatch(key)[actionName](...args); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2693 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2694 |
return { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2695 |
getSelectors() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2696 |
return Object.fromEntries(['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'].map(selectorName => [selectorName, getCoreDataSelector(selectorName)])); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2697 |
}, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2698 |
getActions() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2699 |
return Object.fromEntries(['startResolution', 'finishResolution', 'invalidateResolution', 'invalidateResolutionForStore', 'invalidateResolutionForStoreSelector'].map(actionName => [actionName, getCoreDataAction(actionName)])); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2700 |
}, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2701 |
subscribe() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2702 |
// There's no reasons to trigger any listener when we subscribe to this store |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2703 |
// because there's no state stored in this store that need to retrigger selectors |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2704 |
// if a change happens, the corresponding store where the tracking stated live |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2705 |
// would have already triggered a "subscribe" call. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2706 |
return () => () => {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2707 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2708 |
}; |
19 | 2709 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2710 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2711 |
/* harmony default export */ const store = (coreDataStore); |
16 | 2712 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2713 |
;// ./node_modules/@wordpress/data/build-module/utils/emitter.js |
19 | 2714 |
/** |
2715 |
* Create an event emitter. |
|
2716 |
* |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2717 |
* @return The event emitter. |
19 | 2718 |
*/ |
2719 |
function createEmitter() { |
|
2720 |
let isPaused = false; |
|
2721 |
let isPending = false; |
|
2722 |
const listeners = new Set(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2723 |
const notifyListeners = () => |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2724 |
// We use Array.from to clone the listeners Set |
19 | 2725 |
// This ensures that we don't run a listener |
2726 |
// that was added as a response to another listener. |
|
2727 |
Array.from(listeners).forEach(listener => listener()); |
|
16 | 2728 |
return { |
19 | 2729 |
get isPaused() { |
2730 |
return isPaused; |
|
2731 |
}, |
|
2732 |
subscribe(listener) { |
|
2733 |
listeners.add(listener); |
|
2734 |
return () => listeners.delete(listener); |
|
2735 |
}, |
|
2736 |
pause() { |
|
2737 |
isPaused = true; |
|
16 | 2738 |
}, |
19 | 2739 |
resume() { |
2740 |
isPaused = false; |
|
2741 |
if (isPending) { |
|
2742 |
isPending = false; |
|
2743 |
notifyListeners(); |
|
2744 |
} |
|
16 | 2745 |
}, |
19 | 2746 |
emit() { |
2747 |
if (isPaused) { |
|
2748 |
isPending = true; |
|
2749 |
return; |
|
2750 |
} |
|
2751 |
notifyListeners(); |
|
16 | 2752 |
} |
2753 |
}; |
|
2754 |
} |
|
2755 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2756 |
;// ./node_modules/@wordpress/data/build-module/registry.js |
16 | 2757 |
/** |
19 | 2758 |
* WordPress dependencies |
2759 |
*/ |
|
2760 |
||
2761 |
||
2762 |
/** |
|
16 | 2763 |
* Internal dependencies |
2764 |
*/ |
|
2765 |
||
2766 |
||
2767 |
||
19 | 2768 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2769 |
|
19 | 2770 |
/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */ |
18 | 2771 |
|
16 | 2772 |
/** |
2773 |
* @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations. |
|
2774 |
* |
|
2775 |
* @property {Function} registerGenericStore Given a namespace key and settings |
|
2776 |
* object, registers a new generic |
|
2777 |
* store. |
|
2778 |
* @property {Function} registerStore Given a namespace key and settings |
|
2779 |
* object, registers a new namespace |
|
2780 |
* store. |
|
2781 |
* @property {Function} subscribe Given a function callback, invokes |
|
2782 |
* the callback on any change to state |
|
2783 |
* within any registered store. |
|
2784 |
* @property {Function} select Given a namespace key, returns an |
|
2785 |
* object of the store's registered |
|
2786 |
* selectors. |
|
2787 |
* @property {Function} dispatch Given a namespace key, returns an |
|
2788 |
* object of the store's registered |
|
2789 |
* action dispatchers. |
|
2790 |
*/ |
|
2791 |
||
2792 |
/** |
|
2793 |
* @typedef {Object} WPDataPlugin An object of registry function overrides. |
|
2794 |
* |
|
2795 |
* @property {Function} registerStore registers store. |
|
2796 |
*/ |
|
2797 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2798 |
function getStoreName(storeNameOrDescriptor) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2799 |
return typeof storeNameOrDescriptor === 'string' ? storeNameOrDescriptor : storeNameOrDescriptor.name; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2800 |
} |
16 | 2801 |
/** |
2802 |
* Creates a new store registry, given an optional object of initial store |
|
2803 |
* configurations. |
|
2804 |
* |
|
2805 |
* @param {Object} storeConfigs Initial store configurations. |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
2806 |
* @param {?Object} parent Parent registry. |
16 | 2807 |
* |
2808 |
* @return {WPDataRegistry} Data registry. |
|
2809 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2810 |
function createRegistry(storeConfigs = {}, parent = null) { |
18 | 2811 |
const stores = {}; |
19 | 2812 |
const emitter = createEmitter(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2813 |
let listeningStores = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2814 |
|
16 | 2815 |
/** |
2816 |
* Global listener called for each store's update. |
|
2817 |
*/ |
|
2818 |
function globalListener() { |
|
19 | 2819 |
emitter.emit(); |
16 | 2820 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2821 |
|
16 | 2822 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2823 |
* Subscribe to changes to any data, either in all stores in registry, or |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2824 |
* in one specific store. |
16 | 2825 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2826 |
* @param {Function} listener Listener function. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2827 |
* @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name. |
16 | 2828 |
* |
19 | 2829 |
* @return {Function} Unsubscribe function. |
16 | 2830 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2831 |
const subscribe = (listener, storeNameOrDescriptor) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2832 |
// subscribe to all stores |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2833 |
if (!storeNameOrDescriptor) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2834 |
return emitter.subscribe(listener); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2835 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2836 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2837 |
// subscribe to one store |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2838 |
const storeName = getStoreName(storeNameOrDescriptor); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2839 |
const store = stores[storeName]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2840 |
if (store) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2841 |
return store.subscribe(listener); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2842 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2843 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2844 |
// Trying to access a store that hasn't been registered, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2845 |
// this is a pattern rarely used but seen in some places. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2846 |
// We fallback to global `subscribe` here for backward-compatibility for now. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2847 |
// See https://github.com/WordPress/gutenberg/pull/27466 for more info. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2848 |
if (!parent) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2849 |
return emitter.subscribe(listener); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2850 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2851 |
return parent.subscribe(listener, storeNameOrDescriptor); |
16 | 2852 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2853 |
|
16 | 2854 |
/** |
2855 |
* Calls a selector given the current state and extra arguments. |
|
2856 |
* |
|
19 | 2857 |
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store |
2858 |
* or the store descriptor. |
|
16 | 2859 |
* |
2860 |
* @return {*} The selector's returned value. |
|
2861 |
*/ |
|
19 | 2862 |
function select(storeNameOrDescriptor) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2863 |
const storeName = getStoreName(storeNameOrDescriptor); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2864 |
listeningStores?.add(storeName); |
18 | 2865 |
const store = stores[storeName]; |
16 | 2866 |
if (store) { |
2867 |
return store.getSelectors(); |
|
2868 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2869 |
return parent?.select(storeName); |
16 | 2870 |
} |
19 | 2871 |
function __unstableMarkListeningStores(callback, ref) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2872 |
listeningStores = new Set(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2873 |
try { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2874 |
return callback.call(this); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2875 |
} finally { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2876 |
ref.current = Array.from(listeningStores); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2877 |
listeningStores = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2878 |
} |
18 | 2879 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2880 |
|
16 | 2881 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2882 |
* Given a store descriptor, returns an object containing the store's selectors pre-bound to |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2883 |
* state so that you only need to supply additional arguments, and modified so that they return |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2884 |
* promises that resolve to their eventual values, after any resolvers have ran. |
16 | 2885 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2886 |
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2887 |
* convention of passing the store name is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2888 |
* also supported. |
16 | 2889 |
* |
2890 |
* @return {Object} Each key of the object matches the name of a selector. |
|
2891 |
*/ |
|
19 | 2892 |
function resolveSelect(storeNameOrDescriptor) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2893 |
const storeName = getStoreName(storeNameOrDescriptor); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2894 |
listeningStores?.add(storeName); |
18 | 2895 |
const store = stores[storeName]; |
2896 |
if (store) { |
|
2897 |
return store.getResolveSelectors(); |
|
2898 |
} |
|
2899 |
return parent && parent.resolveSelect(storeName); |
|
16 | 2900 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2901 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2902 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2903 |
* Given a store descriptor, returns an object containing the store's selectors pre-bound to |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2904 |
* state so that you only need to supply additional arguments, and modified so that they throw |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2905 |
* promises in case the selector is not resolved yet. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2906 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2907 |
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2908 |
* convention of passing the store name is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2909 |
* also supported. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2910 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2911 |
* @return {Object} Object containing the store's suspense-wrapped selectors. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2912 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2913 |
function suspendSelect(storeNameOrDescriptor) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2914 |
const storeName = getStoreName(storeNameOrDescriptor); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2915 |
listeningStores?.add(storeName); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2916 |
const store = stores[storeName]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2917 |
if (store) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2918 |
return store.getSuspendSelectors(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2919 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2920 |
return parent && parent.suspendSelect(storeName); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2921 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2922 |
|
16 | 2923 |
/** |
2924 |
* Returns the available actions for a part of the state. |
|
2925 |
* |
|
19 | 2926 |
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store |
2927 |
* or the store descriptor. |
|
16 | 2928 |
* |
2929 |
* @return {*} The action's returned value. |
|
2930 |
*/ |
|
19 | 2931 |
function dispatch(storeNameOrDescriptor) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2932 |
const storeName = getStoreName(storeNameOrDescriptor); |
18 | 2933 |
const store = stores[storeName]; |
16 | 2934 |
if (store) { |
2935 |
return store.getActions(); |
|
2936 |
} |
|
18 | 2937 |
return parent && parent.dispatch(storeName); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2938 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2939 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2940 |
// |
16 | 2941 |
// Deprecated |
2942 |
// TODO: Remove this after `use()` is removed. |
|
2943 |
function withPlugins(attributes) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2944 |
return Object.fromEntries(Object.entries(attributes).map(([key, attribute]) => { |
16 | 2945 |
if (typeof attribute !== 'function') { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2946 |
return [key, attribute]; |
16 | 2947 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2948 |
return [key, function () { |
16 | 2949 |
return registry[key].apply(null, arguments); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2950 |
}]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2951 |
})); |
16 | 2952 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2953 |
|
16 | 2954 |
/** |
19 | 2955 |
* Registers a store instance. |
16 | 2956 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2957 |
* @param {string} name Store registry name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2958 |
* @param {Function} createStore Function that creates a store object (getSelectors, getActions, subscribe). |
16 | 2959 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2960 |
function registerStoreInstance(name, createStore) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2961 |
if (stores[name]) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2962 |
// eslint-disable-next-line no-console |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2963 |
console.error('Store "' + name + '" is already registered.'); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2964 |
return stores[name]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2965 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2966 |
const store = createStore(); |
19 | 2967 |
if (typeof store.getSelectors !== 'function') { |
2968 |
throw new TypeError('store.getSelectors must be a function'); |
|
2969 |
} |
|
2970 |
if (typeof store.getActions !== 'function') { |
|
2971 |
throw new TypeError('store.getActions must be a function'); |
|
16 | 2972 |
} |
19 | 2973 |
if (typeof store.subscribe !== 'function') { |
2974 |
throw new TypeError('store.subscribe must be a function'); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2975 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2976 |
// The emitter is used to keep track of active listeners when the registry |
19 | 2977 |
// get paused, that way, when resumed we should be able to call all these |
2978 |
// pending listeners. |
|
2979 |
store.emitter = createEmitter(); |
|
2980 |
const currentSubscribe = store.subscribe; |
|
2981 |
store.subscribe = listener => { |
|
2982 |
const unsubscribeFromEmitter = store.emitter.subscribe(listener); |
|
2983 |
const unsubscribeFromStore = currentSubscribe(() => { |
|
2984 |
if (store.emitter.isPaused) { |
|
2985 |
store.emitter.emit(); |
|
2986 |
return; |
|
2987 |
} |
|
2988 |
listener(); |
|
2989 |
}); |
|
2990 |
return () => { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2991 |
unsubscribeFromStore?.(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2992 |
unsubscribeFromEmitter?.(); |
19 | 2993 |
}; |
2994 |
}; |
|
2995 |
stores[name] = store; |
|
2996 |
store.subscribe(globalListener); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2997 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2998 |
// Copy private actions and selectors from the parent store. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2999 |
if (parent) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3000 |
try { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3001 |
unlock(store.store).registerPrivateActions(unlock(parent).privateActionsOf(name)); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3002 |
unlock(store.store).registerPrivateSelectors(unlock(parent).privateSelectorsOf(name)); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3003 |
} catch (e) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3004 |
// unlock() throws if store.store was not locked. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3005 |
// The error indicates there's nothing to do here so let's |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3006 |
// ignore it. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3007 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3008 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3009 |
return store; |
16 | 3010 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3011 |
|
18 | 3012 |
/** |
19 | 3013 |
* Registers a new store given a store descriptor. |
18 | 3014 |
* |
19 | 3015 |
* @param {StoreDescriptor} store Store descriptor. |
18 | 3016 |
*/ |
3017 |
function register(store) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3018 |
registerStoreInstance(store.name, () => store.instantiate(registry)); |
19 | 3019 |
} |
3020 |
function registerGenericStore(name, store) { |
|
3021 |
external_wp_deprecated_default()('wp.data.registerGenericStore', { |
|
3022 |
since: '5.9', |
|
3023 |
alternative: 'wp.data.register( storeDescriptor )' |
|
3024 |
}); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3025 |
registerStoreInstance(name, () => store); |
19 | 3026 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3027 |
|
19 | 3028 |
/** |
3029 |
* Registers a standard `@wordpress/data` store. |
|
3030 |
* |
|
3031 |
* @param {string} storeName Unique namespace identifier. |
|
3032 |
* @param {Object} options Store description (reducer, actions, selectors, resolvers). |
|
3033 |
* |
|
3034 |
* @return {Object} Registered store object. |
|
3035 |
*/ |
|
3036 |
function registerStore(storeName, options) { |
|
3037 |
if (!options.reducer) { |
|
3038 |
throw new TypeError('Must specify store reducer'); |
|
3039 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3040 |
const store = registerStoreInstance(storeName, () => createReduxStore(storeName, options).instantiate(registry)); |
19 | 3041 |
return store.store; |
18 | 3042 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3043 |
function batch(callback) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3044 |
// If we're already batching, just call the callback. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3045 |
if (emitter.isPaused) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3046 |
callback(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3047 |
return; |
18 | 3048 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3049 |
emitter.pause(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3050 |
Object.values(stores).forEach(store => store.emitter.pause()); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3051 |
try { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3052 |
callback(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3053 |
} finally { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3054 |
emitter.resume(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3055 |
Object.values(stores).forEach(store => store.emitter.resume()); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3056 |
} |
19 | 3057 |
} |
18 | 3058 |
let registry = { |
19 | 3059 |
batch, |
18 | 3060 |
stores, |
16 | 3061 |
namespaces: stores, |
3062 |
// TODO: Deprecate/remove this. |
|
18 | 3063 |
subscribe, |
3064 |
select, |
|
3065 |
resolveSelect, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3066 |
suspendSelect, |
18 | 3067 |
dispatch, |
3068 |
use, |
|
3069 |
register, |
|
19 | 3070 |
registerGenericStore, |
3071 |
registerStore, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3072 |
__unstableMarkListeningStores |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3073 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3074 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3075 |
// |
16 | 3076 |
// TODO: |
3077 |
// This function will be deprecated as soon as it is no longer internally referenced. |
|
3078 |
function use(plugin, options) { |
|
19 | 3079 |
if (!plugin) { |
3080 |
return; |
|
3081 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3082 |
registry = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3083 |
...registry, |
18 | 3084 |
...plugin(registry, options) |
3085 |
}; |
|
16 | 3086 |
return registry; |
3087 |
} |
|
19 | 3088 |
registry.register(store); |
3089 |
for (const [name, config] of Object.entries(storeConfigs)) { |
|
3090 |
registry.register(createReduxStore(name, config)); |
|
3091 |
} |
|
16 | 3092 |
if (parent) { |
3093 |
parent.subscribe(globalListener); |
|
3094 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3095 |
const registryWithPlugins = withPlugins(registry); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3096 |
lock(registryWithPlugins, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3097 |
privateActionsOf: name => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3098 |
try { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3099 |
return unlock(stores[name].store).privateActions; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3100 |
} catch (e) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3101 |
// unlock() throws an error the store was not locked – this means |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3102 |
// there no private actions are available |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3103 |
return {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3104 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3105 |
}, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3106 |
privateSelectorsOf: name => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3107 |
try { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3108 |
return unlock(stores[name].store).privateSelectors; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3109 |
} catch (e) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3110 |
return {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3111 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3112 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3113 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3114 |
return registryWithPlugins; |
16 | 3115 |
} |
3116 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3117 |
;// ./node_modules/@wordpress/data/build-module/default-registry.js |
16 | 3118 |
/** |
3119 |
* Internal dependencies |
|
3120 |
*/ |
|
3121 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3122 |
/* harmony default export */ const default_registry = (createRegistry()); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3123 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3124 |
;// ./node_modules/is-plain-object/dist/is-plain-object.mjs |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3125 |
/*! |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3126 |
* is-plain-object <https://github.com/jonschlinkert/is-plain-object> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3127 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3128 |
* Copyright (c) 2014-2017, Jon Schlinkert. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3129 |
* Released under the MIT License. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3130 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3131 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3132 |
function is_plain_object_isObject(o) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3133 |
return Object.prototype.toString.call(o) === '[object Object]'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3134 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3135 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3136 |
function is_plain_object_isPlainObject(o) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3137 |
var ctor,prot; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3138 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3139 |
if (is_plain_object_isObject(o) === false) return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3140 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3141 |
// If has modified constructor |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3142 |
ctor = o.constructor; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3143 |
if (ctor === undefined) return true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3144 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3145 |
// If has modified prototype |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3146 |
prot = ctor.prototype; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3147 |
if (is_plain_object_isObject(prot) === false) return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3148 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3149 |
// If constructor does not have an Object-specific method |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3150 |
if (prot.hasOwnProperty('isPrototypeOf') === false) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3151 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3152 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3153 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3154 |
// Most likely a plain Object |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3155 |
return true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3156 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3157 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3158 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3159 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3160 |
// EXTERNAL MODULE: ./node_modules/deepmerge/dist/cjs.js |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3161 |
var cjs = __webpack_require__(66); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3162 |
var cjs_default = /*#__PURE__*/__webpack_require__.n(cjs); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3163 |
;// ./node_modules/@wordpress/data/build-module/plugins/persistence/storage/object.js |
18 | 3164 |
let objectStorage; |
3165 |
const storage = { |
|
3166 |
getItem(key) { |
|
16 | 3167 |
if (!objectStorage || !objectStorage[key]) { |
3168 |
return null; |
|
3169 |
} |
|
3170 |
return objectStorage[key]; |
|
3171 |
}, |
|
18 | 3172 |
setItem(key, value) { |
16 | 3173 |
if (!objectStorage) { |
18 | 3174 |
storage.clear(); |
16 | 3175 |
} |
3176 |
objectStorage[key] = String(value); |
|
3177 |
}, |
|
18 | 3178 |
clear() { |
16 | 3179 |
objectStorage = Object.create(null); |
3180 |
} |
|
3181 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3182 |
/* harmony default export */ const object = (storage); |
16 | 3183 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3184 |
;// ./node_modules/@wordpress/data/build-module/plugins/persistence/storage/default.js |
16 | 3185 |
/** |
3186 |
* Internal dependencies |
|
3187 |
*/ |
|
3188 |
||
18 | 3189 |
let default_storage; |
16 | 3190 |
try { |
3191 |
// Private Browsing in Safari 10 and earlier will throw an error when |
|
3192 |
// attempting to set into localStorage. The test here is intentional in |
|
3193 |
// causing a thrown error as condition for using fallback object storage. |
|
3194 |
default_storage = window.localStorage; |
|
3195 |
default_storage.setItem('__wpDataTestLocalStorage', ''); |
|
3196 |
default_storage.removeItem('__wpDataTestLocalStorage'); |
|
3197 |
} catch (error) { |
|
3198 |
default_storage = object; |
|
3199 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3200 |
/* harmony default export */ const storage_default = (default_storage); |
16 | 3201 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3202 |
;// ./node_modules/@wordpress/data/build-module/plugins/persistence/index.js |
16 | 3203 |
/** |
3204 |
* External dependencies |
|
3205 |
*/ |
|
3206 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3207 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3208 |
|
16 | 3209 |
/** |
3210 |
* Internal dependencies |
|
3211 |
*/ |
|
3212 |
||
3213 |
||
3214 |
||
3215 |
/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */ |
|
3216 |
||
3217 |
/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */ |
|
3218 |
||
3219 |
/** |
|
3220 |
* @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options. |
|
3221 |
* |
|
3222 |
* @property {Storage} storage Persistent storage implementation. This must |
|
3223 |
* at least implement `getItem` and `setItem` of |
|
3224 |
* the Web Storage API. |
|
3225 |
* @property {string} storageKey Key on which to set in persistent storage. |
|
3226 |
*/ |
|
3227 |
||
3228 |
/** |
|
3229 |
* Default plugin storage. |
|
3230 |
* |
|
3231 |
* @type {Storage} |
|
3232 |
*/ |
|
18 | 3233 |
const DEFAULT_STORAGE = storage_default; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3234 |
|
16 | 3235 |
/** |
3236 |
* Default plugin storage key. |
|
3237 |
* |
|
3238 |
* @type {string} |
|
3239 |
*/ |
|
18 | 3240 |
const DEFAULT_STORAGE_KEY = 'WP_DATA'; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3241 |
|
16 | 3242 |
/** |
3243 |
* Higher-order reducer which invokes the original reducer only if state is |
|
3244 |
* inequal from that of the action's `nextState` property, otherwise returning |
|
3245 |
* the original state reference. |
|
3246 |
* |
|
3247 |
* @param {Function} reducer Original reducer. |
|
3248 |
* |
|
3249 |
* @return {Function} Enhanced reducer. |
|
3250 |
*/ |
|
18 | 3251 |
const withLazySameState = reducer => (state, action) => { |
3252 |
if (action.nextState === state) { |
|
3253 |
return state; |
|
3254 |
} |
|
3255 |
return reducer(state, action); |
|
16 | 3256 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3257 |
|
16 | 3258 |
/** |
3259 |
* Creates a persistence interface, exposing getter and setter methods (`get` |
|
3260 |
* and `set` respectively). |
|
3261 |
* |
|
3262 |
* @param {WPDataPersistencePluginOptions} options Plugin options. |
|
3263 |
* |
|
3264 |
* @return {Object} Persistence interface. |
|
3265 |
*/ |
|
3266 |
function createPersistenceInterface(options) { |
|
18 | 3267 |
const { |
3268 |
storage = DEFAULT_STORAGE, |
|
3269 |
storageKey = DEFAULT_STORAGE_KEY |
|
3270 |
} = options; |
|
3271 |
let data; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3272 |
|
16 | 3273 |
/** |
3274 |
* Returns the persisted data as an object, defaulting to an empty object. |
|
3275 |
* |
|
3276 |
* @return {Object} Persisted data. |
|
3277 |
*/ |
|
3278 |
function getData() { |
|
3279 |
if (data === undefined) { |
|
3280 |
// If unset, getItem is expected to return null. Fall back to |
|
3281 |
// empty object. |
|
18 | 3282 |
const persisted = storage.getItem(storageKey); |
16 | 3283 |
if (persisted === null) { |
3284 |
data = {}; |
|
3285 |
} else { |
|
3286 |
try { |
|
3287 |
data = JSON.parse(persisted); |
|
3288 |
} catch (error) { |
|
3289 |
// Similarly, should any error be thrown during parse of |
|
3290 |
// the string (malformed JSON), fall back to empty object. |
|
3291 |
data = {}; |
|
3292 |
} |
|
3293 |
} |
|
3294 |
} |
|
3295 |
return data; |
|
3296 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3297 |
|
16 | 3298 |
/** |
3299 |
* Merges an updated reducer state into the persisted data. |
|
3300 |
* |
|
3301 |
* @param {string} key Key to update. |
|
3302 |
* @param {*} value Updated value. |
|
3303 |
*/ |
|
3304 |
function setData(key, value) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3305 |
data = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3306 |
...data, |
18 | 3307 |
[key]: value |
3308 |
}; |
|
16 | 3309 |
storage.setItem(storageKey, JSON.stringify(data)); |
3310 |
} |
|
3311 |
return { |
|
3312 |
get: getData, |
|
3313 |
set: setData |
|
3314 |
}; |
|
3315 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3316 |
|
16 | 3317 |
/** |
3318 |
* Data plugin to persist store state into a single storage key. |
|
3319 |
* |
|
3320 |
* @param {WPDataRegistry} registry Data registry. |
|
3321 |
* @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options. |
|
3322 |
* |
|
3323 |
* @return {WPDataPlugin} Data plugin. |
|
3324 |
*/ |
|
3325 |
function persistencePlugin(registry, pluginOptions) { |
|
18 | 3326 |
const persistence = createPersistenceInterface(pluginOptions); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3327 |
|
16 | 3328 |
/** |
3329 |
* Creates an enhanced store dispatch function, triggering the state of the |
|
18 | 3330 |
* given store name to be persisted when changed. |
16 | 3331 |
* |
18 | 3332 |
* @param {Function} getState Function which returns current state. |
3333 |
* @param {string} storeName Store name. |
|
3334 |
* @param {?Array<string>} keys Optional subset of keys to save. |
|
16 | 3335 |
* |
3336 |
* @return {Function} Enhanced dispatch function. |
|
3337 |
*/ |
|
18 | 3338 |
function createPersistOnChange(getState, storeName, keys) { |
3339 |
let getPersistedState; |
|
16 | 3340 |
if (Array.isArray(keys)) { |
3341 |
// Given keys, the persisted state should by produced as an object |
|
3342 |
// of the subset of keys. This implementation uses combineReducers |
|
3343 |
// to leverage its behavior of returning the same object when none |
|
3344 |
// of the property values changes. This allows a strict reference |
|
3345 |
// equality to bypass a persistence set on an unchanging state. |
|
18 | 3346 |
const reducers = keys.reduce((accumulator, key) => Object.assign(accumulator, { |
3347 |
[key]: (state, action) => action.nextState[key] |
|
3348 |
}), {}); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3349 |
getPersistedState = withLazySameState(build_module_combineReducers(reducers)); |
16 | 3350 |
} else { |
18 | 3351 |
getPersistedState = (state, action) => action.nextState; |
16 | 3352 |
} |
18 | 3353 |
let lastState = getPersistedState(undefined, { |
16 | 3354 |
nextState: getState() |
3355 |
}); |
|
18 | 3356 |
return () => { |
3357 |
const state = getPersistedState(lastState, { |
|
16 | 3358 |
nextState: getState() |
3359 |
}); |
|
3360 |
if (state !== lastState) { |
|
18 | 3361 |
persistence.set(storeName, state); |
16 | 3362 |
lastState = state; |
3363 |
} |
|
3364 |
}; |
|
3365 |
} |
|
3366 |
return { |
|
18 | 3367 |
registerStore(storeName, options) { |
16 | 3368 |
if (!options.persist) { |
18 | 3369 |
return registry.registerStore(storeName, options); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3370 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3371 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3372 |
// Load from persistence to use as initial state. |
18 | 3373 |
const persistedState = persistence.get()[storeName]; |
16 | 3374 |
if (persistedState !== undefined) { |
18 | 3375 |
let initialState = options.reducer(options.initialState, { |
16 | 3376 |
type: '@@WP/PERSISTENCE_RESTORE' |
3377 |
}); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3378 |
if (is_plain_object_isPlainObject(initialState) && is_plain_object_isPlainObject(persistedState)) { |
16 | 3379 |
// If state is an object, ensure that: |
3380 |
// - Other keys are left intact when persisting only a |
|
3381 |
// subset of keys. |
|
3382 |
// - New keys in what would otherwise be used as initial |
|
3383 |
// state are deeply merged as base for persisted value. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3384 |
initialState = cjs_default()(initialState, persistedState, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3385 |
isMergeableObject: is_plain_object_isPlainObject |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3386 |
}); |
16 | 3387 |
} else { |
3388 |
// If there is a mismatch in object-likeness of default |
|
3389 |
// initial or persisted state, defer to persisted value. |
|
3390 |
initialState = persistedState; |
|
3391 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3392 |
options = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3393 |
...options, |
18 | 3394 |
initialState |
3395 |
}; |
|
16 | 3396 |
} |
18 | 3397 |
const store = registry.registerStore(storeName, options); |
3398 |
store.subscribe(createPersistOnChange(store.getState, storeName, options.persist)); |
|
16 | 3399 |
return store; |
3400 |
} |
|
3401 |
}; |
|
3402 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3403 |
persistencePlugin.__unstableMigrate = () => {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3404 |
/* harmony default export */ const persistence = (persistencePlugin); |
19 | 3405 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3406 |
;// ./node_modules/@wordpress/data/build-module/plugins/index.js |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3407 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3408 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3409 |
;// external ["wp","priorityQueue"] |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3410 |
const external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"]; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3411 |
;// external ["wp","element"] |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3412 |
const external_wp_element_namespaceObject = window["wp"]["element"]; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3413 |
;// external ["wp","isShallowEqual"] |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3414 |
const external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"]; |
19 | 3415 |
var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3416 |
;// ./node_modules/@wordpress/data/build-module/components/registry-provider/context.js |
16 | 3417 |
/** |
3418 |
* WordPress dependencies |
|
3419 |
*/ |
|
3420 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3421 |
|
16 | 3422 |
/** |
3423 |
* Internal dependencies |
|
3424 |
*/ |
|
3425 |
||
19 | 3426 |
const Context = (0,external_wp_element_namespaceObject.createContext)(default_registry); |
18 | 3427 |
const { |
3428 |
Consumer, |
|
3429 |
Provider |
|
3430 |
} = Context; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3431 |
|
16 | 3432 |
/** |
3433 |
* A custom react Context consumer exposing the provided `registry` to |
|
3434 |
* children components. Used along with the RegistryProvider. |
|
3435 |
* |
|
3436 |
* You can read more about the react context api here: |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3437 |
* https://react.dev/learn/passing-data-deeply-with-context#step-3-provide-the-context |
16 | 3438 |
* |
3439 |
* @example |
|
3440 |
* ```js |
|
18 | 3441 |
* import { |
16 | 3442 |
* RegistryProvider, |
3443 |
* RegistryConsumer, |
|
3444 |
* createRegistry |
|
18 | 3445 |
* } from '@wordpress/data'; |
16 | 3446 |
* |
3447 |
* const registry = createRegistry( {} ); |
|
3448 |
* |
|
3449 |
* const App = ( { props } ) => { |
|
3450 |
* return <RegistryProvider value={ registry }> |
|
3451 |
* <div>Hello There</div> |
|
3452 |
* <RegistryConsumer> |
|
3453 |
* { ( registry ) => ( |
|
3454 |
* <ComponentUsingRegistry |
|
3455 |
* { ...props } |
|
3456 |
* registry={ registry } |
|
3457 |
* ) } |
|
3458 |
* </RegistryConsumer> |
|
3459 |
* </RegistryProvider> |
|
3460 |
* } |
|
3461 |
* ``` |
|
3462 |
*/ |
|
18 | 3463 |
const RegistryConsumer = Consumer; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3464 |
|
16 | 3465 |
/** |
3466 |
* A custom Context provider for exposing the provided `registry` to children |
|
3467 |
* components via a consumer. |
|
3468 |
* |
|
3469 |
* See <a name="#RegistryConsumer">RegistryConsumer</a> documentation for |
|
3470 |
* example. |
|
3471 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3472 |
/* harmony default export */ const context = (Provider); |
16 | 3473 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3474 |
;// ./node_modules/@wordpress/data/build-module/components/registry-provider/use-registry.js |
16 | 3475 |
/** |
3476 |
* WordPress dependencies |
|
3477 |
*/ |
|
3478 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3479 |
|
16 | 3480 |
/** |
3481 |
* Internal dependencies |
|
3482 |
*/ |
|
3483 |
||
3484 |
||
3485 |
/** |
|
3486 |
* A custom react hook exposing the registry context for use. |
|
3487 |
* |
|
3488 |
* This exposes the `registry` value provided via the |
|
3489 |
* <a href="#RegistryProvider">Registry Provider</a> to a component implementing |
|
3490 |
* this hook. |
|
3491 |
* |
|
3492 |
* It acts similarly to the `useContext` react hook. |
|
3493 |
* |
|
3494 |
* Note: Generally speaking, `useRegistry` is a low level hook that in most cases |
|
18 | 3495 |
* won't be needed for implementation. Most interactions with the `@wordpress/data` |
3496 |
* API can be performed via the `useSelect` hook, or the `withSelect` and |
|
16 | 3497 |
* `withDispatch` higher order components. |
3498 |
* |
|
3499 |
* @example |
|
3500 |
* ```js |
|
18 | 3501 |
* import { |
16 | 3502 |
* RegistryProvider, |
3503 |
* createRegistry, |
|
3504 |
* useRegistry, |
|
18 | 3505 |
* } from '@wordpress/data'; |
16 | 3506 |
* |
3507 |
* const registry = createRegistry( {} ); |
|
3508 |
* |
|
3509 |
* const SomeChildUsingRegistry = ( props ) => { |
|
19 | 3510 |
* const registry = useRegistry(); |
16 | 3511 |
* // ...logic implementing the registry in other react hooks. |
3512 |
* }; |
|
3513 |
* |
|
3514 |
* |
|
3515 |
* const ParentProvidingRegistry = ( props ) => { |
|
3516 |
* return <RegistryProvider value={ registry }> |
|
3517 |
* <SomeChildUsingRegistry { ...props } /> |
|
3518 |
* </RegistryProvider> |
|
3519 |
* }; |
|
3520 |
* ``` |
|
3521 |
* |
|
3522 |
* @return {Function} A custom react hook exposing the registry context value. |
|
3523 |
*/ |
|
3524 |
function useRegistry() { |
|
19 | 3525 |
return (0,external_wp_element_namespaceObject.useContext)(Context); |
16 | 3526 |
} |
3527 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3528 |
;// ./node_modules/@wordpress/data/build-module/components/async-mode-provider/context.js |
16 | 3529 |
/** |
3530 |
* WordPress dependencies |
|
3531 |
*/ |
|
3532 |
||
19 | 3533 |
const context_Context = (0,external_wp_element_namespaceObject.createContext)(false); |
18 | 3534 |
const { |
3535 |
Consumer: context_Consumer, |
|
3536 |
Provider: context_Provider |
|
3537 |
} = context_Context; |
|
19 | 3538 |
const AsyncModeConsumer = (/* unused pure expression or super */ null && (context_Consumer)); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3539 |
|
16 | 3540 |
/** |
3541 |
* Context Provider Component used to switch the data module component rerendering |
|
3542 |
* between Sync and Async modes. |
|
3543 |
* |
|
3544 |
* @example |
|
3545 |
* |
|
3546 |
* ```js |
|
3547 |
* import { useSelect, AsyncModeProvider } from '@wordpress/data'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3548 |
* import { store as blockEditorStore } from '@wordpress/block-editor'; |
16 | 3549 |
* |
3550 |
* function BlockCount() { |
|
3551 |
* const count = useSelect( ( select ) => { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3552 |
* return select( blockEditorStore ).getBlockCount() |
16 | 3553 |
* }, [] ); |
3554 |
* |
|
3555 |
* return count; |
|
3556 |
* } |
|
3557 |
* |
|
3558 |
* function App() { |
|
3559 |
* return ( |
|
3560 |
* <AsyncModeProvider value={ true }> |
|
3561 |
* <BlockCount /> |
|
3562 |
* </AsyncModeProvider> |
|
3563 |
* ); |
|
3564 |
* } |
|
3565 |
* ``` |
|
3566 |
* |
|
3567 |
* In this example, the BlockCount component is rerendered asynchronously. |
|
3568 |
* It means if a more critical task is being performed (like typing in an input), |
|
3569 |
* the rerendering is delayed until the browser becomes IDLE. |
|
3570 |
* It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior. |
|
3571 |
* |
|
19 | 3572 |
* @param {boolean} props.value Enable Async Mode. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3573 |
* @return {Component} The component to be rendered. |
16 | 3574 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3575 |
/* harmony default export */ const async_mode_provider_context = (context_Provider); |
16 | 3576 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3577 |
;// ./node_modules/@wordpress/data/build-module/components/async-mode-provider/use-async-mode.js |
16 | 3578 |
/** |
3579 |
* WordPress dependencies |
|
3580 |
*/ |
|
3581 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3582 |
|
16 | 3583 |
/** |
3584 |
* Internal dependencies |
|
3585 |
*/ |
|
3586 |
||
3587 |
function useAsyncMode() { |
|
19 | 3588 |
return (0,external_wp_element_namespaceObject.useContext)(context_Context); |
16 | 3589 |
} |
3590 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3591 |
;// ./node_modules/@wordpress/data/build-module/components/use-select/index.js |
16 | 3592 |
/** |
3593 |
* WordPress dependencies |
|
3594 |
*/ |
|
3595 |
||
3596 |
||
3597 |
||
3598 |
||
3599 |
/** |
|
3600 |
* Internal dependencies |
|
3601 |
*/ |
|
3602 |
||
3603 |
||
19 | 3604 |
const renderQueue = (0,external_wp_priorityQueue_namespaceObject.createQueue)(); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3605 |
function warnOnUnstableReference(a, b) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3606 |
if (!a || !b) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3607 |
return; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3608 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3609 |
const keys = typeof a === 'object' && typeof b === 'object' ? Object.keys(a).filter(k => a[k] !== b[k]) : []; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3610 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3611 |
// eslint-disable-next-line no-console |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3612 |
console.warn('The `useSelect` hook returns different values when called with the same state and parameters.\n' + 'This can lead to unnecessary re-renders and performance issues if not fixed.\n\n' + 'Non-equal value keys: %s\n\n', keys.join(', ')); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3613 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3614 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3615 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3616 |
* @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3617 |
* @template {import('../../types').AnyConfig} C |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3618 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3619 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3620 |
* @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3621 |
* @template State |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3622 |
* @template {Record<string,import('../../types').ActionCreator>} Actions |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3623 |
* @template Selectors |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3624 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3625 |
/** @typedef {import('../../types').MapSelect} MapSelect */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3626 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3627 |
* @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3628 |
* @template {MapSelect|StoreDescriptor<any>} T |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3629 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3630 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3631 |
function Store(registry, suspense) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3632 |
const select = suspense ? registry.suspendSelect : registry.select; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3633 |
const queueContext = {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3634 |
let lastMapSelect; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3635 |
let lastMapResult; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3636 |
let lastMapResultValid = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3637 |
let lastIsAsync; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3638 |
let subscriber; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3639 |
let didWarnUnstableReference; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3640 |
const storeStatesOnMount = new Map(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3641 |
function getStoreState(name) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3642 |
var _registry$stores$name; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3643 |
// If there's no store property (custom generic store), return an empty |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3644 |
// object. When comparing the state, the empty objects will cause the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3645 |
// equality check to fail, setting `lastMapResultValid` to false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3646 |
return (_registry$stores$name = registry.stores[name]?.store?.getState?.()) !== null && _registry$stores$name !== void 0 ? _registry$stores$name : {}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3647 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3648 |
const createSubscriber = stores => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3649 |
// The set of stores the `subscribe` function is supposed to subscribe to. Here it is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3650 |
// initialized, and then the `updateStores` function can add new stores to it. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3651 |
const activeStores = [...stores]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3652 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3653 |
// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3654 |
// be called multiple times to establish multiple subscriptions. That's why we need to |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3655 |
// keep a set of active subscriptions; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3656 |
const activeSubscriptions = new Set(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3657 |
function subscribe(listener) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3658 |
// Maybe invalidate the value right after subscription was created. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3659 |
// React will call `getValue` after subscribing, to detect store |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3660 |
// updates that happened in the interval between the `getValue` call |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3661 |
// during render and creating the subscription, which is slightly |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3662 |
// delayed. We need to ensure that this second `getValue` call will |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3663 |
// compute a fresh value only if any of the store states have |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3664 |
// changed in the meantime. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3665 |
if (lastMapResultValid) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3666 |
for (const name of activeStores) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3667 |
if (storeStatesOnMount.get(name) !== getStoreState(name)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3668 |
lastMapResultValid = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3669 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3670 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3671 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3672 |
storeStatesOnMount.clear(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3673 |
const onStoreChange = () => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3674 |
// Invalidate the value on store update, so that a fresh value is computed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3675 |
lastMapResultValid = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3676 |
listener(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3677 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3678 |
const onChange = () => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3679 |
if (lastIsAsync) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3680 |
renderQueue.add(queueContext, onStoreChange); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3681 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3682 |
onStoreChange(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3683 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3684 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3685 |
const unsubs = []; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3686 |
function subscribeStore(storeName) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3687 |
unsubs.push(registry.subscribe(onChange, storeName)); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3688 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3689 |
for (const storeName of activeStores) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3690 |
subscribeStore(storeName); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3691 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3692 |
activeSubscriptions.add(subscribeStore); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3693 |
return () => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3694 |
activeSubscriptions.delete(subscribeStore); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3695 |
for (const unsub of unsubs.values()) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3696 |
// The return value of the subscribe function could be undefined if the store is a custom generic store. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3697 |
unsub?.(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3698 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3699 |
// Cancel existing store updates that were already scheduled. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3700 |
renderQueue.cancel(queueContext); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3701 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3702 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3703 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3704 |
// Check if `newStores` contains some stores we're not subscribed to yet, and add them. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3705 |
function updateStores(newStores) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3706 |
for (const newStore of newStores) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3707 |
if (activeStores.includes(newStore)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3708 |
continue; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3709 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3710 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3711 |
// New `subscribe` calls will subscribe to `newStore`, too. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3712 |
activeStores.push(newStore); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3713 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3714 |
// Add `newStore` to existing subscriptions. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3715 |
for (const subscription of activeSubscriptions) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3716 |
subscription(newStore); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3717 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3718 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3719 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3720 |
return { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3721 |
subscribe, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3722 |
updateStores |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3723 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3724 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3725 |
return (mapSelect, isAsync) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3726 |
function updateValue() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3727 |
// If the last value is valid, and the `mapSelect` callback hasn't changed, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3728 |
// then we can safely return the cached value. The value can change only on |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3729 |
// store update, and in that case value will be invalidated by the listener. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3730 |
if (lastMapResultValid && mapSelect === lastMapSelect) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3731 |
return lastMapResult; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3732 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3733 |
const listeningStores = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3734 |
current: null |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3735 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3736 |
const mapResult = registry.__unstableMarkListeningStores(() => mapSelect(select, registry), listeningStores); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3737 |
if (true) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3738 |
if (!didWarnUnstableReference) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3739 |
const secondMapResult = mapSelect(select, registry); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3740 |
if (!external_wp_isShallowEqual_default()(mapResult, secondMapResult)) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3741 |
warnOnUnstableReference(mapResult, secondMapResult); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3742 |
didWarnUnstableReference = true; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3743 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3744 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3745 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3746 |
if (!subscriber) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3747 |
for (const name of listeningStores.current) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3748 |
storeStatesOnMount.set(name, getStoreState(name)); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3749 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3750 |
subscriber = createSubscriber(listeningStores.current); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3751 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3752 |
subscriber.updateStores(listeningStores.current); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3753 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3754 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3755 |
// If the new value is shallow-equal to the old one, keep the old one so |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3756 |
// that we don't trigger unwanted updates that do a `===` check. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3757 |
if (!external_wp_isShallowEqual_default()(lastMapResult, mapResult)) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3758 |
lastMapResult = mapResult; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3759 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3760 |
lastMapSelect = mapSelect; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3761 |
lastMapResultValid = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3762 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3763 |
function getValue() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3764 |
// Update the value in case it's been invalidated or `mapSelect` has changed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3765 |
updateValue(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3766 |
return lastMapResult; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3767 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3768 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3769 |
// When transitioning from async to sync mode, cancel existing store updates |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3770 |
// that have been scheduled, and invalidate the value so that it's freshly |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3771 |
// computed. It might have been changed by the update we just cancelled. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3772 |
if (lastIsAsync && !isAsync) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3773 |
lastMapResultValid = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3774 |
renderQueue.cancel(queueContext); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3775 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3776 |
updateValue(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3777 |
lastIsAsync = isAsync; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3778 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3779 |
// Return a pair of functions that can be passed to `useSyncExternalStore`. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3780 |
return { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3781 |
subscribe: subscriber.subscribe, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3782 |
getValue |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3783 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3784 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3785 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3786 |
function _useStaticSelect(storeName) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3787 |
return useRegistry().select(storeName); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3788 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3789 |
function _useMappingSelect(suspense, mapSelect, deps) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3790 |
const registry = useRegistry(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3791 |
const isAsync = useAsyncMode(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3792 |
const store = (0,external_wp_element_namespaceObject.useMemo)(() => Store(registry, suspense), [registry, suspense]); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3793 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3794 |
// These are "pass-through" dependencies from the parent hook, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3795 |
// and the parent should catch any hook rule violations. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3796 |
const selector = (0,external_wp_element_namespaceObject.useCallback)(mapSelect, deps); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3797 |
const { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3798 |
subscribe, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3799 |
getValue |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3800 |
} = store(selector, isAsync); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3801 |
const result = (0,external_wp_element_namespaceObject.useSyncExternalStore)(subscribe, getValue, getValue); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3802 |
(0,external_wp_element_namespaceObject.useDebugValue)(result); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3803 |
return result; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3804 |
} |
18 | 3805 |
|
16 | 3806 |
/** |
3807 |
* Custom react hook for retrieving props from registered selectors. |
|
3808 |
* |
|
3809 |
* In general, this custom React hook follows the |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3810 |
* [rules of hooks](https://react.dev/reference/rules/rules-of-hooks). |
16 | 3811 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3812 |
* @template {MapSelect | StoreDescriptor<any>} T |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3813 |
* @param {T} mapSelect Function called on every state change. The returned value is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3814 |
* exposed to the component implementing this hook. The function |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3815 |
* receives the `registry.select` method on the first argument |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3816 |
* and the `registry` on the second argument. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3817 |
* When a store key is passed, all selectors for the store will be |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3818 |
* returned. This is only meant for usage of these selectors in event |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3819 |
* callbacks, not for data needed to create the element tree. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3820 |
* @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3821 |
* invoked on every state change unless the dependencies change. |
16 | 3822 |
* |
3823 |
* @example |
|
3824 |
* ```js |
|
18 | 3825 |
* import { useSelect } from '@wordpress/data'; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3826 |
* import { store as myCustomStore } from 'my-custom-store'; |
16 | 3827 |
* |
3828 |
* function HammerPriceDisplay( { currency } ) { |
|
3829 |
* const price = useSelect( ( select ) => { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3830 |
* return select( myCustomStore ).getPrice( 'hammer', currency ); |
16 | 3831 |
* }, [ currency ] ); |
3832 |
* return new Intl.NumberFormat( 'en-US', { |
|
3833 |
* style: 'currency', |
|
3834 |
* currency, |
|
3835 |
* } ).format( price ); |
|
3836 |
* } |
|
3837 |
* |
|
3838 |
* // Rendered in the application: |
|
3839 |
* // <HammerPriceDisplay currency="USD" /> |
|
3840 |
* ``` |
|
3841 |
* |
|
3842 |
* In the above example, when `HammerPriceDisplay` is rendered into an |
|
3843 |
* application, the price will be retrieved from the store state using the |
|
3844 |
* `mapSelect` callback on `useSelect`. If the currency prop changes then |
|
3845 |
* any price in the state for that currency is retrieved. If the currency prop |
|
3846 |
* doesn't change and other props are passed in that do change, the price will |
|
3847 |
* not change because the dependency is just the currency. |
|
3848 |
* |
|
18 | 3849 |
* When data is only used in an event callback, the data should not be retrieved |
3850 |
* on render, so it may be useful to get the selectors function instead. |
|
3851 |
* |
|
3852 |
* **Don't use `useSelect` this way when calling the selectors in the render |
|
3853 |
* function because your component won't re-render on a data change.** |
|
3854 |
* |
|
3855 |
* ```js |
|
3856 |
* import { useSelect } from '@wordpress/data'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3857 |
* import { store as myCustomStore } from 'my-custom-store'; |
18 | 3858 |
* |
3859 |
* function Paste( { children } ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3860 |
* const { getSettings } = useSelect( myCustomStore ); |
18 | 3861 |
* function onPaste() { |
3862 |
* // Do something with the settings. |
|
3863 |
* const settings = getSettings(); |
|
3864 |
* } |
|
3865 |
* return <div onPaste={ onPaste }>{ children }</div>; |
|
3866 |
* } |
|
3867 |
* ``` |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3868 |
* @return {UseSelectReturn<T>} A custom react hook. |
16 | 3869 |
*/ |
19 | 3870 |
function useSelect(mapSelect, deps) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3871 |
// On initial call, on mount, determine the mode of this `useSelect` call |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3872 |
// and then never allow it to change on subsequent updates. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3873 |
const staticSelectMode = typeof mapSelect !== 'function'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3874 |
const staticSelectModeRef = (0,external_wp_element_namespaceObject.useRef)(staticSelectMode); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3875 |
if (staticSelectMode !== staticSelectModeRef.current) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3876 |
const prevMode = staticSelectModeRef.current ? 'static' : 'mapping'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3877 |
const nextMode = staticSelectMode ? 'static' : 'mapping'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3878 |
throw new Error(`Switching useSelect from ${prevMode} to ${nextMode} is not allowed`); |
18 | 3879 |
} |
3880 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3881 |
// `staticSelectMode` is not allowed to change during the hook instance's, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3882 |
// lifetime, so the rules of hooks are not really violated. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3883 |
return staticSelectMode ? _useStaticSelect(mapSelect) : _useMappingSelect(false, mapSelect, deps); |
16 | 3884 |
} |
3885 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3886 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3887 |
* A variant of the `useSelect` hook that has the same API, but is a compatible |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3888 |
* Suspense-enabled data source. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3889 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3890 |
* @template {MapSelect} T |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3891 |
* @param {T} mapSelect Function called on every state change. The |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3892 |
* returned value is exposed to the component |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3893 |
* using this hook. The function receives the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3894 |
* `registry.suspendSelect` method as the first |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3895 |
* argument and the `registry` as the second one. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3896 |
* @param {Array} deps A dependency array used to memoize the `mapSelect` |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3897 |
* so that the same `mapSelect` is invoked on every |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3898 |
* state change unless the dependencies change. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3899 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3900 |
* @throws {Promise} A suspense Promise that is thrown if any of the called |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3901 |
* selectors is in an unresolved state. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3902 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3903 |
* @return {ReturnType<T>} Data object returned by the `mapSelect` function. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3904 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3905 |
function useSuspenseSelect(mapSelect, deps) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3906 |
return _useMappingSelect(true, mapSelect, deps); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3907 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3908 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3909 |
;// external "ReactJSXRuntime" |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3910 |
const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"]; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3911 |
;// ./node_modules/@wordpress/data/build-module/components/with-select/index.js |
16 | 3912 |
/** |
3913 |
* WordPress dependencies |
|
3914 |
*/ |
|
3915 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3916 |
|
16 | 3917 |
/** |
3918 |
* Internal dependencies |
|
3919 |
*/ |
|
3920 |
||
3921 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3922 |
/** @typedef {import('react').ComponentType} ComponentType */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3923 |
|
16 | 3924 |
/** |
3925 |
* Higher-order component used to inject state-derived props using registered |
|
3926 |
* selectors. |
|
3927 |
* |
|
3928 |
* @param {Function} mapSelectToProps Function called on every state change, |
|
19 | 3929 |
* expected to return object of props to |
3930 |
* merge with the component's own props. |
|
16 | 3931 |
* |
3932 |
* @example |
|
3933 |
* ```js |
|
18 | 3934 |
* import { withSelect } from '@wordpress/data'; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3935 |
* import { store as myCustomStore } from 'my-custom-store'; |
18 | 3936 |
* |
16 | 3937 |
* function PriceDisplay( { price, currency } ) { |
3938 |
* return new Intl.NumberFormat( 'en-US', { |
|
3939 |
* style: 'currency', |
|
3940 |
* currency, |
|
3941 |
* } ).format( price ); |
|
3942 |
* } |
|
3943 |
* |
|
3944 |
* const HammerPriceDisplay = withSelect( ( select, ownProps ) => { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3945 |
* const { getPrice } = select( myCustomStore ); |
16 | 3946 |
* const { currency } = ownProps; |
3947 |
* |
|
3948 |
* return { |
|
3949 |
* price: getPrice( 'hammer', currency ), |
|
3950 |
* }; |
|
3951 |
* } )( PriceDisplay ); |
|
3952 |
* |
|
3953 |
* // Rendered in the application: |
|
3954 |
* // |
|
3955 |
* // <HammerPriceDisplay currency="USD" /> |
|
3956 |
* ``` |
|
3957 |
* In the above example, when `HammerPriceDisplay` is rendered into an |
|
3958 |
* application, it will pass the price into the underlying `PriceDisplay` |
|
3959 |
* component and update automatically if the price of a hammer ever changes in |
|
3960 |
* the store. |
|
3961 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3962 |
* @return {ComponentType} Enhanced component with merged state data props. |
16 | 3963 |
*/ |
3964 |
||
19 | 3965 |
const withSelect = mapSelectToProps => (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(WrappedComponent => (0,external_wp_compose_namespaceObject.pure)(ownProps => { |
18 | 3966 |
const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry); |
3967 |
const mergeProps = useSelect(mapSelect); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3968 |
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WrappedComponent, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3969 |
...ownProps, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3970 |
...mergeProps |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3971 |
}); |
18 | 3972 |
}), 'withSelect'); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3973 |
/* harmony default export */ const with_select = (withSelect); |
16 | 3974 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
3975 |
;// ./node_modules/@wordpress/data/build-module/components/use-dispatch/use-dispatch-with-map.js |
16 | 3976 |
/** |
3977 |
* WordPress dependencies |
|
3978 |
*/ |
|
3979 |
||
3980 |
||
18 | 3981 |
|
16 | 3982 |
/** |
3983 |
* Internal dependencies |
|
3984 |
*/ |
|
3985 |
||
3986 |
||
3987 |
/** |
|
3988 |
* Custom react hook for returning aggregate dispatch actions using the provided |
|
3989 |
* dispatchMap. |
|
3990 |
* |
|
3991 |
* Currently this is an internal api only and is implemented by `withDispatch` |
|
3992 |
* |
|
19 | 3993 |
* @param {Function} dispatchMap Receives the `registry.dispatch` function as |
3994 |
* the first argument and the `registry` object |
|
3995 |
* as the second argument. Should return an |
|
3996 |
* object mapping props to functions. |
|
3997 |
* @param {Array} deps An array of dependencies for the hook. |
|
16 | 3998 |
* @return {Object} An object mapping props to functions created by the passed |
3999 |
* in dispatchMap. |
|
4000 |
*/ |
|
18 | 4001 |
const useDispatchWithMap = (dispatchMap, deps) => { |
4002 |
const registry = useRegistry(); |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4003 |
const currentDispatchMapRef = (0,external_wp_element_namespaceObject.useRef)(dispatchMap); |
19 | 4004 |
(0,external_wp_compose_namespaceObject.useIsomorphicLayoutEffect)(() => { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4005 |
currentDispatchMapRef.current = dispatchMap; |
16 | 4006 |
}); |
19 | 4007 |
return (0,external_wp_element_namespaceObject.useMemo)(() => { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4008 |
const currentDispatchProps = currentDispatchMapRef.current(registry.dispatch, registry); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4009 |
return Object.fromEntries(Object.entries(currentDispatchProps).map(([propName, dispatcher]) => { |
16 | 4010 |
if (typeof dispatcher !== 'function') { |
4011 |
// eslint-disable-next-line no-console |
|
18 | 4012 |
console.warn(`Property ${propName} returned from dispatchMap in useDispatchWithMap must be a function.`); |
16 | 4013 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4014 |
return [propName, (...args) => currentDispatchMapRef.current(registry.dispatch, registry)[propName](...args)]; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4015 |
})); |
18 | 4016 |
}, [registry, ...deps]); |
16 | 4017 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4018 |
/* harmony default export */ const use_dispatch_with_map = (useDispatchWithMap); |
16 | 4019 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4020 |
;// ./node_modules/@wordpress/data/build-module/components/with-dispatch/index.js |
16 | 4021 |
/** |
4022 |
* WordPress dependencies |
|
4023 |
*/ |
|
4024 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4025 |
|
16 | 4026 |
/** |
4027 |
* Internal dependencies |
|
4028 |
*/ |
|
4029 |
||
4030 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4031 |
/** @typedef {import('react').ComponentType} ComponentType */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4032 |
|
16 | 4033 |
/** |
4034 |
* Higher-order component used to add dispatch props using registered action |
|
4035 |
* creators. |
|
4036 |
* |
|
4037 |
* @param {Function} mapDispatchToProps A function of returning an object of |
|
4038 |
* prop names where value is a |
|
4039 |
* dispatch-bound action creator, or a |
|
4040 |
* function to be called with the |
|
4041 |
* component's props and returning an |
|
4042 |
* action creator. |
|
4043 |
* |
|
4044 |
* @example |
|
4045 |
* ```jsx |
|
4046 |
* function Button( { onClick, children } ) { |
|
4047 |
* return <button type="button" onClick={ onClick }>{ children }</button>; |
|
4048 |
* } |
|
4049 |
* |
|
18 | 4050 |
* import { withDispatch } from '@wordpress/data'; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4051 |
* import { store as myCustomStore } from 'my-custom-store'; |
16 | 4052 |
* |
4053 |
* const SaleButton = withDispatch( ( dispatch, ownProps ) => { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4054 |
* const { startSale } = dispatch( myCustomStore ); |
16 | 4055 |
* const { discountPercent } = ownProps; |
4056 |
* |
|
4057 |
* return { |
|
4058 |
* onClick() { |
|
4059 |
* startSale( discountPercent ); |
|
4060 |
* }, |
|
4061 |
* }; |
|
4062 |
* } )( Button ); |
|
4063 |
* |
|
4064 |
* // Rendered in the application: |
|
4065 |
* // |
|
4066 |
* // <SaleButton discountPercent="20">Start Sale!</SaleButton> |
|
4067 |
* ``` |
|
4068 |
* |
|
4069 |
* @example |
|
4070 |
* In the majority of cases, it will be sufficient to use only two first params |
|
4071 |
* passed to `mapDispatchToProps` as illustrated in the previous example. |
|
4072 |
* However, there might be some very advanced use cases where using the |
|
4073 |
* `registry` object might be used as a tool to optimize the performance of |
|
4074 |
* your component. Using `select` function from the registry might be useful |
|
4075 |
* when you need to fetch some dynamic data from the store at the time when the |
|
4076 |
* event is fired, but at the same time, you never use it to render your |
|
4077 |
* component. In such scenario, you can avoid using the `withSelect` higher |
|
4078 |
* order component to compute such prop, which might lead to unnecessary |
|
4079 |
* re-renders of your component caused by its frequent value change. |
|
4080 |
* Keep in mind, that `mapDispatchToProps` must return an object with functions |
|
4081 |
* only. |
|
4082 |
* |
|
4083 |
* ```jsx |
|
4084 |
* function Button( { onClick, children } ) { |
|
4085 |
* return <button type="button" onClick={ onClick }>{ children }</button>; |
|
4086 |
* } |
|
4087 |
* |
|
18 | 4088 |
* import { withDispatch } from '@wordpress/data'; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4089 |
* import { store as myCustomStore } from 'my-custom-store'; |
16 | 4090 |
* |
4091 |
* const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => { |
|
4092 |
* // Stock number changes frequently. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4093 |
* const { getStockNumber } = select( myCustomStore ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4094 |
* const { startSale } = dispatch( myCustomStore ); |
16 | 4095 |
* return { |
4096 |
* onClick() { |
|
4097 |
* const discountPercent = getStockNumber() > 50 ? 10 : 20; |
|
4098 |
* startSale( discountPercent ); |
|
4099 |
* }, |
|
4100 |
* }; |
|
4101 |
* } )( Button ); |
|
4102 |
* |
|
4103 |
* // Rendered in the application: |
|
4104 |
* // |
|
4105 |
* // <SaleButton>Start Sale!</SaleButton> |
|
4106 |
* ``` |
|
4107 |
* |
|
4108 |
* _Note:_ It is important that the `mapDispatchToProps` function always |
|
4109 |
* returns an object with the same keys. For example, it should not contain |
|
4110 |
* conditions under which a different value would be returned. |
|
4111 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4112 |
* @return {ComponentType} Enhanced component with merged dispatcher props. |
16 | 4113 |
*/ |
4114 |
||
19 | 4115 |
const withDispatch = mapDispatchToProps => (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(WrappedComponent => ownProps => { |
18 | 4116 |
const mapDispatch = (dispatch, registry) => mapDispatchToProps(dispatch, ownProps, registry); |
4117 |
const dispatchProps = use_dispatch_with_map(mapDispatch, []); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4118 |
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WrappedComponent, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4119 |
...ownProps, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4120 |
...dispatchProps |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4121 |
}); |
18 | 4122 |
}, 'withDispatch'); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4123 |
/* harmony default export */ const with_dispatch = (withDispatch); |
16 | 4124 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4125 |
;// ./node_modules/@wordpress/data/build-module/components/with-registry/index.js |
16 | 4126 |
/** |
4127 |
* WordPress dependencies |
|
4128 |
*/ |
|
4129 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4130 |
|
16 | 4131 |
/** |
4132 |
* Internal dependencies |
|
4133 |
*/ |
|
4134 |
||
4135 |
||
4136 |
/** |
|
4137 |
* Higher-order component which renders the original component with the current |
|
4138 |
* registry context passed as its `registry` prop. |
|
4139 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4140 |
* @param {Component} OriginalComponent Original component. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4141 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4142 |
* @return {Component} Enhanced component. |
16 | 4143 |
*/ |
4144 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4145 |
const withRegistry = (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(OriginalComponent => props => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(RegistryConsumer, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4146 |
children: registry => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(OriginalComponent, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4147 |
...props, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4148 |
registry: registry |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4149 |
}) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4150 |
}), 'withRegistry'); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4151 |
/* harmony default export */ const with_registry = (withRegistry); |
16 | 4152 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4153 |
;// ./node_modules/@wordpress/data/build-module/components/use-dispatch/use-dispatch.js |
16 | 4154 |
/** |
4155 |
* Internal dependencies |
|
4156 |
*/ |
|
4157 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4158 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4159 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4160 |
* @typedef {import('../../types').StoreDescriptor<StoreConfig>} StoreDescriptor |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4161 |
* @template {import('../../types').AnyConfig} StoreConfig |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4162 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4163 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4164 |
* @typedef {import('../../types').UseDispatchReturn<StoreNameOrDescriptor>} UseDispatchReturn |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4165 |
* @template StoreNameOrDescriptor |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4166 |
*/ |
18 | 4167 |
|
16 | 4168 |
/** |
4169 |
* A custom react hook returning the current registry dispatch actions creators. |
|
4170 |
* |
|
4171 |
* Note: The component using this hook must be within the context of a |
|
4172 |
* RegistryProvider. |
|
4173 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4174 |
* @template {undefined | string | StoreDescriptor<any>} StoreNameOrDescriptor |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4175 |
* @param {StoreNameOrDescriptor} [storeNameOrDescriptor] Optionally provide the name of the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4176 |
* store or its descriptor from which to |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4177 |
* retrieve action creators. If not |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4178 |
* provided, the registry.dispatch |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4179 |
* function is returned instead. |
16 | 4180 |
* |
4181 |
* @example |
|
4182 |
* This illustrates a pattern where you may need to retrieve dynamic data from |
|
4183 |
* the server via the `useSelect` hook to use in combination with the dispatch |
|
4184 |
* action. |
|
4185 |
* |
|
4186 |
* ```jsx |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4187 |
* import { useCallback } from 'react'; |
18 | 4188 |
* import { useDispatch, useSelect } from '@wordpress/data'; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4189 |
* import { store as myCustomStore } from 'my-custom-store'; |
16 | 4190 |
* |
4191 |
* function Button( { onClick, children } ) { |
|
4192 |
* return <button type="button" onClick={ onClick }>{ children }</button> |
|
4193 |
* } |
|
4194 |
* |
|
4195 |
* const SaleButton = ( { children } ) => { |
|
4196 |
* const { stockNumber } = useSelect( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4197 |
* ( select ) => select( myCustomStore ).getStockNumber(), |
16 | 4198 |
* [] |
4199 |
* ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4200 |
* const { startSale } = useDispatch( myCustomStore ); |
16 | 4201 |
* const onClick = useCallback( () => { |
4202 |
* const discountPercent = stockNumber > 50 ? 10: 20; |
|
4203 |
* startSale( discountPercent ); |
|
4204 |
* }, [ stockNumber ] ); |
|
4205 |
* return <Button onClick={ onClick }>{ children }</Button> |
|
4206 |
* } |
|
4207 |
* |
|
4208 |
* // Rendered somewhere in the application: |
|
4209 |
* // |
|
4210 |
* // <SaleButton>Start Sale!</SaleButton> |
|
4211 |
* ``` |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4212 |
* @return {UseDispatchReturn<StoreNameOrDescriptor>} A custom react hook. |
16 | 4213 |
*/ |
19 | 4214 |
const useDispatch = storeNameOrDescriptor => { |
18 | 4215 |
const { |
4216 |
dispatch |
|
4217 |
} = useRegistry(); |
|
19 | 4218 |
return storeNameOrDescriptor === void 0 ? dispatch : dispatch(storeNameOrDescriptor); |
16 | 4219 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4220 |
/* harmony default export */ const use_dispatch = (useDispatch); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4221 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4222 |
;// ./node_modules/@wordpress/data/build-module/dispatch.js |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4223 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4224 |
* Internal dependencies |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4225 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4226 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4227 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4228 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4229 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4230 |
* Given a store descriptor, returns an object of the store's action creators. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4231 |
* Calling an action creator will cause it to be dispatched, updating the state value accordingly. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4232 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4233 |
* Note: Action creators returned by the dispatch will return a promise when |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4234 |
* they are called. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4235 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4236 |
* @param storeNameOrDescriptor The store descriptor. The legacy calling convention of passing |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4237 |
* the store name is also supported. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4238 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4239 |
* @example |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4240 |
* ```js |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4241 |
* import { dispatch } from '@wordpress/data'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4242 |
* import { store as myCustomStore } from 'my-custom-store'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4243 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4244 |
* dispatch( myCustomStore ).setPrice( 'hammer', 9.75 ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4245 |
* ``` |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4246 |
* @return Object containing the action creators. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4247 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4248 |
function dispatch_dispatch(storeNameOrDescriptor) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4249 |
return default_registry.dispatch(storeNameOrDescriptor); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4250 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4251 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4252 |
;// ./node_modules/@wordpress/data/build-module/select.js |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4253 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4254 |
* Internal dependencies |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4255 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4256 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4257 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4258 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4259 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4260 |
* Given a store descriptor, returns an object of the store's selectors. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4261 |
* The selector functions are been pre-bound to pass the current state automatically. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4262 |
* As a consumer, you need only pass arguments of the selector, if applicable. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4263 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4264 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4265 |
* @param storeNameOrDescriptor The store descriptor. The legacy calling convention |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4266 |
* of passing the store name is also supported. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4267 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4268 |
* @example |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4269 |
* ```js |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4270 |
* import { select } from '@wordpress/data'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4271 |
* import { store as myCustomStore } from 'my-custom-store'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4272 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4273 |
* select( myCustomStore ).getPrice( 'hammer' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4274 |
* ``` |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4275 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4276 |
* @return Object containing the store's selectors. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4277 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4278 |
function select_select(storeNameOrDescriptor) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4279 |
return default_registry.select(storeNameOrDescriptor); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4280 |
} |
16 | 4281 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
4282 |
;// ./node_modules/@wordpress/data/build-module/index.js |
16 | 4283 |
/** |
4284 |
* Internal dependencies |
|
4285 |
*/ |
|
4286 |
||
4287 |
||
4288 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4289 |
|
19 | 4290 |
/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */ |
18 | 4291 |
|
4292 |
||
4293 |
||
16 | 4294 |
|
4295 |
||
4296 |
||
4297 |
||
4298 |
||
4299 |
||
4300 |
||
4301 |
||
4302 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4303 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4304 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4305 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4306 |
|
16 | 4307 |
/** |
4308 |
* Object of available plugins to use with a registry. |
|
4309 |
* |
|
4310 |
* @see [use](#use) |
|
4311 |
* |
|
4312 |
* @type {Object} |
|
4313 |
*/ |
|
4314 |
||
4315 |
||
4316 |
/** |
|
4317 |
* The combineReducers helper function turns an object whose values are different |
|
4318 |
* reducing functions into a single reducing function you can pass to registerReducer. |
|
4319 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4320 |
* @type {import('./types').combineReducers} |
16 | 4321 |
* @param {Object} reducers An object whose values correspond to different reducing |
4322 |
* functions that need to be combined into one. |
|
4323 |
* |
|
4324 |
* @example |
|
4325 |
* ```js |
|
18 | 4326 |
* import { combineReducers, createReduxStore, register } from '@wordpress/data'; |
16 | 4327 |
* |
4328 |
* const prices = ( state = {}, action ) => { |
|
4329 |
* return action.type === 'SET_PRICE' ? |
|
4330 |
* { |
|
4331 |
* ...state, |
|
4332 |
* [ action.item ]: action.price, |
|
4333 |
* } : |
|
4334 |
* state; |
|
4335 |
* }; |
|
4336 |
* |
|
4337 |
* const discountPercent = ( state = 0, action ) => { |
|
4338 |
* return action.type === 'START_SALE' ? |
|
4339 |
* action.discountPercent : |
|
4340 |
* state; |
|
4341 |
* }; |
|
4342 |
* |
|
18 | 4343 |
* const store = createReduxStore( 'my-shop', { |
16 | 4344 |
* reducer: combineReducers( { |
4345 |
* prices, |
|
4346 |
* discountPercent, |
|
4347 |
* } ), |
|
4348 |
* } ); |
|
18 | 4349 |
* register( store ); |
16 | 4350 |
* ``` |
4351 |
* |
|
19 | 4352 |
* @return {Function} A reducer that invokes every reducer inside the reducers |
4353 |
* object, and constructs a state object with the same shape. |
|
16 | 4354 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4355 |
const build_module_combineReducers = combine_reducers_combineReducers; |
16 | 4356 |
|
4357 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4358 |
* Given a store descriptor, returns an object containing the store's selectors pre-bound to state |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4359 |
* so that you only need to supply additional arguments, and modified so that they return promises |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4360 |
* that resolve to their eventual values, after any resolvers have ran. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4361 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4362 |
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4363 |
* convention of passing the store name is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4364 |
* also supported. |
16 | 4365 |
* |
4366 |
* @example |
|
4367 |
* ```js |
|
18 | 4368 |
* import { resolveSelect } from '@wordpress/data'; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4369 |
* import { store as myCustomStore } from 'my-custom-store'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4370 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4371 |
* resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log) |
16 | 4372 |
* ``` |
4373 |
* |
|
4374 |
* @return {Object} Object containing the store's promise-wrapped selectors. |
|
4375 |
*/ |
|
18 | 4376 |
const build_module_resolveSelect = default_registry.resolveSelect; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4377 |
|
16 | 4378 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4379 |
* Given a store descriptor, returns an object containing the store's selectors pre-bound to state |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4380 |
* so that you only need to supply additional arguments, and modified so that they throw promises |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4381 |
* in case the selector is not resolved yet. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4382 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4383 |
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4384 |
* convention of passing the store name is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4385 |
* also supported. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4386 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4387 |
* @return {Object} Object containing the store's suspense-wrapped selectors. |
16 | 4388 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4389 |
const suspendSelect = default_registry.suspendSelect; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4390 |
|
16 | 4391 |
/** |
4392 |
* Given a listener function, the function will be called any time the state value |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4393 |
* of one of the registered stores has changed. If you specify the optional |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4394 |
* `storeNameOrDescriptor` parameter, the listener function will be called only |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4395 |
* on updates on that one specific registered store. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4396 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4397 |
* This function returns an `unsubscribe` function used to stop the subscription. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4398 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4399 |
* @param {Function} listener Callback function. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4400 |
* @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name. |
16 | 4401 |
* |
4402 |
* @example |
|
4403 |
* ```js |
|
18 | 4404 |
* import { subscribe } from '@wordpress/data'; |
16 | 4405 |
* |
4406 |
* const unsubscribe = subscribe( () => { |
|
4407 |
* // You could use this opportunity to test whether the derived result of a |
|
4408 |
* // selector has subsequently changed as the result of a state update. |
|
4409 |
* } ); |
|
4410 |
* |
|
4411 |
* // Later, if necessary... |
|
4412 |
* unsubscribe(); |
|
4413 |
* ``` |
|
4414 |
*/ |
|
19 | 4415 |
const subscribe = default_registry.subscribe; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4416 |
|
16 | 4417 |
/** |
19 | 4418 |
* Registers a generic store instance. |
4419 |
* |
|
4420 |
* @deprecated Use `register( storeDescriptor )` instead. |
|
4421 |
* |
|
4422 |
* @param {string} name Store registry name. |
|
4423 |
* @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`). |
|
16 | 4424 |
*/ |
19 | 4425 |
const registerGenericStore = default_registry.registerGenericStore; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4426 |
|
16 | 4427 |
/** |
4428 |
* Registers a standard `@wordpress/data` store. |
|
4429 |
* |
|
18 | 4430 |
* @deprecated Use `register` instead. |
4431 |
* |
|
4432 |
* @param {string} storeName Unique namespace identifier for the store. |
|
4433 |
* @param {Object} options Store description (reducer, actions, selectors, resolvers). |
|
16 | 4434 |
* |
4435 |
* @return {Object} Registered store object. |
|
4436 |
*/ |
|
18 | 4437 |
const registerStore = default_registry.registerStore; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4438 |
|
16 | 4439 |
/** |
4440 |
* Extends a registry to inherit functionality provided by a given plugin. A |
|
4441 |
* plugin is an object with properties aligning to that of a registry, merged |
|
4442 |
* to extend the default registry behavior. |
|
4443 |
* |
|
4444 |
* @param {Object} plugin Plugin object. |
|
4445 |
*/ |
|
19 | 4446 |
const use = default_registry.use; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4447 |
|
18 | 4448 |
/** |
19 | 4449 |
* Registers a standard `@wordpress/data` store descriptor. |
18 | 4450 |
* |
4451 |
* @example |
|
4452 |
* ```js |
|
4453 |
* import { createReduxStore, register } from '@wordpress/data'; |
|
4454 |
* |
|
4455 |
* const store = createReduxStore( 'demo', { |
|
4456 |
* reducer: ( state = 'OK' ) => state, |
|
4457 |
* selectors: { |
|
4458 |
* getValue: ( state ) => state, |
|
4459 |
* }, |
|
4460 |
* } ); |
|
4461 |
* register( store ); |
|
4462 |
* ``` |
|
4463 |
* |
|
19 | 4464 |
* @param {StoreDescriptor} store Store descriptor. |
18 | 4465 |
*/ |
19 | 4466 |
const register = default_registry.register; |
4467 |
||
4468 |
(window.wp = window.wp || {}).data = __webpack_exports__; |
|
4469 |
/******/ })() |
|
4470 |
; |