@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
|
@@ -1,91 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var persistence_exports = {};
|
|
30
|
+
__export(persistence_exports, {
|
|
31
|
+
createPersistenceInterface: () => createPersistenceInterface,
|
|
32
|
+
default: () => persistence_default,
|
|
33
|
+
withLazySameState: () => withLazySameState
|
|
6
34
|
});
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Internal dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */
|
|
22
|
-
|
|
23
|
-
/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options.
|
|
27
|
-
*
|
|
28
|
-
* @property {Storage} storage Persistent storage implementation. This must
|
|
29
|
-
* at least implement `getItem` and `setItem` of
|
|
30
|
-
* the Web Storage API.
|
|
31
|
-
* @property {string} storageKey Key on which to set in persistent storage.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Default plugin storage.
|
|
36
|
-
*
|
|
37
|
-
* @type {Storage}
|
|
38
|
-
*/
|
|
39
|
-
const DEFAULT_STORAGE = _default2.default;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Default plugin storage key.
|
|
43
|
-
*
|
|
44
|
-
* @type {string}
|
|
45
|
-
*/
|
|
46
|
-
const DEFAULT_STORAGE_KEY = 'WP_DATA';
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Higher-order reducer which invokes the original reducer only if state is
|
|
50
|
-
* inequal from that of the action's `nextState` property, otherwise returning
|
|
51
|
-
* the original state reference.
|
|
52
|
-
*
|
|
53
|
-
* @param {Function} reducer Original reducer.
|
|
54
|
-
*
|
|
55
|
-
* @return {Function} Enhanced reducer.
|
|
56
|
-
*/
|
|
57
|
-
const withLazySameState = reducer => (state, action) => {
|
|
35
|
+
module.exports = __toCommonJS(persistence_exports);
|
|
36
|
+
var import_is_plain_object = require("is-plain-object");
|
|
37
|
+
var import_deepmerge = __toESM(require("deepmerge"));
|
|
38
|
+
var import_default = __toESM(require("./storage/default"));
|
|
39
|
+
var import__ = require("../../");
|
|
40
|
+
const DEFAULT_STORAGE = import_default.default;
|
|
41
|
+
const DEFAULT_STORAGE_KEY = "WP_DATA";
|
|
42
|
+
const withLazySameState = (reducer) => (state, action) => {
|
|
58
43
|
if (action.nextState === state) {
|
|
59
44
|
return state;
|
|
60
45
|
}
|
|
61
46
|
return reducer(state, action);
|
|
62
47
|
};
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Creates a persistence interface, exposing getter and setter methods (`get`
|
|
66
|
-
* and `set` respectively).
|
|
67
|
-
*
|
|
68
|
-
* @param {WPDataPersistencePluginOptions} options Plugin options.
|
|
69
|
-
*
|
|
70
|
-
* @return {Object} Persistence interface.
|
|
71
|
-
*/
|
|
72
|
-
exports.withLazySameState = withLazySameState;
|
|
73
48
|
function createPersistenceInterface(options) {
|
|
74
|
-
const {
|
|
75
|
-
storage = DEFAULT_STORAGE,
|
|
76
|
-
storageKey = DEFAULT_STORAGE_KEY
|
|
77
|
-
} = options;
|
|
49
|
+
const { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } = options;
|
|
78
50
|
let data;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Returns the persisted data as an object, defaulting to an empty object.
|
|
82
|
-
*
|
|
83
|
-
* @return {Object} Persisted data.
|
|
84
|
-
*/
|
|
85
51
|
function getData() {
|
|
86
|
-
if (data ===
|
|
87
|
-
// If unset, getItem is expected to return null. Fall back to
|
|
88
|
-
// empty object.
|
|
52
|
+
if (data === void 0) {
|
|
89
53
|
const persisted = storage.getItem(storageKey);
|
|
90
54
|
if (persisted === null) {
|
|
91
55
|
data = {};
|
|
@@ -93,26 +57,14 @@ function createPersistenceInterface(options) {
|
|
|
93
57
|
try {
|
|
94
58
|
data = JSON.parse(persisted);
|
|
95
59
|
} catch (error) {
|
|
96
|
-
// Similarly, should any error be thrown during parse of
|
|
97
|
-
// the string (malformed JSON), fall back to empty object.
|
|
98
60
|
data = {};
|
|
99
61
|
}
|
|
100
62
|
}
|
|
101
63
|
}
|
|
102
64
|
return data;
|
|
103
65
|
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Merges an updated reducer state into the persisted data.
|
|
107
|
-
*
|
|
108
|
-
* @param {string} key Key to update.
|
|
109
|
-
* @param {*} value Updated value.
|
|
110
|
-
*/
|
|
111
66
|
function setData(key, value) {
|
|
112
|
-
data = {
|
|
113
|
-
...data,
|
|
114
|
-
[key]: value
|
|
115
|
-
};
|
|
67
|
+
data = { ...data, [key]: value };
|
|
116
68
|
storage.setItem(storageKey, JSON.stringify(data));
|
|
117
69
|
}
|
|
118
70
|
return {
|
|
@@ -120,44 +72,24 @@ function createPersistenceInterface(options) {
|
|
|
120
72
|
set: setData
|
|
121
73
|
};
|
|
122
74
|
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Data plugin to persist store state into a single storage key.
|
|
126
|
-
*
|
|
127
|
-
* @param {WPDataRegistry} registry Data registry.
|
|
128
|
-
* @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.
|
|
129
|
-
*
|
|
130
|
-
* @return {WPDataPlugin} Data plugin.
|
|
131
|
-
*/
|
|
132
75
|
function persistencePlugin(registry, pluginOptions) {
|
|
133
76
|
const persistence = createPersistenceInterface(pluginOptions);
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Creates an enhanced store dispatch function, triggering the state of the
|
|
137
|
-
* given store name to be persisted when changed.
|
|
138
|
-
*
|
|
139
|
-
* @param {Function} getState Function which returns current state.
|
|
140
|
-
* @param {string} storeName Store name.
|
|
141
|
-
* @param {?Array<string>} keys Optional subset of keys to save.
|
|
142
|
-
*
|
|
143
|
-
* @return {Function} Enhanced dispatch function.
|
|
144
|
-
*/
|
|
145
77
|
function createPersistOnChange(getState, storeName, keys) {
|
|
146
78
|
let getPersistedState;
|
|
147
79
|
if (Array.isArray(keys)) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
80
|
+
const reducers = keys.reduce(
|
|
81
|
+
(accumulator, key) => Object.assign(accumulator, {
|
|
82
|
+
[key]: (state, action) => action.nextState[key]
|
|
83
|
+
}),
|
|
84
|
+
{}
|
|
85
|
+
);
|
|
86
|
+
getPersistedState = withLazySameState(
|
|
87
|
+
(0, import__.combineReducers)(reducers)
|
|
88
|
+
);
|
|
157
89
|
} else {
|
|
158
90
|
getPersistedState = (state, action) => action.nextState;
|
|
159
91
|
}
|
|
160
|
-
let lastState = getPersistedState(
|
|
92
|
+
let lastState = getPersistedState(void 0, {
|
|
161
93
|
nextState: getState()
|
|
162
94
|
});
|
|
163
95
|
return () => {
|
|
@@ -175,25 +107,16 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
175
107
|
if (!options.persist) {
|
|
176
108
|
return registry.registerStore(storeName, options);
|
|
177
109
|
}
|
|
178
|
-
|
|
179
|
-
// Load from persistence to use as initial state.
|
|
180
110
|
const persistedState = persistence.get()[storeName];
|
|
181
|
-
if (persistedState !==
|
|
111
|
+
if (persistedState !== void 0) {
|
|
182
112
|
let initialState = options.reducer(options.initialState, {
|
|
183
|
-
type:
|
|
113
|
+
type: "@@WP/PERSISTENCE_RESTORE"
|
|
184
114
|
});
|
|
185
|
-
if ((0,
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
// subset of keys.
|
|
189
|
-
// - New keys in what would otherwise be used as initial
|
|
190
|
-
// state are deeply merged as base for persisted value.
|
|
191
|
-
initialState = (0, _deepmerge.default)(initialState, persistedState, {
|
|
192
|
-
isMergeableObject: _isPlainObject.isPlainObject
|
|
115
|
+
if ((0, import_is_plain_object.isPlainObject)(initialState) && (0, import_is_plain_object.isPlainObject)(persistedState)) {
|
|
116
|
+
initialState = (0, import_deepmerge.default)(initialState, persistedState, {
|
|
117
|
+
isMergeableObject: import_is_plain_object.isPlainObject
|
|
193
118
|
});
|
|
194
119
|
} else {
|
|
195
|
-
// If there is a mismatch in object-likeness of default
|
|
196
|
-
// initial or persisted state, defer to persisted value.
|
|
197
120
|
initialState = persistedState;
|
|
198
121
|
}
|
|
199
122
|
options = {
|
|
@@ -202,11 +125,23 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
202
125
|
};
|
|
203
126
|
}
|
|
204
127
|
const store = registry.registerStore(storeName, options);
|
|
205
|
-
store.subscribe(
|
|
128
|
+
store.subscribe(
|
|
129
|
+
createPersistOnChange(
|
|
130
|
+
store.getState,
|
|
131
|
+
storeName,
|
|
132
|
+
options.persist
|
|
133
|
+
)
|
|
134
|
+
);
|
|
206
135
|
return store;
|
|
207
136
|
}
|
|
208
137
|
};
|
|
209
138
|
}
|
|
210
|
-
persistencePlugin.__unstableMigrate = () => {
|
|
211
|
-
|
|
212
|
-
|
|
139
|
+
persistencePlugin.__unstableMigrate = () => {
|
|
140
|
+
};
|
|
141
|
+
var persistence_default = persistencePlugin;
|
|
142
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
143
|
+
0 && (module.exports = {
|
|
144
|
+
createPersistenceInterface,
|
|
145
|
+
withLazySameState
|
|
146
|
+
});
|
|
147
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["_isPlainObject","require","_deepmerge","_interopRequireDefault","_default2","_","DEFAULT_STORAGE","defaultStorage","DEFAULT_STORAGE_KEY","withLazySameState","reducer","state","action","nextState","exports","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","combineReducers","lastState","registerStore","persist","persistedState","initialState","type","isPlainObject","deepmerge","isMergeableObject","store","subscribe","__unstableMigrate","_default","default"],"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":";;;;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AAKA,IAAAG,SAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,CAAA,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1B,iBAAiB,CAAC4B,iBAAiB,GAAG,MAAM,CAAC,CAAC;AAAC,IAAAC,QAAA,GAAAjD,OAAA,CAAAkD,OAAA,GAEhC9B,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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,6BAA8B;AAC9B,uBAAsB;AAKtB,qBAA2B;AAC3B,eAAgC;AAoBhC,MAAM,kBAAkB,eAAAA;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,UAAW;AAC9C,UAAK,cAAc,MAAO;AACzB,eAAO,CAAC;AAAA,MACT,OAAO;AACN,YAAI;AACH,iBAAO,KAAK,MAAO,SAAU;AAAA,QAC9B,SAAU,OAAQ;AAGjB,iBAAO,CAAC;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAQA,WAAS,QAAS,KAAK,OAAQ;AAC9B,WAAO,EAAE,GAAG,MAAM,CAAE,GAAI,GAAG,MAAM;AACjC,YAAQ,QAAS,YA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B,CAAE;AAAA,QACH,OAAO;AAGN,yBAAe;AAAA,QAChB;AAEA,kBAAU;AAAA,UACT,GAAG;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAEA,YAAM,QAAQ,SAAS,cAAe,WAAW,OAAQ;AAEzD,YAAM;AAAA,QACL;AAAA,UACC,MAAM;AAAA,UACN;AAAA,UACA,QAAQ;AAAA,QACT;AAAA,MACD;AAEA,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEA,kBAAkB,oBAAoB,MAAM;AAAC;AAE7C,IAAO,sBAAQ;",
|
|
6
|
+
"names": ["defaultStorage", "deepmerge"]
|
|
7
|
+
}
|
|
@@ -1,25 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var default_exports = {};
|
|
30
|
+
__export(default_exports, {
|
|
31
|
+
default: () => default_default
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
/**
|
|
10
|
-
* Internal dependencies
|
|
11
|
-
*/
|
|
12
|
-
|
|
33
|
+
module.exports = __toCommonJS(default_exports);
|
|
34
|
+
var import_object = __toESM(require("./object"));
|
|
13
35
|
let storage;
|
|
14
36
|
try {
|
|
15
|
-
// Private Browsing in Safari 10 and earlier will throw an error when
|
|
16
|
-
// attempting to set into localStorage. The test here is intentional in
|
|
17
|
-
// causing a thrown error as condition for using fallback object storage.
|
|
18
37
|
storage = window.localStorage;
|
|
19
|
-
storage.setItem(
|
|
20
|
-
storage.removeItem(
|
|
38
|
+
storage.setItem("__wpDataTestLocalStorage", "");
|
|
39
|
+
storage.removeItem("__wpDataTestLocalStorage");
|
|
21
40
|
} catch (error) {
|
|
22
|
-
storage =
|
|
41
|
+
storage = import_object.default;
|
|
23
42
|
}
|
|
24
|
-
var
|
|
25
|
-
//# sourceMappingURL=default.js.map
|
|
43
|
+
var default_default = storage;
|
|
44
|
+
//# sourceMappingURL=default.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/plugins/persistence/storage/default.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport objectStorage from './object';\n\nlet storage;\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem( '__wpDataTestLocalStorage' );\n} catch ( error ) {\n\tstorage = objectStorage;\n}\n\nexport default storage;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA0B;AAE1B,IAAI;AAEJ,IAAI;AAIH,YAAU,OAAO;AACjB,UAAQ,QAAS,4BAA4B,EAAG;AAChD,UAAQ,WAAY,0BAA2B;AAChD,SAAU,OAAQ;AACjB,YAAU,cAAAA;AACX;AAEA,IAAO,kBAAQ;",
|
|
6
|
+
"names": ["objectStorage"]
|
|
7
|
+
}
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var object_exports = {};
|
|
20
|
+
__export(object_exports, {
|
|
21
|
+
default: () => object_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
23
|
+
module.exports = __toCommonJS(object_exports);
|
|
7
24
|
let objectStorage;
|
|
8
25
|
const storage = {
|
|
9
26
|
getItem(key) {
|
|
@@ -19,8 +36,8 @@ const storage = {
|
|
|
19
36
|
objectStorage[key] = String(value);
|
|
20
37
|
},
|
|
21
38
|
clear() {
|
|
22
|
-
objectStorage = Object.create(null);
|
|
39
|
+
objectStorage = /* @__PURE__ */ Object.create(null);
|
|
23
40
|
}
|
|
24
41
|
};
|
|
25
|
-
var
|
|
26
|
-
//# sourceMappingURL=object.js.map
|
|
42
|
+
var object_default = storage;
|
|
43
|
+
//# sourceMappingURL=object.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/plugins/persistence/storage/object.js"],
|
|
4
|
+
"sourcesContent": ["let objectStorage;\n\nconst storage = {\n\tgetItem( key ) {\n\t\tif ( ! objectStorage || ! objectStorage[ key ] ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn objectStorage[ key ];\n\t},\n\tsetItem( key, value ) {\n\t\tif ( ! objectStorage ) {\n\t\t\tstorage.clear();\n\t\t}\n\n\t\tobjectStorage[ key ] = String( value );\n\t},\n\tclear() {\n\t\tobjectStorage = Object.create( null );\n\t},\n};\n\nexport default storage;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAI;AAEJ,MAAM,UAAU;AAAA,EACf,QAAS,KAAM;AACd,QAAK,CAAE,iBAAiB,CAAE,cAAe,GAAI,GAAI;AAChD,aAAO;AAAA,IACR;AAEA,WAAO,cAAe,GAAI;AAAA,EAC3B;AAAA,EACA,QAAS,KAAK,OAAQ;AACrB,QAAK,CAAE,eAAgB;AACtB,cAAQ,MAAM;AAAA,IACf;AAEA,kBAAe,GAAI,IAAI,OAAQ,KAAM;AAAA,EACtC;AAAA,EACA,QAAQ;AACP,oBAAgB,uBAAO,OAAQ,IAAK;AAAA,EACrC;AACD;AAEA,IAAO,iBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,23 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var promise_middleware_exports = {};
|
|
30
|
+
__export(promise_middleware_exports, {
|
|
31
|
+
default: () => promise_middleware_default
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Simplest possible promise redux middleware.
|
|
15
|
-
*
|
|
16
|
-
* @type {import('redux').Middleware}
|
|
17
|
-
*/
|
|
18
|
-
const promiseMiddleware = () => next => action => {
|
|
19
|
-
if ((0, _isPromise.default)(action)) {
|
|
20
|
-
return action.then(resolvedAction => {
|
|
33
|
+
module.exports = __toCommonJS(promise_middleware_exports);
|
|
34
|
+
var import_is_promise = __toESM(require("is-promise"));
|
|
35
|
+
const promiseMiddleware = () => (next) => (action) => {
|
|
36
|
+
if ((0, import_is_promise.default)(action)) {
|
|
37
|
+
return action.then((resolvedAction) => {
|
|
21
38
|
if (resolvedAction) {
|
|
22
39
|
return next(resolvedAction);
|
|
23
40
|
}
|
|
@@ -25,5 +42,5 @@ const promiseMiddleware = () => next => action => {
|
|
|
25
42
|
}
|
|
26
43
|
return next(action);
|
|
27
44
|
};
|
|
28
|
-
var
|
|
29
|
-
//# sourceMappingURL=promise-middleware.js.map
|
|
45
|
+
var promise_middleware_default = promiseMiddleware;
|
|
46
|
+
//# sourceMappingURL=promise-middleware.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/promise-middleware.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport isPromise from 'is-promise';\n\n/**\n * Simplest possible promise redux middleware.\n *\n * @type {import('redux').Middleware}\n */\nconst promiseMiddleware = () => ( next ) => ( action ) => {\n\tif ( isPromise( action ) ) {\n\t\treturn action.then( ( resolvedAction ) => {\n\t\t\tif ( resolvedAction ) {\n\t\t\t\treturn next( resolvedAction );\n\t\t\t}\n\t\t} );\n\t}\n\n\treturn next( action );\n};\n\nexport default promiseMiddleware;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAsB;AAOtB,MAAM,oBAAoB,MAAM,CAAE,SAAU,CAAE,WAAY;AACzD,UAAK,kBAAAA,SAAW,MAAO,GAAI;AAC1B,WAAO,OAAO,KAAM,CAAE,mBAAoB;AACzC,UAAK,gBAAiB;AACrB,eAAO,KAAM,cAAe;AAAA,MAC7B;AAAA,IACD,CAAE;AAAA,EACH;AAEA,SAAO,KAAM,MAAO;AACrB;AAEA,IAAO,6BAAQ;",
|
|
6
|
+
"names": ["isPromise"]
|
|
7
|
+
}
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var combine_reducers_exports = {};
|
|
20
|
+
__export(combine_reducers_exports, {
|
|
21
|
+
combineReducers: () => combineReducers
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
23
|
+
module.exports = __toCommonJS(combine_reducers_exports);
|
|
7
24
|
function combineReducers(reducers) {
|
|
8
25
|
const keys = Object.keys(reducers);
|
|
9
26
|
return function combinedReducer(state = {}, action) {
|
|
@@ -19,4 +36,8 @@ function combineReducers(reducers) {
|
|
|
19
36
|
return hasChanged ? nextState : state;
|
|
20
37
|
};
|
|
21
38
|
}
|
|
22
|
-
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
combineReducers
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=combine-reducers.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/redux-store/combine-reducers.js"],
|
|
4
|
+
"sourcesContent": ["export function combineReducers( reducers ) {\n\tconst keys = Object.keys( reducers );\n\n\treturn function combinedReducer( state = {}, action ) {\n\t\tconst nextState = {};\n\t\tlet hasChanged = false;\n\t\tfor ( const key of keys ) {\n\t\t\tconst reducer = reducers[ key ];\n\t\t\tconst prevStateForKey = state[ key ];\n\t\t\tconst nextStateForKey = reducer( prevStateForKey, action );\n\t\t\tnextState[ key ] = nextStateForKey;\n\t\t\thasChanged = hasChanged || nextStateForKey !== prevStateForKey;\n\t\t}\n\n\t\treturn hasChanged ? nextState : state;\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,gBAAiB,UAAW;AAC3C,QAAM,OAAO,OAAO,KAAM,QAAS;AAEnC,SAAO,SAAS,gBAAiB,QAAQ,CAAC,GAAG,QAAS;AACrD,UAAM,YAAY,CAAC;AACnB,QAAI,aAAa;AACjB,eAAY,OAAO,MAAO;AACzB,YAAM,UAAU,SAAU,GAAI;AAC9B,YAAM,kBAAkB,MAAO,GAAI;AACnC,YAAM,kBAAkB,QAAS,iBAAiB,MAAO;AACzD,gBAAW,GAAI,IAAI;AACnB,mBAAa,cAAc,oBAAoB;AAAA,IAChD;AAEA,WAAO,aAAa,YAAY;AAAA,EACjC;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|