@wordpress/data 10.32.0 → 10.32.1-next.47f435fc9.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/build/components/async-mode-provider/context.js +35 -54
- package/build/components/async-mode-provider/context.js.map +7 -1
- package/build/components/async-mode-provider/index.js +40 -25
- package/build/components/async-mode-provider/index.js.map +7 -1
- package/build/components/async-mode-provider/use-async-mode.js +25 -16
- package/build/components/async-mode-provider/use-async-mode.js.map +7 -1
- package/build/components/registry-provider/context.js +46 -64
- package/build/components/registry-provider/context.js.map +7 -1
- package/build/components/registry-provider/index.js +40 -25
- package/build/components/registry-provider/index.js.map +7 -1
- package/build/components/registry-provider/use-registry.js +25 -55
- package/build/components/registry-provider/use-registry.js.map +7 -1
- package/build/components/use-dispatch/index.js +38 -17
- package/build/components/use-dispatch/index.js.map +7 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js +59 -44
- package/build/components/use-dispatch/use-dispatch-with-map.js.map +7 -1
- package/build/components/use-dispatch/use-dispatch.js +36 -71
- package/build/components/use-dispatch/use-dispatch.js.map +7 -1
- package/build/components/use-select/index.js +79 -208
- package/build/components/use-select/index.js.map +7 -1
- package/build/components/with-dispatch/index.js +34 -107
- package/build/components/with-dispatch/index.js.map +7 -1
- package/build/components/with-registry/index.js +30 -30
- package/build/components/with-registry/index.js.map +7 -1
- package/build/components/with-select/index.js +44 -67
- package/build/components/with-select/index.js.map +7 -1
- package/build/controls.js +49 -110
- package/build/controls.js.map +7 -1
- package/build/create-selector.js +36 -11
- package/build/create-selector.js.map +7 -1
- package/build/default-registry.js +24 -10
- package/build/default-registry.js.map +7 -1
- package/build/dispatch.js +38 -31
- package/build/dispatch.js.map +7 -1
- package/build/factory.js +29 -85
- package/build/factory.js.map +7 -1
- package/build/index.js +114 -301
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/plugins/index.js +36 -11
- package/build/plugins/index.js.map +7 -1
- package/build/plugins/persistence/index.js +74 -139
- package/build/plugins/persistence/index.js.map +7 -1
- package/build/plugins/persistence/storage/default.js +37 -18
- package/build/plugins/persistence/storage/default.js.map +7 -1
- package/build/plugins/persistence/storage/object.js +24 -7
- package/build/plugins/persistence/storage/object.js.map +7 -1
- package/build/promise-middleware.js +37 -20
- package/build/promise-middleware.js.map +7 -1
- package/build/redux-store/combine-reducers.js +26 -5
- package/build/redux-store/combine-reducers.js.map +7 -1
- package/build/redux-store/index.js +221 -331
- package/build/redux-store/index.js.map +7 -1
- package/build/redux-store/metadata/actions.js +51 -112
- package/build/redux-store/metadata/actions.js.map +7 -1
- package/build/redux-store/metadata/equivalent-key-map.d.js +1 -1
- package/build/redux-store/metadata/equivalent-key-map.d.js.map +7 -1
- package/build/redux-store/metadata/reducer.js +111 -115
- package/build/redux-store/metadata/reducer.js.map +7 -1
- package/build/redux-store/metadata/selectors.js +109 -181
- package/build/redux-store/metadata/selectors.js.map +7 -1
- package/build/redux-store/metadata/utils.js +32 -35
- package/build/redux-store/metadata/utils.js.map +7 -1
- package/build/redux-store/thunk-middleware.js +24 -7
- package/build/redux-store/thunk-middleware.js.map +7 -1
- package/build/registry.js +94 -198
- package/build/registry.js.map +7 -1
- package/build/resolvers-cache-middleware.js +26 -27
- package/build/resolvers-cache-middleware.js.map +7 -1
- package/build/select.js +38 -31
- package/build/select.js.map +7 -1
- package/build/store/index.js +52 -16
- package/build/store/index.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build/utils/emitter.js +33 -16
- package/build/utils/emitter.js.map +7 -1
- package/build-module/components/async-mode-provider/context.js +12 -49
- package/build-module/components/async-mode-provider/context.js.map +7 -1
- package/build-module/components/async-mode-provider/index.js +8 -3
- package/build-module/components/async-mode-provider/index.js.map +7 -1
- package/build-module/components/async-mode-provider/use-async-mode.js +7 -11
- package/build-module/components/async-mode-provider/use-async-mode.js.map +7 -1
- package/build-module/components/registry-provider/context.js +13 -58
- package/build-module/components/registry-provider/context.js.map +7 -1
- package/build-module/components/registry-provider/index.js +8 -3
- package/build-module/components/registry-provider/index.js.map +7 -1
- package/build-module/components/registry-provider/use-registry.js +7 -51
- package/build-module/components/registry-provider/use-registry.js.map +7 -1
- package/build-module/components/use-dispatch/index.js +7 -3
- package/build-module/components/use-dispatch/index.js.map +7 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js +27 -35
- package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +7 -1
- package/build-module/components/use-dispatch/use-dispatch.js +8 -66
- package/build-module/components/use-dispatch/use-dispatch.js.map +7 -1
- package/build-module/components/use-select/index.js +45 -193
- package/build-module/components/use-select/index.js.map +7 -1
- package/build-module/components/with-dispatch/index.js +16 -104
- package/build-module/components/with-dispatch/index.js.map +7 -1
- package/build-module/components/with-registry/index.js +12 -27
- package/build-module/components/with-registry/index.js.map +7 -1
- package/build-module/components/with-select/index.js +16 -63
- package/build-module/components/with-select/index.js.map +7 -1
- package/build-module/controls.js +25 -105
- package/build-module/controls.js.map +7 -1
- package/build-module/create-selector.js +5 -8
- package/build-module/create-selector.js.map +7 -1
- package/build-module/default-registry.js +6 -6
- package/build-module/default-registry.js.map +7 -1
- package/build-module/dispatch.js +6 -27
- package/build-module/dispatch.js.map +7 -1
- package/build-module/factory.js +8 -82
- package/build-module/factory.js.map +7 -1
- package/build-module/index.js +62 -185
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/plugins/index.js +5 -2
- package/build-module/plugins/index.js.map +7 -1
- package/build-module/plugins/persistence/index.js +38 -129
- package/build-module/plugins/persistence/index.js.map +7 -1
- package/build-module/plugins/persistence/storage/default.js +8 -11
- package/build-module/plugins/persistence/storage/default.js.map +7 -1
- package/build-module/plugins/persistence/storage/object.js +6 -3
- package/build-module/plugins/persistence/storage/object.js.map +7 -1
- package/build-module/promise-middleware.js +8 -14
- package/build-module/promise-middleware.js.map +7 -1
- package/build-module/redux-store/combine-reducers.js +5 -2
- package/build-module/redux-store/combine-reducers.js.map +7 -1
- package/build-module/redux-store/index.js +180 -310
- package/build-module/redux-store/index.js.map +7 -1
- package/build-module/redux-store/metadata/actions.js +30 -109
- package/build-module/redux-store/metadata/actions.js.map +7 -1
- package/build-module/redux-store/metadata/equivalent-key-map.d.js +1 -2
- package/build-module/redux-store/metadata/equivalent-key-map.d.js.map +7 -1
- package/build-module/redux-store/metadata/reducer.js +83 -108
- package/build-module/redux-store/metadata/reducer.js.map +7 -1
- package/build-module/redux-store/metadata/selectors.js +76 -175
- package/build-module/redux-store/metadata/selectors.js.map +7 -1
- package/build-module/redux-store/metadata/utils.js +10 -30
- package/build-module/redux-store/metadata/utils.js.map +7 -1
- package/build-module/redux-store/thunk-middleware.js +7 -4
- package/build-module/redux-store/thunk-middleware.js.map +7 -1
- package/build-module/registry.js +56 -187
- package/build-module/registry.js.map +7 -1
- package/build-module/resolvers-cache-middleware.js +8 -23
- package/build-module/resolvers-cache-middleware.js.map +7 -1
- package/build-module/select.js +6 -27
- package/build-module/select.js.map +7 -1
- package/build-module/store/index.js +34 -12
- package/build-module/store/index.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/build-module/utils/emitter.js +12 -13
- package/build-module/utils/emitter.js.map +7 -1
- package/package.json +17 -10
package/build-module/index.js
CHANGED
|
@@ -1,185 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
* prices,
|
|
64
|
-
* discountPercent,
|
|
65
|
-
* } ),
|
|
66
|
-
* } );
|
|
67
|
-
* register( store );
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* @return {Function} A reducer that invokes every reducer inside the reducers
|
|
71
|
-
* object, and constructs a state object with the same shape.
|
|
72
|
-
*/
|
|
73
|
-
export const combineReducers = combineReducersModule;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Given a store descriptor, returns an object containing the store's selectors pre-bound to state
|
|
77
|
-
* so that you only need to supply additional arguments, and modified so that they return promises
|
|
78
|
-
* that resolve to their eventual values, after any resolvers have ran.
|
|
79
|
-
*
|
|
80
|
-
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
|
|
81
|
-
* convention of passing the store name is
|
|
82
|
-
* also supported.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```js
|
|
86
|
-
* import { resolveSelect } from '@wordpress/data';
|
|
87
|
-
* import { store as myCustomStore } from 'my-custom-store';
|
|
88
|
-
*
|
|
89
|
-
* resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)
|
|
90
|
-
* ```
|
|
91
|
-
*
|
|
92
|
-
* @return {Object} Object containing the store's promise-wrapped selectors.
|
|
93
|
-
*/
|
|
94
|
-
export const resolveSelect = defaultRegistry.resolveSelect;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Given a store descriptor, returns an object containing the store's selectors pre-bound to state
|
|
98
|
-
* so that you only need to supply additional arguments, and modified so that they throw promises
|
|
99
|
-
* in case the selector is not resolved yet.
|
|
100
|
-
*
|
|
101
|
-
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
|
|
102
|
-
* convention of passing the store name is
|
|
103
|
-
* also supported.
|
|
104
|
-
*
|
|
105
|
-
* @return {Object} Object containing the store's suspense-wrapped selectors.
|
|
106
|
-
*/
|
|
107
|
-
export const suspendSelect = defaultRegistry.suspendSelect;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Given a listener function, the function will be called any time the state value
|
|
111
|
-
* of one of the registered stores has changed. If you specify the optional
|
|
112
|
-
* `storeNameOrDescriptor` parameter, the listener function will be called only
|
|
113
|
-
* on updates on that one specific registered store.
|
|
114
|
-
*
|
|
115
|
-
* This function returns an `unsubscribe` function used to stop the subscription.
|
|
116
|
-
*
|
|
117
|
-
* @param {Function} listener Callback function.
|
|
118
|
-
* @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* ```js
|
|
122
|
-
* import { subscribe } from '@wordpress/data';
|
|
123
|
-
*
|
|
124
|
-
* const unsubscribe = subscribe( () => {
|
|
125
|
-
* // You could use this opportunity to test whether the derived result of a
|
|
126
|
-
* // selector has subsequently changed as the result of a state update.
|
|
127
|
-
* } );
|
|
128
|
-
*
|
|
129
|
-
* // Later, if necessary...
|
|
130
|
-
* unsubscribe();
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
export const subscribe = defaultRegistry.subscribe;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Registers a generic store instance.
|
|
137
|
-
*
|
|
138
|
-
* @deprecated Use `register( storeDescriptor )` instead.
|
|
139
|
-
*
|
|
140
|
-
* @param {string} name Store registry name.
|
|
141
|
-
* @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).
|
|
142
|
-
*/
|
|
143
|
-
export const registerGenericStore = defaultRegistry.registerGenericStore;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Registers a standard `@wordpress/data` store.
|
|
147
|
-
*
|
|
148
|
-
* @deprecated Use `register` instead.
|
|
149
|
-
*
|
|
150
|
-
* @param {string} storeName Unique namespace identifier for the store.
|
|
151
|
-
* @param {Object} options Store description (reducer, actions, selectors, resolvers).
|
|
152
|
-
*
|
|
153
|
-
* @return {Object} Registered store object.
|
|
154
|
-
*/
|
|
155
|
-
export const registerStore = defaultRegistry.registerStore;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Extends a registry to inherit functionality provided by a given plugin. A
|
|
159
|
-
* plugin is an object with properties aligning to that of a registry, merged
|
|
160
|
-
* to extend the default registry behavior.
|
|
161
|
-
*
|
|
162
|
-
* @param {Object} plugin Plugin object.
|
|
163
|
-
*/
|
|
164
|
-
export const use = defaultRegistry.use;
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Registers a standard `@wordpress/data` store descriptor.
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```js
|
|
171
|
-
* import { createReduxStore, register } from '@wordpress/data';
|
|
172
|
-
*
|
|
173
|
-
* const store = createReduxStore( 'demo', {
|
|
174
|
-
* reducer: ( state = 'OK' ) => state,
|
|
175
|
-
* selectors: {
|
|
176
|
-
* getValue: ( state ) => state,
|
|
177
|
-
* },
|
|
178
|
-
* } );
|
|
179
|
-
* register( store );
|
|
180
|
-
* ```
|
|
181
|
-
*
|
|
182
|
-
* @param {StoreDescriptor} store Store descriptor.
|
|
183
|
-
*/
|
|
184
|
-
export const register = defaultRegistry.register;
|
|
185
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import defaultRegistry from "./default-registry";
|
|
2
|
+
import * as plugins from "./plugins";
|
|
3
|
+
import { combineReducers as combineReducersModule } from "./redux-store";
|
|
4
|
+
import { default as default2 } from "./components/with-select";
|
|
5
|
+
import { default as default3 } from "./components/with-dispatch";
|
|
6
|
+
import { default as default4 } from "./components/with-registry";
|
|
7
|
+
import {
|
|
8
|
+
RegistryProvider,
|
|
9
|
+
RegistryConsumer,
|
|
10
|
+
useRegistry
|
|
11
|
+
} from "./components/registry-provider";
|
|
12
|
+
import {
|
|
13
|
+
default as default5,
|
|
14
|
+
useSuspenseSelect
|
|
15
|
+
} from "./components/use-select";
|
|
16
|
+
import { useDispatch } from "./components/use-dispatch";
|
|
17
|
+
import { AsyncModeProvider } from "./components/async-mode-provider";
|
|
18
|
+
import { createRegistry } from "./registry";
|
|
19
|
+
import { createRegistrySelector, createRegistryControl } from "./factory";
|
|
20
|
+
import { createSelector } from "./create-selector";
|
|
21
|
+
import { controls } from "./controls";
|
|
22
|
+
import { default as default6 } from "./redux-store";
|
|
23
|
+
import { dispatch } from "./dispatch";
|
|
24
|
+
import { select } from "./select";
|
|
25
|
+
const combineReducers = combineReducersModule;
|
|
26
|
+
const resolveSelect = defaultRegistry.resolveSelect;
|
|
27
|
+
const suspendSelect = defaultRegistry.suspendSelect;
|
|
28
|
+
const subscribe = defaultRegistry.subscribe;
|
|
29
|
+
const registerGenericStore = defaultRegistry.registerGenericStore;
|
|
30
|
+
const registerStore = defaultRegistry.registerStore;
|
|
31
|
+
const use = defaultRegistry.use;
|
|
32
|
+
const register = defaultRegistry.register;
|
|
33
|
+
export {
|
|
34
|
+
AsyncModeProvider,
|
|
35
|
+
RegistryConsumer,
|
|
36
|
+
RegistryProvider,
|
|
37
|
+
combineReducers,
|
|
38
|
+
controls,
|
|
39
|
+
default6 as createReduxStore,
|
|
40
|
+
createRegistry,
|
|
41
|
+
createRegistryControl,
|
|
42
|
+
createRegistrySelector,
|
|
43
|
+
createSelector,
|
|
44
|
+
dispatch,
|
|
45
|
+
plugins,
|
|
46
|
+
register,
|
|
47
|
+
registerGenericStore,
|
|
48
|
+
registerStore,
|
|
49
|
+
resolveSelect,
|
|
50
|
+
select,
|
|
51
|
+
subscribe,
|
|
52
|
+
suspendSelect,
|
|
53
|
+
use,
|
|
54
|
+
useDispatch,
|
|
55
|
+
useRegistry,
|
|
56
|
+
default5 as useSelect,
|
|
57
|
+
useSuspenseSelect,
|
|
58
|
+
default3 as withDispatch,
|
|
59
|
+
default4 as withRegistry,
|
|
60
|
+
default2 as withSelect
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport defaultRegistry from './default-registry';\nimport * as plugins from './plugins';\nimport { combineReducers as combineReducersModule } from './redux-store';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nexport { default as withSelect } from './components/with-select';\nexport { default as withDispatch } from './components/with-dispatch';\nexport { default as withRegistry } from './components/with-registry';\nexport {\n\tRegistryProvider,\n\tRegistryConsumer,\n\tuseRegistry,\n} from './components/registry-provider';\nexport {\n\tdefault as useSelect,\n\tuseSuspenseSelect,\n} from './components/use-select';\nexport { useDispatch } from './components/use-dispatch';\nexport { AsyncModeProvider } from './components/async-mode-provider';\nexport { createRegistry } from './registry';\nexport { createRegistrySelector, createRegistryControl } from './factory';\nexport { createSelector } from './create-selector';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\nexport { dispatch } from './dispatch';\nexport { select } from './select';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\n *\n * @type {Object}\n */\nexport { plugins };\n\n/**\n * The combineReducers helper function turns an object whose values are different\n * reducing functions into a single reducing function you can pass to registerReducer.\n *\n * @type {import('./types').combineReducers}\n * @param {Object} reducers An object whose values correspond to different reducing\n * functions that need to be combined into one.\n *\n * @example\n * ```js\n * import { combineReducers, createReduxStore, register } from '@wordpress/data';\n *\n * const prices = ( state = {}, action ) => {\n * \treturn action.type === 'SET_PRICE' ?\n * \t\t{\n * \t\t\t...state,\n * \t\t\t[ action.item ]: action.price,\n * \t\t} :\n * \t\tstate;\n * };\n *\n * const discountPercent = ( state = 0, action ) => {\n * \treturn action.type === 'START_SALE' ?\n * \t\taction.discountPercent :\n * \t\tstate;\n * };\n *\n * const store = createReduxStore( 'my-shop', {\n * \treducer: combineReducers( {\n * \t\tprices,\n * \t\tdiscountPercent,\n * \t} ),\n * } );\n * register( store );\n * ```\n *\n * @return {Function} A reducer that invokes every reducer inside the reducers\n * object, and constructs a state object with the same shape.\n */\nexport const combineReducers = combineReducersModule;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they return promises\n * that resolve to their eventual values, after any resolvers have ran.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return {Object} Object containing the store's promise-wrapped selectors.\n */\nexport const resolveSelect = defaultRegistry.resolveSelect;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they throw promises\n * in case the selector is not resolved yet.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @return {Object} Object containing the store's suspense-wrapped selectors.\n */\nexport const suspendSelect = defaultRegistry.suspendSelect;\n\n/**\n * Given a listener function, the function will be called any time the state value\n * of one of the registered stores has changed. If you specify the optional\n * `storeNameOrDescriptor` parameter, the listener function will be called only\n * on updates on that one specific registered store.\n *\n * This function returns an `unsubscribe` function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n *\n * @example\n * ```js\n * import { subscribe } from '@wordpress/data';\n *\n * const unsubscribe = subscribe( () => {\n * \t// You could use this opportunity to test whether the derived result of a\n * \t// selector has subsequently changed as the result of a state update.\n * } );\n *\n * // Later, if necessary...\n * unsubscribe();\n * ```\n */\nexport const subscribe = defaultRegistry.subscribe;\n\n/**\n * Registers a generic store instance.\n *\n * @deprecated Use `register( storeDescriptor )` instead.\n *\n * @param {string} name Store registry name.\n * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).\n */\nexport const registerGenericStore = defaultRegistry.registerGenericStore;\n\n/**\n * Registers a standard `@wordpress/data` store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} storeName Unique namespace identifier for the store.\n * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n *\n * @return {Object} Registered store object.\n */\nexport const registerStore = defaultRegistry.registerStore;\n\n/**\n * Extends a registry to inherit functionality provided by a given plugin. A\n * plugin is an object with properties aligning to that of a registry, merged\n * to extend the default registry behavior.\n *\n * @param {Object} plugin Plugin object.\n */\nexport const use = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store descriptor.\n *\n * @example\n * ```js\n * import { createReduxStore, register } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * register( store );\n * ```\n *\n * @param {StoreDescriptor} store Store descriptor.\n */\nexport const register = defaultRegistry.register;\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,qBAAqB;AAC5B,YAAY,aAAa;AACzB,SAAS,mBAAmB,6BAA6B;AAIzD,SAAoB,WAAXA,gBAA6B;AACtC,SAAoB,WAAXA,gBAA+B;AACxC,SAAoB,WAAXA,gBAA+B;AACxC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACY,WAAXA;AAAA,EACA;AAAA,OACM;AACP,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB,6BAA6B;AAC9D,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAoB,WAAXA,gBAAmC;AAC5C,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAkDhB,MAAM,kBAAkB;AAqBxB,MAAM,gBAAgB,gBAAgB;AAatC,MAAM,gBAAgB,gBAAgB;AA0BtC,MAAM,YAAY,gBAAgB;AAUlC,MAAM,uBAAuB,gBAAgB;AAY7C,MAAM,gBAAgB,gBAAgB;AAStC,MAAM,MAAM,gBAAgB;AAoB5B,MAAM,WAAW,gBAAgB;",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from "@wordpress/private-apis";
|
|
2
|
+
const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
3
|
+
"I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
|
|
4
|
+
"@wordpress/data"
|
|
5
|
+
);
|
|
6
|
+
export {
|
|
6
7
|
lock,
|
|
7
8
|
unlock
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=lock-unlock.js.map
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=lock-unlock.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lock-unlock.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/data'\n\t);\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,wDAAwD;AAE1D,MAAM,EAAE,MAAM,OAAO,IAC3B;AAAA,EACC;AAAA,EACA;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/plugins/index.js"],
|
|
4
|
+
"sourcesContent": ["export { default as persistence } from './persistence';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAA8B;",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|
|
@@ -1,82 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import deepmerge from 'deepmerge';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import defaultStorage from './storage/default';
|
|
11
|
-
import { combineReducers } from '../../';
|
|
12
|
-
|
|
13
|
-
/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */
|
|
14
|
-
|
|
15
|
-
/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options.
|
|
19
|
-
*
|
|
20
|
-
* @property {Storage} storage Persistent storage implementation. This must
|
|
21
|
-
* at least implement `getItem` and `setItem` of
|
|
22
|
-
* the Web Storage API.
|
|
23
|
-
* @property {string} storageKey Key on which to set in persistent storage.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Default plugin storage.
|
|
28
|
-
*
|
|
29
|
-
* @type {Storage}
|
|
30
|
-
*/
|
|
1
|
+
import { isPlainObject } from "is-plain-object";
|
|
2
|
+
import deepmerge from "deepmerge";
|
|
3
|
+
import defaultStorage from "./storage/default";
|
|
4
|
+
import { combineReducers } from "../../";
|
|
31
5
|
const DEFAULT_STORAGE = defaultStorage;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* Default plugin storage key.
|
|
35
|
-
*
|
|
36
|
-
* @type {string}
|
|
37
|
-
*/
|
|
38
|
-
const DEFAULT_STORAGE_KEY = 'WP_DATA';
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Higher-order reducer which invokes the original reducer only if state is
|
|
42
|
-
* inequal from that of the action's `nextState` property, otherwise returning
|
|
43
|
-
* the original state reference.
|
|
44
|
-
*
|
|
45
|
-
* @param {Function} reducer Original reducer.
|
|
46
|
-
*
|
|
47
|
-
* @return {Function} Enhanced reducer.
|
|
48
|
-
*/
|
|
49
|
-
export const withLazySameState = reducer => (state, action) => {
|
|
6
|
+
const DEFAULT_STORAGE_KEY = "WP_DATA";
|
|
7
|
+
const withLazySameState = (reducer) => (state, action) => {
|
|
50
8
|
if (action.nextState === state) {
|
|
51
9
|
return state;
|
|
52
10
|
}
|
|
53
11
|
return reducer(state, action);
|
|
54
12
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* Creates a persistence interface, exposing getter and setter methods (`get`
|
|
58
|
-
* and `set` respectively).
|
|
59
|
-
*
|
|
60
|
-
* @param {WPDataPersistencePluginOptions} options Plugin options.
|
|
61
|
-
*
|
|
62
|
-
* @return {Object} Persistence interface.
|
|
63
|
-
*/
|
|
64
|
-
export function createPersistenceInterface(options) {
|
|
65
|
-
const {
|
|
66
|
-
storage = DEFAULT_STORAGE,
|
|
67
|
-
storageKey = DEFAULT_STORAGE_KEY
|
|
68
|
-
} = options;
|
|
13
|
+
function createPersistenceInterface(options) {
|
|
14
|
+
const { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } = options;
|
|
69
15
|
let data;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Returns the persisted data as an object, defaulting to an empty object.
|
|
73
|
-
*
|
|
74
|
-
* @return {Object} Persisted data.
|
|
75
|
-
*/
|
|
76
16
|
function getData() {
|
|
77
|
-
if (data ===
|
|
78
|
-
// If unset, getItem is expected to return null. Fall back to
|
|
79
|
-
// empty object.
|
|
17
|
+
if (data === void 0) {
|
|
80
18
|
const persisted = storage.getItem(storageKey);
|
|
81
19
|
if (persisted === null) {
|
|
82
20
|
data = {};
|
|
@@ -84,26 +22,14 @@ export function createPersistenceInterface(options) {
|
|
|
84
22
|
try {
|
|
85
23
|
data = JSON.parse(persisted);
|
|
86
24
|
} catch (error) {
|
|
87
|
-
// Similarly, should any error be thrown during parse of
|
|
88
|
-
// the string (malformed JSON), fall back to empty object.
|
|
89
25
|
data = {};
|
|
90
26
|
}
|
|
91
27
|
}
|
|
92
28
|
}
|
|
93
29
|
return data;
|
|
94
30
|
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Merges an updated reducer state into the persisted data.
|
|
98
|
-
*
|
|
99
|
-
* @param {string} key Key to update.
|
|
100
|
-
* @param {*} value Updated value.
|
|
101
|
-
*/
|
|
102
31
|
function setData(key, value) {
|
|
103
|
-
data = {
|
|
104
|
-
...data,
|
|
105
|
-
[key]: value
|
|
106
|
-
};
|
|
32
|
+
data = { ...data, [key]: value };
|
|
107
33
|
storage.setItem(storageKey, JSON.stringify(data));
|
|
108
34
|
}
|
|
109
35
|
return {
|
|
@@ -111,44 +37,24 @@ export function createPersistenceInterface(options) {
|
|
|
111
37
|
set: setData
|
|
112
38
|
};
|
|
113
39
|
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Data plugin to persist store state into a single storage key.
|
|
117
|
-
*
|
|
118
|
-
* @param {WPDataRegistry} registry Data registry.
|
|
119
|
-
* @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.
|
|
120
|
-
*
|
|
121
|
-
* @return {WPDataPlugin} Data plugin.
|
|
122
|
-
*/
|
|
123
40
|
function persistencePlugin(registry, pluginOptions) {
|
|
124
41
|
const persistence = createPersistenceInterface(pluginOptions);
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Creates an enhanced store dispatch function, triggering the state of the
|
|
128
|
-
* given store name to be persisted when changed.
|
|
129
|
-
*
|
|
130
|
-
* @param {Function} getState Function which returns current state.
|
|
131
|
-
* @param {string} storeName Store name.
|
|
132
|
-
* @param {?Array<string>} keys Optional subset of keys to save.
|
|
133
|
-
*
|
|
134
|
-
* @return {Function} Enhanced dispatch function.
|
|
135
|
-
*/
|
|
136
42
|
function createPersistOnChange(getState, storeName, keys) {
|
|
137
43
|
let getPersistedState;
|
|
138
44
|
if (Array.isArray(keys)) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
45
|
+
const reducers = keys.reduce(
|
|
46
|
+
(accumulator, key) => Object.assign(accumulator, {
|
|
47
|
+
[key]: (state, action) => action.nextState[key]
|
|
48
|
+
}),
|
|
49
|
+
{}
|
|
50
|
+
);
|
|
51
|
+
getPersistedState = withLazySameState(
|
|
52
|
+
combineReducers(reducers)
|
|
53
|
+
);
|
|
148
54
|
} else {
|
|
149
55
|
getPersistedState = (state, action) => action.nextState;
|
|
150
56
|
}
|
|
151
|
-
let lastState = getPersistedState(
|
|
57
|
+
let lastState = getPersistedState(void 0, {
|
|
152
58
|
nextState: getState()
|
|
153
59
|
});
|
|
154
60
|
return () => {
|
|
@@ -166,25 +72,16 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
166
72
|
if (!options.persist) {
|
|
167
73
|
return registry.registerStore(storeName, options);
|
|
168
74
|
}
|
|
169
|
-
|
|
170
|
-
// Load from persistence to use as initial state.
|
|
171
75
|
const persistedState = persistence.get()[storeName];
|
|
172
|
-
if (persistedState !==
|
|
76
|
+
if (persistedState !== void 0) {
|
|
173
77
|
let initialState = options.reducer(options.initialState, {
|
|
174
|
-
type:
|
|
78
|
+
type: "@@WP/PERSISTENCE_RESTORE"
|
|
175
79
|
});
|
|
176
80
|
if (isPlainObject(initialState) && isPlainObject(persistedState)) {
|
|
177
|
-
// If state is an object, ensure that:
|
|
178
|
-
// - Other keys are left intact when persisting only a
|
|
179
|
-
// subset of keys.
|
|
180
|
-
// - New keys in what would otherwise be used as initial
|
|
181
|
-
// state are deeply merged as base for persisted value.
|
|
182
81
|
initialState = deepmerge(initialState, persistedState, {
|
|
183
82
|
isMergeableObject: isPlainObject
|
|
184
83
|
});
|
|
185
84
|
} else {
|
|
186
|
-
// If there is a mismatch in object-likeness of default
|
|
187
|
-
// initial or persisted state, defer to persisted value.
|
|
188
85
|
initialState = persistedState;
|
|
189
86
|
}
|
|
190
87
|
options = {
|
|
@@ -193,11 +90,23 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
193
90
|
};
|
|
194
91
|
}
|
|
195
92
|
const store = registry.registerStore(storeName, options);
|
|
196
|
-
store.subscribe(
|
|
93
|
+
store.subscribe(
|
|
94
|
+
createPersistOnChange(
|
|
95
|
+
store.getState,
|
|
96
|
+
storeName,
|
|
97
|
+
options.persist
|
|
98
|
+
)
|
|
99
|
+
);
|
|
197
100
|
return store;
|
|
198
101
|
}
|
|
199
102
|
};
|
|
200
103
|
}
|
|
201
|
-
persistencePlugin.__unstableMigrate = () => {
|
|
202
|
-
|
|
203
|
-
|
|
104
|
+
persistencePlugin.__unstableMigrate = () => {
|
|
105
|
+
};
|
|
106
|
+
var persistence_default = persistencePlugin;
|
|
107
|
+
export {
|
|
108
|
+
createPersistenceInterface,
|
|
109
|
+
persistence_default as default,
|
|
110
|
+
withLazySameState
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["isPlainObject","deepmerge","defaultStorage","combineReducers","DEFAULT_STORAGE","DEFAULT_STORAGE_KEY","withLazySameState","reducer","state","action","nextState","createPersistenceInterface","options","storage","storageKey","data","getData","undefined","persisted","getItem","JSON","parse","error","setData","key","value","setItem","stringify","get","set","persistencePlugin","registry","pluginOptions","persistence","createPersistOnChange","getState","storeName","keys","getPersistedState","Array","isArray","reducers","reduce","accumulator","Object","assign","lastState","registerStore","persist","persistedState","initialState","type","isMergeableObject","store","subscribe","__unstableMigrate"],"sources":["@wordpress/data/src/plugins/persistence/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\n\n/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */\n\n/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */\n\n/**\n * @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options.\n *\n * @property {Storage} storage Persistent storage implementation. This must\n * at least implement `getItem` and `setItem` of\n * the Web Storage API.\n * @property {string} storageKey Key on which to set in persistent storage.\n */\n\n/**\n * Default plugin storage.\n *\n * @type {Storage}\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n *\n * @type {string}\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param {Function} reducer Original reducer.\n *\n * @return {Function} Enhanced reducer.\n */\nexport const withLazySameState = ( reducer ) => ( state, action ) => {\n\tif ( action.nextState === state ) {\n\t\treturn state;\n\t}\n\n\treturn reducer( state, action );\n};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param {WPDataPersistencePluginOptions} options Plugin options.\n *\n * @return {Object} Persistence interface.\n */\nexport function createPersistenceInterface( options ) {\n\tconst { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions;\n\n\tlet data;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return {Object} Persisted data.\n\t */\n\tfunction getData() {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param {string} key Key to update.\n\t * @param {*} value Updated value.\n\t */\n\tfunction setData( key, value ) {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param {WPDataRegistry} registry Data registry.\n * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.\n *\n * @return {WPDataPlugin} Data plugin.\n */\nfunction persistencePlugin( registry, pluginOptions ) {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param {Function} getState Function which returns current state.\n\t * @param {string} storeName Store name.\n\t * @param {?Array<string>} keys Optional subset of keys to save.\n\t *\n\t * @return {Function} Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange( getState, storeName, keys ) {\n\t\tlet getPersistedState;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t( accumulator, key ) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: ( state, action ) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = ( state, action ) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore( storeName, options ) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = deepmerge( initialState, persistedState, {\n\t\t\t\t\t\tisMergeableObject: isPlainObject,\n\t\t\t\t\t} );\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\npersistencePlugin.__unstableMigrate = () => {};\n\nexport default persistencePlugin;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,QAAQ,iBAAiB;AAC/C,OAAOC,SAAS,MAAM,WAAW;;AAEjC;AACA;AACA;AACA,OAAOC,cAAc,MAAM,mBAAmB;AAC9C,SAASC,eAAe,QAAQ,QAAQ;;AAExC;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAMC,eAAe,GAAGF,cAAc;;AAEtC;AACA;AACA;AACA;AACA;AACA,MAAMG,mBAAmB,GAAG,SAAS;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,GAAKC,OAAO,IAAM,CAAEC,KAAK,EAAEC,MAAM,KAAM;EACpE,IAAKA,MAAM,CAACC,SAAS,KAAKF,KAAK,EAAG;IACjC,OAAOA,KAAK;EACb;EAEA,OAAOD,OAAO,CAAEC,KAAK,EAAEC,MAAO,CAAC;AAChC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,0BAA0BA,CAAEC,OAAO,EAAG;EACrD,MAAM;IAAEC,OAAO,GAAGT,eAAe;IAAEU,UAAU,GAAGT;EAAoB,CAAC,GACpEO,OAAO;EAER,IAAIG,IAAI;;EAER;AACD;AACA;AACA;AACA;EACC,SAASC,OAAOA,CAAA,EAAG;IAClB,IAAKD,IAAI,KAAKE,SAAS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Ac,EAAE;YACvDG,iBAAiB,EAAEpD;UACpB,CAAE,CAAC;QACJ,CAAC,MAAM;UACN;UACA;UACAkD,YAAY,GAAGD,cAAc;QAC9B;QAEArC,OAAO,GAAG;UACT,GAAGA,OAAO;UACVsC;QACD,CAAC;MACF;MAEA,MAAMG,KAAK,GAAGtB,QAAQ,CAACgB,aAAa,CAAEX,SAAS,EAAExB,OAAQ,CAAC;MAE1DyC,KAAK,CAACC,SAAS,CACdpB,qBAAqB,CACpBmB,KAAK,CAAClB,QAAQ,EACdC,SAAS,EACTxB,OAAO,CAACoC,OACT,CACD,CAAC;MAED,OAAOK,KAAK;IACb;EACD,CAAC;AACF;AAEAvB,iBAAiB,CAACyB,iBAAiB,GAAG,MAAM,CAAC,CAAC;AAE9C,eAAezB,iBAAiB","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/persistence/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\n\n/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */\n\n/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */\n\n/**\n * @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options.\n *\n * @property {Storage} storage Persistent storage implementation. This must\n * at least implement `getItem` and `setItem` of\n * the Web Storage API.\n * @property {string} storageKey Key on which to set in persistent storage.\n */\n\n/**\n * Default plugin storage.\n *\n * @type {Storage}\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n *\n * @type {string}\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param {Function} reducer Original reducer.\n *\n * @return {Function} Enhanced reducer.\n */\nexport const withLazySameState = ( reducer ) => ( state, action ) => {\n\tif ( action.nextState === state ) {\n\t\treturn state;\n\t}\n\n\treturn reducer( state, action );\n};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param {WPDataPersistencePluginOptions} options Plugin options.\n *\n * @return {Object} Persistence interface.\n */\nexport function createPersistenceInterface( options ) {\n\tconst { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions;\n\n\tlet data;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return {Object} Persisted data.\n\t */\n\tfunction getData() {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param {string} key Key to update.\n\t * @param {*} value Updated value.\n\t */\n\tfunction setData( key, value ) {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param {WPDataRegistry} registry Data registry.\n * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.\n *\n * @return {WPDataPlugin} Data plugin.\n */\nfunction persistencePlugin( registry, pluginOptions ) {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param {Function} getState Function which returns current state.\n\t * @param {string} storeName Store name.\n\t * @param {?Array<string>} keys Optional subset of keys to save.\n\t *\n\t * @return {Function} Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange( getState, storeName, keys ) {\n\t\tlet getPersistedState;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t( accumulator, key ) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: ( state, action ) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = ( state, action ) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore( storeName, options ) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = deepmerge( initialState, persistedState, {\n\t\t\t\t\t\tisMergeableObject: isPlainObject,\n\t\t\t\t\t} );\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\npersistencePlugin.__unstableMigrate = () => {};\n\nexport default persistencePlugin;\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,qBAAqB;AAC9B,OAAO,eAAe;AAKtB,OAAO,oBAAoB;AAC3B,SAAS,uBAAuB;AAoBhC,MAAM,kBAAkB;AAOxB,MAAM,sBAAsB;AAWrB,MAAM,oBAAoB,CAAE,YAAa,CAAE,OAAO,WAAY;AACpE,MAAK,OAAO,cAAc,OAAQ;AACjC,WAAO;AAAA,EACR;AAEA,SAAO,QAAS,OAAO,MAAO;AAC/B;AAUO,SAAS,2BAA4B,SAAU;AACrD,QAAM,EAAE,UAAU,iBAAiB,aAAa,oBAAoB,IACnE;AAED,MAAI;AAOJ,WAAS,UAAU;AAClB,QAAK,SAAS,QAAY;AAGzB,YAAM,YAAY,QAAQ,QAAS,UAA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