@wordpress/data 9.3.0 → 9.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/components/use-dispatch/use-dispatch-with-map.js +2 -6
- package/build/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build/components/use-select/index.js +1 -1
- package/build/components/use-select/index.js.map +1 -1
- package/build/controls.js +18 -37
- package/build/controls.js.map +1 -1
- package/build/factory.js +1 -3
- package/build/factory.js.map +1 -1
- package/build/redux-store/index.js +100 -191
- package/build/redux-store/index.js.map +1 -1
- package/build/redux-store/metadata/reducer.js +2 -8
- package/build/redux-store/metadata/reducer.js.map +1 -1
- package/build/redux-store/metadata/selectors.js +13 -15
- package/build/redux-store/metadata/selectors.js.map +1 -1
- package/build/redux-store/metadata/utils.js +1 -3
- package/build/redux-store/metadata/utils.js.map +1 -1
- package/build/registry.js +8 -18
- package/build/registry.js.map +1 -1
- package/build/resolvers-cache-middleware.js +3 -6
- package/build/resolvers-cache-middleware.js.map +1 -1
- package/build/store/index.js +2 -10
- package/build/store/index.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js +2 -6
- package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build-module/components/use-select/index.js +1 -1
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/controls.js +18 -37
- package/build-module/controls.js.map +1 -1
- package/build-module/factory.js +1 -3
- package/build-module/factory.js.map +1 -1
- package/build-module/redux-store/index.js +100 -191
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/redux-store/metadata/reducer.js +2 -8
- package/build-module/redux-store/metadata/reducer.js.map +1 -1
- package/build-module/redux-store/metadata/selectors.js +13 -15
- package/build-module/redux-store/metadata/selectors.js.map +1 -1
- package/build-module/redux-store/metadata/utils.js +1 -3
- package/build-module/redux-store/metadata/utils.js.map +1 -1
- package/build-module/registry.js +8 -18
- package/build-module/registry.js.map +1 -1
- package/build-module/resolvers-cache-middleware.js +3 -6
- package/build-module/resolvers-cache-middleware.js.map +1 -1
- package/build-module/store/index.js +2 -10
- package/build-module/store/index.js.map +1 -1
- package/build-types/redux-store/index.d.ts.map +1 -1
- package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/redux-store/index.js +129 -206
- package/src/redux-store/metadata/selectors.js +9 -2
- package/src/test/privateAPIs.js +31 -0
- package/tsconfig.tsbuildinfo +1 -1
package/build-module/controls.js
CHANGED
|
@@ -36,11 +36,7 @@ function isObject(object) {
|
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
function select(storeNameOrDescriptor, selectorName) {
|
|
40
|
-
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
41
|
-
args[_key - 2] = arguments[_key];
|
|
42
|
-
}
|
|
43
|
-
|
|
39
|
+
function select(storeNameOrDescriptor, selectorName, ...args) {
|
|
44
40
|
return {
|
|
45
41
|
type: SELECT,
|
|
46
42
|
storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
|
|
@@ -74,11 +70,7 @@ function select(storeNameOrDescriptor, selectorName) {
|
|
|
74
70
|
*/
|
|
75
71
|
|
|
76
72
|
|
|
77
|
-
function resolveSelect(storeNameOrDescriptor, selectorName) {
|
|
78
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
79
|
-
args[_key2 - 2] = arguments[_key2];
|
|
80
|
-
}
|
|
81
|
-
|
|
73
|
+
function resolveSelect(storeNameOrDescriptor, selectorName, ...args) {
|
|
82
74
|
return {
|
|
83
75
|
type: RESOLVE_SELECT,
|
|
84
76
|
storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
|
|
@@ -108,11 +100,7 @@ function resolveSelect(storeNameOrDescriptor, selectorName) {
|
|
|
108
100
|
*/
|
|
109
101
|
|
|
110
102
|
|
|
111
|
-
function dispatch(storeNameOrDescriptor, actionName) {
|
|
112
|
-
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
113
|
-
args[_key3 - 2] = arguments[_key3];
|
|
114
|
-
}
|
|
115
|
-
|
|
103
|
+
function dispatch(storeNameOrDescriptor, actionName, ...args) {
|
|
116
104
|
return {
|
|
117
105
|
type: DISPATCH,
|
|
118
106
|
storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
|
|
@@ -127,30 +115,23 @@ export const controls = {
|
|
|
127
115
|
dispatch
|
|
128
116
|
};
|
|
129
117
|
export const builtinControls = {
|
|
130
|
-
[SELECT]: createRegistryControl(registry =>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
storeKey,
|
|
141
|
-
selectorName,
|
|
142
|
-
args
|
|
143
|
-
} = _ref2;
|
|
118
|
+
[SELECT]: createRegistryControl(registry => ({
|
|
119
|
+
storeKey,
|
|
120
|
+
selectorName,
|
|
121
|
+
args
|
|
122
|
+
}) => registry.select(storeKey)[selectorName](...args)),
|
|
123
|
+
[RESOLVE_SELECT]: createRegistryControl(registry => ({
|
|
124
|
+
storeKey,
|
|
125
|
+
selectorName,
|
|
126
|
+
args
|
|
127
|
+
}) => {
|
|
144
128
|
const method = registry.select(storeKey)[selectorName].hasResolver ? 'resolveSelect' : 'select';
|
|
145
129
|
return registry[method](storeKey)[selectorName](...args);
|
|
146
130
|
}),
|
|
147
|
-
[DISPATCH]: createRegistryControl(registry =>
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
} = _ref3;
|
|
153
|
-
return registry.dispatch(storeKey)[actionName](...args);
|
|
154
|
-
})
|
|
131
|
+
[DISPATCH]: createRegistryControl(registry => ({
|
|
132
|
+
storeKey,
|
|
133
|
+
actionName,
|
|
134
|
+
args
|
|
135
|
+
}) => registry.dispatch(storeKey)[actionName](...args))
|
|
155
136
|
};
|
|
156
137
|
//# sourceMappingURL=controls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/controls.js"],"names":["createRegistryControl","SELECT","RESOLVE_SELECT","DISPATCH","isObject","object","select","storeNameOrDescriptor","selectorName","args","type","storeKey","name","resolveSelect","dispatch","actionName","controls","builtinControls","registry","method","hasResolver"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,qBAAT,QAAsC,WAAtC;AAEA;;AAEA,MAAMC,MAAM,GAAG,eAAf;AACA,MAAMC,cAAc,GAAG,uBAAvB;AACA,MAAMC,QAAQ,GAAG,iBAAjB;;AAEA,SAASC,QAAT,CAAmBC,MAAnB,EAA4B;AAC3B,SAAOA,MAAM,KAAK,IAAX,IAAmB,OAAOA,MAAP,KAAkB,QAA5C;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,MAAT,CAAiBC,qBAAjB,EAAwCC,YAAxC,
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/controls.js"],"names":["createRegistryControl","SELECT","RESOLVE_SELECT","DISPATCH","isObject","object","select","storeNameOrDescriptor","selectorName","args","type","storeKey","name","resolveSelect","dispatch","actionName","controls","builtinControls","registry","method","hasResolver"],"mappings":"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","sourcesContent":["/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nconst SELECT = '@@data/SELECT';\nconst RESOLVE_SELECT = '@@data/RESOLVE_SELECT';\nconst DISPATCH = '@@data/DISPATCH';\n\nfunction isObject( object ) {\n\treturn object !== null && typeof object === 'object';\n}\n\n/**\n * Dispatches a control action for triggering a synchronous registry select.\n *\n * Note: This control synchronously returns the current selector value, triggering the\n * resolution, but not waiting for it.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector.\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using `select`.\n * export function* myAction() {\n * const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' );\n * // Do stuff with the result from the `select`.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction select( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: SELECT,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering and resolving a registry select.\n *\n * Note: when this control action is handled, it automatically considers\n * selectors that may have a resolver. In such case, it will return a `Promise` that resolves\n * after the selector finishes resolving, with the final result value.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using resolveSelect\n * export function* myAction() {\n * \tconst isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' );\n * \t// do stuff with the result from the select.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction resolveSelect( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: RESOLVE_SELECT,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering a registry dispatch.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} actionName The name of the action to dispatch\n * @param {Array} args Arguments for the dispatch action.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data-controls';\n *\n * // Action generator using dispatch\n * export function* myAction() {\n * yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' );\n * // do some other things.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction dispatch( storeNameOrDescriptor, actionName, ...args ) {\n\treturn {\n\t\ttype: DISPATCH,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tactionName,\n\t\targs,\n\t};\n}\n\nexport const controls = { select, resolveSelect, dispatch };\n\nexport const builtinControls = {\n\t[ SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) =>\n\t\t\t\tregistry.select( storeKey )[ selectorName ]( ...args )\n\t),\n\t[ RESOLVE_SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) => {\n\t\t\t\tconst method = registry.select( storeKey )[ selectorName ]\n\t\t\t\t\t.hasResolver\n\t\t\t\t\t? 'resolveSelect'\n\t\t\t\t\t: 'select';\n\t\t\t\treturn registry[ method ]( storeKey )[ selectorName ](\n\t\t\t\t\t...args\n\t\t\t\t);\n\t\t\t}\n\t),\n\t[ DISPATCH ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, actionName, args } ) =>\n\t\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"]}
|
package/build-module/factory.js
CHANGED
|
@@ -42,9 +42,7 @@ export function createRegistrySelector(registrySelector) {
|
|
|
42
42
|
// Create a selector function that is bound to the registry referenced by `selector.registry`
|
|
43
43
|
// and that has the same API as a regular selector. Binding it in such a way makes it
|
|
44
44
|
// possible to call the selector directly from another selector.
|
|
45
|
-
const selector =
|
|
46
|
-
return registrySelector(selector.registry.select)(...arguments);
|
|
47
|
-
};
|
|
45
|
+
const selector = (...args) => registrySelector(selector.registry.select)(...args);
|
|
48
46
|
/**
|
|
49
47
|
* Flag indicating that the selector is a registry selector that needs the correct registry
|
|
50
48
|
* reference to be assigned to `selecto.registry` to make it work correctly.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/factory.js"],"names":["createRegistrySelector","registrySelector","selector","registry","select","isRegistrySelector","createRegistryControl","registryControl","isRegistryControl"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,sBAAT,CAAiCC,gBAAjC,EAAoD;AAC1D;AACA;AACA;AACA,QAAMC,QAAQ,GAAG
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/factory.js"],"names":["createRegistrySelector","registrySelector","selector","args","registry","select","isRegistrySelector","createRegistryControl","registryControl","isRegistryControl"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,sBAAT,CAAiCC,gBAAjC,EAAoD;AAC1D;AACA;AACA;AACA,QAAMC,QAAQ,GAAG,CAAE,GAAGC,IAAL,KAChBF,gBAAgB,CAAEC,QAAQ,CAACE,QAAT,CAAkBC,MAApB,CAAhB,CAA8C,GAAGF,IAAjD,CADD;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;;;AACCD,EAAAA,QAAQ,CAACI,kBAAT,GAA8B,IAA9B;AAEA,SAAOJ,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASK,qBAAT,CAAgCC,eAAhC,EAAkD;AACxDA,EAAAA,eAAe,CAACC,iBAAhB,GAAoC,IAApC;AAEA,SAAOD,eAAP;AACA","sourcesContent":["/**\n * Creates a selector function that takes additional curried argument with the\n * registry `select` function. While a regular selector has signature\n * ```js\n * ( state, ...selectorArgs ) => ( result )\n * ```\n * that allows to select data from the store's `state`, a registry selector\n * has signature:\n * ```js\n * ( select ) => ( state, ...selectorArgs ) => ( result )\n * ```\n * that supports also selecting from other registered stores.\n *\n * @example\n * ```js\n * import { store as coreStore } from '@wordpress/core-data';\n * import { store as editorStore } from '@wordpress/editor';\n *\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( editorStore ).getCurrentPostId();\n * } );\n *\n * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {\n * // calling another registry selector just like any other function\n * const postType = getCurrentPostType( state );\n * const postId = getCurrentPostId( state );\n *\t return select( coreStore ).getEntityRecordEdits( 'postType', postType, postId );\n * } );\n * ```\n *\n * Note how the `getCurrentPostId` selector can be called just like any other function,\n * (it works even inside a regular non-registry selector) and we don't need to pass the\n * registry as argument. The registry binding happens automatically when registering the selector\n * with a store.\n *\n * @param {Function} registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return {Function} Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector( registrySelector ) {\n\t// Create a selector function that is bound to the registry referenced by `selector.registry`\n\t// and that has the same API as a regular selector. Binding it in such a way makes it\n\t// possible to call the selector directly from another selector.\n\tconst selector = ( ...args ) =>\n\t\tregistrySelector( selector.registry.select )( ...args );\n\n\t/**\n\t * Flag indicating that the selector is a registry selector that needs the correct registry\n\t * reference to be assigned to `selecto.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t *\n\t * @type {boolean}\n\t */\n\tselector.isRegistrySelector = true;\n\n\treturn selector;\n}\n\n/**\n * Creates a control function that takes additional curried argument with the `registry` object.\n * While a regular control has signature\n * ```js\n * ( action ) => ( iteratorOrPromise )\n * ```\n * where the control works with the `action` that it's bound to, a registry control has signature:\n * ```js\n * ( registry ) => ( action ) => ( iteratorOrPromise )\n * ```\n * A registry control is typically used to select data or dispatch an action to a registered\n * store.\n *\n * When registering a control created with `createRegistryControl` with a store, the store\n * knows which calling convention to use when executing the control.\n *\n * @param {Function} registryControl Function receiving a registry object and returning a control.\n *\n * @return {Function} Registry control that can be registered with a store.\n */\nexport function createRegistryControl( registryControl ) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"]}
|
|
@@ -57,12 +57,7 @@ const trimUndefinedValues = array => {
|
|
|
57
57
|
*/
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
const mapValues = (obj, callback) => Object.entries(obj !== null && obj !== void 0 ? obj : {}).
|
|
61
|
-
let [key, value] = _ref;
|
|
62
|
-
return { ...acc,
|
|
63
|
-
[key]: callback(value, key)
|
|
64
|
-
};
|
|
65
|
-
}, {}); // Convert Map objects to plain objects
|
|
60
|
+
const mapValues = (obj, callback) => Object.fromEntries(Object.entries(obj !== null && obj !== void 0 ? obj : {}).map(([key, value]) => [key, callback(value, key)])); // Convert Map objects to plain objects
|
|
66
61
|
|
|
67
62
|
|
|
68
63
|
const mapToObject = (key, state) => {
|
|
@@ -168,54 +163,63 @@ export default function createReduxStore(key, options) {
|
|
|
168
163
|
|
|
169
164
|
lock(store, privateRegistrationFunctions);
|
|
170
165
|
const resolversCache = createResolversCache();
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
...
|
|
174
|
-
}
|
|
166
|
+
|
|
167
|
+
function bindAction(action) {
|
|
168
|
+
return (...args) => Promise.resolve(store.dispatch(action(...args)));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const actions = { ...mapValues(metadataActions, bindAction),
|
|
172
|
+
...mapValues(options.actions, bindAction)
|
|
173
|
+
};
|
|
175
174
|
lock(actions, new Proxy(privateActions, {
|
|
176
175
|
get: (target, prop) => {
|
|
177
|
-
|
|
176
|
+
const privateAction = privateActions[prop];
|
|
177
|
+
return privateAction ? bindAction(privateAction) : actions[prop];
|
|
178
178
|
}
|
|
179
179
|
}));
|
|
180
|
-
let selectors = mapSelectors({ ...mapValues(metadataSelectors, selector => function (state) {
|
|
181
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
182
|
-
args[_key - 1] = arguments[_key];
|
|
183
|
-
}
|
|
184
180
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
selector.registry = registry;
|
|
190
|
-
}
|
|
181
|
+
function bindSelector(selector) {
|
|
182
|
+
if (selector.isRegistrySelector) {
|
|
183
|
+
selector.registry = registry;
|
|
184
|
+
}
|
|
191
185
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
args[_key2 - 1] = arguments[_key2];
|
|
195
|
-
}
|
|
186
|
+
const boundSelector = (...args) => {
|
|
187
|
+
const state = store.__unstableOriginalGetState();
|
|
196
188
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
})
|
|
200
|
-
}, store);
|
|
201
|
-
lock(selectors, new Proxy(privateSelectors, {
|
|
202
|
-
get: (target, prop) => {
|
|
203
|
-
return mapSelectors(mapValues(privateSelectors, selector => function (state) {
|
|
204
|
-
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
205
|
-
args[_key3 - 1] = arguments[_key3];
|
|
206
|
-
}
|
|
189
|
+
return selector(state.root, ...args);
|
|
190
|
+
};
|
|
207
191
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
192
|
+
boundSelector.hasResolver = false;
|
|
193
|
+
return boundSelector;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function bindMetadataSelector(selector) {
|
|
197
|
+
const boundSelector = (...args) => {
|
|
198
|
+
const state = store.__unstableOriginalGetState();
|
|
199
|
+
|
|
200
|
+
return selector(state.metadata, ...args);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
boundSelector.hasResolver = false;
|
|
204
|
+
return boundSelector;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
let selectors = { ...mapValues(metadataSelectors, bindMetadataSelector),
|
|
208
|
+
...mapValues(options.selectors, bindSelector)
|
|
209
|
+
};
|
|
210
|
+
let resolvers;
|
|
212
211
|
|
|
213
212
|
if (options.resolvers) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
selectors = result.selectors;
|
|
213
|
+
resolvers = mapResolvers(options.resolvers);
|
|
214
|
+
selectors = mapSelectorsWithResolvers(selectors, resolvers, store, resolversCache);
|
|
217
215
|
}
|
|
218
216
|
|
|
217
|
+
lock(selectors, new Proxy(privateSelectors, {
|
|
218
|
+
get: (target, prop) => {
|
|
219
|
+
const privateSelector = privateSelectors[prop];
|
|
220
|
+
return privateSelector ? bindSelector(privateSelector) : selectors[prop];
|
|
221
|
+
}
|
|
222
|
+
}));
|
|
219
223
|
const resolveSelectors = mapResolveSelectors(selectors, store);
|
|
220
224
|
const suspendSelectors = mapSuspendSelectors(selectors, store);
|
|
221
225
|
|
|
@@ -315,61 +319,6 @@ function instantiateReduxStore(key, options, registry, thunkArgs) {
|
|
|
315
319
|
root: initialState
|
|
316
320
|
}, compose(enhancers));
|
|
317
321
|
}
|
|
318
|
-
/**
|
|
319
|
-
* Maps selectors to a store.
|
|
320
|
-
*
|
|
321
|
-
* @param {Object} selectors Selectors to register. Keys will be used as the
|
|
322
|
-
* public facing API. Selectors will get passed the
|
|
323
|
-
* state as first argument.
|
|
324
|
-
* @param {Object} store The store to which the selectors should be mapped.
|
|
325
|
-
* @return {Object} Selectors mapped to the provided store.
|
|
326
|
-
*/
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
function mapSelectors(selectors, store) {
|
|
330
|
-
const createStateSelector = registrySelector => {
|
|
331
|
-
const selector = function runSelector() {
|
|
332
|
-
// This function is an optimized implementation of:
|
|
333
|
-
//
|
|
334
|
-
// selector( store.getState(), ...arguments )
|
|
335
|
-
//
|
|
336
|
-
// Where the above would incur an `Array#concat` in its application,
|
|
337
|
-
// the logic here instead efficiently constructs an arguments array via
|
|
338
|
-
// direct assignment.
|
|
339
|
-
const argsLength = arguments.length;
|
|
340
|
-
const args = new Array(argsLength + 1);
|
|
341
|
-
args[0] = store.__unstableOriginalGetState();
|
|
342
|
-
|
|
343
|
-
for (let i = 0; i < argsLength; i++) {
|
|
344
|
-
args[i + 1] = arguments[i];
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return registrySelector(...args);
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
selector.hasResolver = false;
|
|
351
|
-
return selector;
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
return mapValues(selectors, createStateSelector);
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Maps actions to dispatch from a given store.
|
|
358
|
-
*
|
|
359
|
-
* @param {Object} actions Actions to register.
|
|
360
|
-
* @param {Object} store The redux store to which the actions should be mapped.
|
|
361
|
-
*
|
|
362
|
-
* @return {Object} Actions mapped to the redux store provided.
|
|
363
|
-
*/
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
function mapActions(actions, store) {
|
|
367
|
-
const createBoundAction = action => function () {
|
|
368
|
-
return Promise.resolve(store.dispatch(action(...arguments)));
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
return mapValues(actions, createBoundAction);
|
|
372
|
-
}
|
|
373
322
|
/**
|
|
374
323
|
* Maps selectors to functions that return a resolution promise for them
|
|
375
324
|
*
|
|
@@ -396,20 +345,10 @@ function mapResolveSelectors(selectors, store) {
|
|
|
396
345
|
// If the selector doesn't have a resolver, just convert the return value
|
|
397
346
|
// (including exceptions) to a Promise, no additional extra behavior is needed.
|
|
398
347
|
if (!selector.hasResolver) {
|
|
399
|
-
return async
|
|
400
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
401
|
-
args[_key4] = arguments[_key4];
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
return selector.apply(null, args);
|
|
405
|
-
};
|
|
348
|
+
return async (...args) => selector.apply(null, args);
|
|
406
349
|
}
|
|
407
350
|
|
|
408
|
-
return
|
|
409
|
-
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
410
|
-
args[_key5] = arguments[_key5];
|
|
411
|
-
}
|
|
412
|
-
|
|
351
|
+
return (...args) => {
|
|
413
352
|
return new Promise((resolve, reject) => {
|
|
414
353
|
const hasFinished = () => selectors.hasFinishedResolution(selectorName, args);
|
|
415
354
|
|
|
@@ -460,11 +399,7 @@ function mapSuspendSelectors(selectors, store) {
|
|
|
460
399
|
return selector;
|
|
461
400
|
}
|
|
462
401
|
|
|
463
|
-
return
|
|
464
|
-
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
465
|
-
args[_key6] = arguments[_key6];
|
|
466
|
-
}
|
|
467
|
-
|
|
402
|
+
return (...args) => {
|
|
468
403
|
const result = selector.apply(null, args);
|
|
469
404
|
|
|
470
405
|
if (selectors.hasFinishedResolution(selectorName, args)) {
|
|
@@ -487,22 +422,15 @@ function mapSuspendSelectors(selectors, store) {
|
|
|
487
422
|
});
|
|
488
423
|
}
|
|
489
424
|
/**
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
* used in ensuring that the data needs for the selector are satisfied.
|
|
425
|
+
* Convert resolvers to a normalized form, an object with `fulfill` method and
|
|
426
|
+
* optional methods like `isFulfilled`.
|
|
493
427
|
*
|
|
494
|
-
* @param {Object} resolvers
|
|
495
|
-
* @param {Object} selectors The current selectors to be modified.
|
|
496
|
-
* @param {Object} store The redux store to which the resolvers should be mapped.
|
|
497
|
-
* @param {Object} resolversCache Resolvers Cache.
|
|
428
|
+
* @param {Object} resolvers Resolver to convert
|
|
498
429
|
*/
|
|
499
430
|
|
|
500
431
|
|
|
501
|
-
function mapResolvers(resolvers
|
|
502
|
-
|
|
503
|
-
// cases, an object with a `fullfill` method and other optional methods like `isFulfilled`.
|
|
504
|
-
// Here we normalize the `resolver` function to an object with `fulfill` method.
|
|
505
|
-
const mappedResolvers = mapValues(resolvers, resolver => {
|
|
432
|
+
function mapResolvers(resolvers) {
|
|
433
|
+
return mapValues(resolvers, resolver => {
|
|
506
434
|
if (resolver.fulfill) {
|
|
507
435
|
return resolver;
|
|
508
436
|
}
|
|
@@ -513,87 +441,68 @@ function mapResolvers(resolvers, selectors, store, resolversCache) {
|
|
|
513
441
|
|
|
514
442
|
};
|
|
515
443
|
});
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Returns resolvers with matched selectors for a given namespace.
|
|
447
|
+
* Resolvers are side effects invoked once per argument set of a given selector call,
|
|
448
|
+
* used in ensuring that the data needs for the selector are satisfied.
|
|
449
|
+
*
|
|
450
|
+
* @param {Object} selectors The current selectors to be modified.
|
|
451
|
+
* @param {Object} resolvers Resolvers to register.
|
|
452
|
+
* @param {Object} store The redux store to which the resolvers should be mapped.
|
|
453
|
+
* @param {Object} resolversCache Resolvers Cache.
|
|
454
|
+
*/
|
|
516
455
|
|
|
517
|
-
const mapSelector = (selector, selectorName) => {
|
|
518
|
-
const resolver = resolvers[selectorName];
|
|
519
456
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
457
|
+
function mapSelectorsWithResolvers(selectors, resolvers, store, resolversCache) {
|
|
458
|
+
function fulfillSelector(resolver, selectorName, args) {
|
|
459
|
+
const state = store.getState();
|
|
460
|
+
|
|
461
|
+
if (resolversCache.isRunning(selectorName, args) || typeof resolver.isFulfilled === 'function' && resolver.isFulfilled(state, ...args)) {
|
|
462
|
+
return;
|
|
523
463
|
}
|
|
524
464
|
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
}
|
|
465
|
+
const {
|
|
466
|
+
metadata
|
|
467
|
+
} = store.__unstableOriginalGetState();
|
|
529
468
|
|
|
530
|
-
|
|
531
|
-
|
|
469
|
+
if (metadataSelectors.hasStartedResolution(metadata, selectorName, args)) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
532
472
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
473
|
+
resolversCache.markAsRunning(selectorName, args);
|
|
474
|
+
setTimeout(async () => {
|
|
475
|
+
resolversCache.clear(selectorName, args);
|
|
476
|
+
store.dispatch(metadataActions.startResolution(selectorName, args));
|
|
536
477
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
} = store.__unstableOriginalGetState();
|
|
478
|
+
try {
|
|
479
|
+
const action = resolver.fulfill(...args);
|
|
540
480
|
|
|
541
|
-
if (
|
|
542
|
-
|
|
481
|
+
if (action) {
|
|
482
|
+
await store.dispatch(action);
|
|
543
483
|
}
|
|
544
484
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
store.dispatch(metadataActions.startResolution(selectorName, args));
|
|
549
|
-
|
|
550
|
-
try {
|
|
551
|
-
await fulfillResolver(store, mappedResolvers, selectorName, ...args);
|
|
552
|
-
store.dispatch(metadataActions.finishResolution(selectorName, args));
|
|
553
|
-
} catch (error) {
|
|
554
|
-
store.dispatch(metadataActions.failResolution(selectorName, args, error));
|
|
555
|
-
}
|
|
556
|
-
});
|
|
485
|
+
store.dispatch(metadataActions.finishResolution(selectorName, args));
|
|
486
|
+
} catch (error) {
|
|
487
|
+
store.dispatch(metadataActions.failResolution(selectorName, args, error));
|
|
557
488
|
}
|
|
489
|
+
}, 0);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
return mapValues(selectors, (selector, selectorName) => {
|
|
493
|
+
const resolver = resolvers[selectorName];
|
|
494
|
+
|
|
495
|
+
if (!resolver) {
|
|
496
|
+
return selector;
|
|
497
|
+
}
|
|
558
498
|
|
|
559
|
-
|
|
499
|
+
const selectorResolver = (...args) => {
|
|
500
|
+
fulfillSelector(resolver, selectorName, args);
|
|
560
501
|
return selector(...args);
|
|
561
502
|
};
|
|
562
503
|
|
|
563
504
|
selectorResolver.hasResolver = true;
|
|
564
505
|
return selectorResolver;
|
|
565
|
-
};
|
|
566
|
-
|
|
567
|
-
return {
|
|
568
|
-
resolvers: mappedResolvers,
|
|
569
|
-
selectors: mapValues(selectors, mapSelector)
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
/**
|
|
573
|
-
* Calls a resolver given arguments
|
|
574
|
-
*
|
|
575
|
-
* @param {Object} store Store reference, for fulfilling via resolvers
|
|
576
|
-
* @param {Object} resolvers Store Resolvers
|
|
577
|
-
* @param {string} selectorName Selector name to fulfill.
|
|
578
|
-
* @param {Array} args Selector Arguments.
|
|
579
|
-
*/
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
async function fulfillResolver(store, resolvers, selectorName) {
|
|
583
|
-
const resolver = resolvers[selectorName];
|
|
584
|
-
|
|
585
|
-
if (!resolver) {
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
for (var _len8 = arguments.length, args = new Array(_len8 > 3 ? _len8 - 3 : 0), _key8 = 3; _key8 < _len8; _key8++) {
|
|
590
|
-
args[_key8 - 3] = arguments[_key8];
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
const action = resolver.fulfill(...args);
|
|
594
|
-
|
|
595
|
-
if (action) {
|
|
596
|
-
await store.dispatch(action);
|
|
597
|
-
}
|
|
506
|
+
});
|
|
598
507
|
}
|
|
599
508
|
//# sourceMappingURL=index.js.map
|