@wordpress/data 10.41.0 → 10.41.1-next.v.202603102151.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/README.md +20 -28
- package/build/components/async-mode-provider/context.cjs +1 -1
- package/build/components/async-mode-provider/context.cjs.map +3 -3
- package/build/components/async-mode-provider/index.cjs +1 -1
- package/build/components/async-mode-provider/index.cjs.map +1 -1
- package/build/components/async-mode-provider/use-async-mode.cjs +1 -1
- package/build/components/async-mode-provider/use-async-mode.cjs.map +3 -3
- package/build/components/registry-provider/context.cjs +1 -1
- package/build/components/registry-provider/context.cjs.map +1 -1
- package/build/components/registry-provider/index.cjs +1 -1
- package/build/components/registry-provider/index.cjs.map +1 -1
- package/build/components/registry-provider/use-registry.cjs +1 -1
- package/build/components/registry-provider/use-registry.cjs.map +3 -3
- package/build/components/use-dispatch/index.cjs +1 -1
- package/build/components/use-dispatch/index.cjs.map +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.cjs +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.cjs.map +3 -3
- package/build/components/use-dispatch/use-dispatch.cjs +1 -1
- package/build/components/use-dispatch/use-dispatch.cjs.map +3 -3
- package/build/components/use-select/index.cjs +2 -2
- package/build/components/use-select/index.cjs.map +3 -3
- package/build/components/with-dispatch/index.cjs +1 -1
- package/build/components/with-dispatch/index.cjs.map +3 -3
- package/build/components/with-registry/index.cjs +1 -1
- package/build/components/with-registry/index.cjs.map +3 -3
- package/build/components/with-select/index.cjs +1 -1
- package/build/components/with-select/index.cjs.map +3 -3
- package/build/controls.cjs +7 -6
- package/build/controls.cjs.map +3 -3
- package/build/default-registry.cjs +3 -2
- package/build/default-registry.cjs.map +3 -3
- package/build/dispatch.cjs +3 -1
- package/build/dispatch.cjs.map +2 -2
- package/build/factory.cjs.map +2 -2
- package/build/index.cjs +9 -8
- package/build/index.cjs.map +3 -3
- package/build/plugins/index.cjs +1 -1
- package/build/plugins/index.cjs.map +1 -1
- package/build/plugins/persistence/index.cjs +13 -8
- package/build/plugins/persistence/index.cjs.map +3 -3
- package/build/plugins/persistence/storage/default.cjs +1 -1
- package/build/plugins/persistence/storage/default.cjs.map +3 -3
- package/build/plugins/persistence/storage/object.cjs +1 -1
- package/build/plugins/persistence/storage/object.cjs.map +3 -3
- package/build/promise-middleware.cjs +2 -1
- package/build/promise-middleware.cjs.map +3 -3
- package/build/redux-store/index.cjs +32 -16
- package/build/redux-store/index.cjs.map +3 -3
- package/build/redux-store/metadata/selectors.cjs +1 -1
- package/build/redux-store/metadata/selectors.cjs.map +3 -3
- package/build/redux-store/metadata/types.cjs +19 -0
- package/build/redux-store/metadata/types.cjs.map +7 -0
- package/build/registry.cjs +11 -7
- package/build/registry.cjs.map +3 -3
- package/build/resolvers-cache-middleware.cjs +6 -3
- package/build/resolvers-cache-middleware.cjs.map +3 -3
- package/build/select.cjs +3 -1
- package/build/select.cjs.map +2 -2
- package/build/store/index.cjs +1 -1
- package/build/store/index.cjs.map +3 -3
- package/build/types.cjs.map +1 -1
- package/build-module/components/async-mode-provider/context.mjs +1 -1
- package/build-module/components/async-mode-provider/context.mjs.map +3 -3
- package/build-module/components/async-mode-provider/index.mjs +1 -1
- package/build-module/components/async-mode-provider/index.mjs.map +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.mjs +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.mjs.map +3 -3
- package/build-module/components/registry-provider/context.mjs +1 -1
- package/build-module/components/registry-provider/context.mjs.map +1 -1
- package/build-module/components/registry-provider/index.mjs +1 -1
- package/build-module/components/registry-provider/index.mjs.map +1 -1
- package/build-module/components/registry-provider/use-registry.mjs +1 -1
- package/build-module/components/registry-provider/use-registry.mjs.map +3 -3
- package/build-module/components/use-dispatch/index.mjs +1 -1
- package/build-module/components/use-dispatch/index.mjs.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.mjs +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.mjs.map +3 -3
- package/build-module/components/use-dispatch/use-dispatch.mjs +1 -1
- package/build-module/components/use-dispatch/use-dispatch.mjs.map +3 -3
- package/build-module/components/use-select/index.mjs +2 -2
- package/build-module/components/use-select/index.mjs.map +3 -3
- package/build-module/components/with-dispatch/index.mjs +1 -1
- package/build-module/components/with-dispatch/index.mjs.map +3 -3
- package/build-module/components/with-registry/index.mjs +1 -1
- package/build-module/components/with-registry/index.mjs.map +3 -3
- package/build-module/components/with-select/index.mjs +1 -1
- package/build-module/components/with-select/index.mjs.map +3 -3
- package/build-module/controls.mjs +7 -6
- package/build-module/controls.mjs.map +3 -3
- package/build-module/default-registry.mjs +3 -2
- package/build-module/default-registry.mjs.map +3 -3
- package/build-module/dispatch.mjs +3 -1
- package/build-module/dispatch.mjs.map +2 -2
- package/build-module/factory.mjs.map +2 -2
- package/build-module/index.mjs +4 -3
- package/build-module/index.mjs.map +2 -2
- package/build-module/plugins/index.mjs +1 -1
- package/build-module/plugins/index.mjs.map +1 -1
- package/build-module/plugins/persistence/index.mjs +13 -8
- package/build-module/plugins/persistence/index.mjs.map +3 -3
- package/build-module/plugins/persistence/storage/default.mjs +1 -1
- package/build-module/plugins/persistence/storage/default.mjs.map +3 -3
- package/build-module/plugins/persistence/storage/object.mjs +1 -1
- package/build-module/plugins/persistence/storage/object.mjs.map +3 -3
- package/build-module/promise-middleware.mjs +2 -1
- package/build-module/promise-middleware.mjs.map +3 -3
- package/build-module/redux-store/index.mjs +32 -16
- package/build-module/redux-store/index.mjs.map +3 -3
- package/build-module/redux-store/metadata/selectors.mjs +1 -1
- package/build-module/redux-store/metadata/selectors.mjs.map +3 -3
- package/build-module/redux-store/metadata/types.mjs +1 -0
- package/build-module/redux-store/metadata/types.mjs.map +7 -0
- package/build-module/registry.mjs +11 -7
- package/build-module/registry.mjs.map +3 -3
- package/build-module/resolvers-cache-middleware.mjs +6 -3
- package/build-module/resolvers-cache-middleware.mjs.map +3 -3
- package/build-module/select.mjs +3 -1
- package/build-module/select.mjs.map +2 -2
- package/build-module/store/index.mjs +1 -1
- package/build-module/store/index.mjs.map +3 -3
- package/build-types/components/async-mode-provider/context.d.ts +37 -3
- package/build-types/components/async-mode-provider/context.d.ts.map +1 -1
- package/build-types/components/async-mode-provider/index.d.ts +2 -2
- package/build-types/components/async-mode-provider/index.d.ts.map +1 -1
- package/build-types/components/async-mode-provider/use-async-mode.d.ts.map +1 -1
- package/build-types/components/registry-provider/context.d.ts +10 -3
- package/build-types/components/registry-provider/context.d.ts.map +1 -1
- package/build-types/components/registry-provider/index.d.ts +2 -2
- package/build-types/components/registry-provider/index.d.ts.map +1 -1
- package/build-types/components/registry-provider/use-registry.d.ts +3 -2
- package/build-types/components/registry-provider/use-registry.d.ts.map +1 -1
- package/build-types/components/use-dispatch/index.d.ts +2 -2
- package/build-types/components/use-dispatch/index.d.ts.map +1 -1
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts +11 -9
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts.map +1 -1
- package/build-types/components/use-dispatch/use-dispatch.d.ts +10 -19
- package/build-types/components/use-dispatch/use-dispatch.d.ts.map +1 -1
- package/build-types/components/use-select/index.d.ts +24 -28
- package/build-types/components/use-select/index.d.ts.map +1 -1
- package/build-types/components/with-dispatch/index.d.ts +10 -11
- package/build-types/components/with-dispatch/index.d.ts.map +1 -1
- package/build-types/components/with-registry/index.d.ts +2 -6
- package/build-types/components/with-registry/index.d.ts.map +1 -1
- package/build-types/components/with-select/index.d.ts +7 -8
- package/build-types/components/with-select/index.d.ts.map +1 -1
- package/build-types/controls.d.ts +57 -44
- package/build-types/controls.d.ts.map +1 -1
- package/build-types/default-registry.d.ts +2 -2
- package/build-types/default-registry.d.ts.map +1 -1
- package/build-types/dispatch.d.ts +4 -0
- package/build-types/dispatch.d.ts.map +1 -1
- package/build-types/factory.d.ts +2 -1
- package/build-types/factory.d.ts.map +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/plugins/index.d.ts +1 -1
- package/build-types/plugins/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/index.d.ts +38 -27
- package/build-types/plugins/persistence/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/storage/default.d.ts +7 -1
- package/build-types/plugins/persistence/storage/default.d.ts.map +1 -1
- package/build-types/plugins/persistence/storage/object.d.ts +4 -5
- package/build-types/plugins/persistence/storage/object.d.ts.map +1 -1
- package/build-types/promise-middleware.d.ts +6 -4
- package/build-types/promise-middleware.d.ts.map +1 -1
- package/build-types/redux-store/index.d.ts +12 -15
- package/build-types/redux-store/index.d.ts.map +1 -1
- package/build-types/redux-store/metadata/selectors.d.ts +45 -50
- package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
- package/build-types/redux-store/metadata/types.d.ts +48 -0
- package/build-types/redux-store/metadata/types.d.ts.map +1 -0
- package/build-types/registry.d.ts +5 -49
- package/build-types/registry.d.ts.map +1 -1
- package/build-types/resolvers-cache-middleware.d.ts +13 -7
- package/build-types/resolvers-cache-middleware.d.ts.map +1 -1
- package/build-types/select.d.ts +3 -0
- package/build-types/select.d.ts.map +1 -1
- package/build-types/store/index.d.ts +5 -12
- package/build-types/store/index.d.ts.map +1 -1
- package/build-types/types.d.ts +201 -10
- package/build-types/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/components/async-mode-provider/{context.js → context.ts} +0 -1
- package/src/components/async-mode-provider/{use-async-mode.js → use-async-mode.ts} +1 -1
- package/src/components/registry-provider/{use-registry.js → use-registry.ts} +3 -2
- package/src/components/use-dispatch/{use-dispatch-with-map.js → use-dispatch-with-map.ts} +18 -9
- package/src/components/use-dispatch/{use-dispatch.js → use-dispatch.ts} +25 -20
- package/src/components/use-select/{index.js → index.ts} +84 -70
- package/src/components/with-dispatch/{index.js → index.tsx} +20 -13
- package/src/components/with-registry/{index.js → index.tsx} +1 -5
- package/src/components/with-select/{index.js → index.tsx} +17 -10
- package/src/{controls.js → controls.ts} +53 -26
- package/src/{default-registry.js → default-registry.ts} +3 -1
- package/src/dispatch.ts +7 -1
- package/src/factory.ts +4 -3
- package/src/index.ts +4 -8
- package/src/plugins/persistence/{index.js → index.ts} +93 -54
- package/src/plugins/persistence/storage/{default.js → default.ts} +3 -2
- package/src/plugins/persistence/storage/object.ts +25 -0
- package/src/{promise-middleware.js → promise-middleware.ts} +3 -3
- package/src/redux-store/{index.js → index.ts} +218 -131
- package/src/redux-store/metadata/{selectors.js → selectors.ts} +83 -54
- package/src/redux-store/metadata/types.ts +100 -0
- package/src/{registry.js → registry.ts} +98 -88
- package/src/{resolvers-cache-middleware.js → resolvers-cache-middleware.ts} +22 -7
- package/src/select.ts +6 -1
- package/src/store/{index.js → index.ts} +13 -8
- package/src/types.ts +263 -24
- package/src/plugins/persistence/storage/object.js +0 -23
- /package/src/components/async-mode-provider/{index.js → index.ts} +0 -0
- /package/src/components/registry-provider/{context.js → context.ts} +0 -0
- /package/src/components/registry-provider/{index.js → index.ts} +0 -0
- /package/src/components/use-dispatch/{index.js → index.ts} +0 -0
- /package/src/plugins/{index.js → index.ts} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
+
// @ts-expect-error -- is-plain-object types don't resolve with package.json "exports".
|
|
4
5
|
import { isPlainObject } from 'is-plain-object';
|
|
5
6
|
import deepmerge from 'deepmerge';
|
|
6
7
|
|
|
@@ -9,31 +10,37 @@ import deepmerge from 'deepmerge';
|
|
|
9
10
|
*/
|
|
10
11
|
import defaultStorage from './storage/default';
|
|
11
12
|
import { combineReducers } from '../../';
|
|
13
|
+
import type {
|
|
14
|
+
DataRegistry,
|
|
15
|
+
ReduxStoreConfig,
|
|
16
|
+
StorageInterface,
|
|
17
|
+
} from '../../types';
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
interface PersistencePluginOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Persistent storage implementation. This must
|
|
22
|
+
* at least implement `getItem` and `setItem` of
|
|
23
|
+
* the Web Storage API.
|
|
24
|
+
*/
|
|
25
|
+
storage?: StorageInterface;
|
|
26
|
+
/**
|
|
27
|
+
* Key on which to set in persistent storage.
|
|
28
|
+
*/
|
|
29
|
+
storageKey?: string;
|
|
30
|
+
}
|
|
16
31
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
*/
|
|
32
|
+
interface PersistenceInterface {
|
|
33
|
+
get: () => Record< string, unknown >;
|
|
34
|
+
set: ( key: string, value: unknown ) => void;
|
|
35
|
+
}
|
|
25
36
|
|
|
26
37
|
/**
|
|
27
38
|
* Default plugin storage.
|
|
28
|
-
*
|
|
29
|
-
* @type {Storage}
|
|
30
39
|
*/
|
|
31
40
|
const DEFAULT_STORAGE = defaultStorage;
|
|
32
41
|
|
|
33
42
|
/**
|
|
34
43
|
* Default plugin storage key.
|
|
35
|
-
*
|
|
36
|
-
* @type {string}
|
|
37
44
|
*/
|
|
38
45
|
const DEFAULT_STORAGE_KEY = 'WP_DATA';
|
|
39
46
|
|
|
@@ -42,38 +49,42 @@ const DEFAULT_STORAGE_KEY = 'WP_DATA';
|
|
|
42
49
|
* inequal from that of the action's `nextState` property, otherwise returning
|
|
43
50
|
* the original state reference.
|
|
44
51
|
*
|
|
45
|
-
* @param
|
|
52
|
+
* @param reducer Original reducer.
|
|
46
53
|
*
|
|
47
|
-
* @return
|
|
54
|
+
* @return Enhanced reducer.
|
|
48
55
|
*/
|
|
49
|
-
export const withLazySameState =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
export const withLazySameState =
|
|
57
|
+
( reducer: ( state: any, action: any ) => any ) =>
|
|
58
|
+
( state: unknown, action: { nextState: unknown } ) => {
|
|
59
|
+
if ( action.nextState === state ) {
|
|
60
|
+
return state;
|
|
61
|
+
}
|
|
53
62
|
|
|
54
|
-
|
|
55
|
-
};
|
|
63
|
+
return reducer( state, action );
|
|
64
|
+
};
|
|
56
65
|
|
|
57
66
|
/**
|
|
58
67
|
* Creates a persistence interface, exposing getter and setter methods (`get`
|
|
59
68
|
* and `set` respectively).
|
|
60
69
|
*
|
|
61
|
-
* @param
|
|
70
|
+
* @param options Plugin options.
|
|
62
71
|
*
|
|
63
|
-
* @return
|
|
72
|
+
* @return Persistence interface.
|
|
64
73
|
*/
|
|
65
|
-
export function createPersistenceInterface(
|
|
74
|
+
export function createPersistenceInterface(
|
|
75
|
+
options: PersistencePluginOptions
|
|
76
|
+
): PersistenceInterface {
|
|
66
77
|
const { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =
|
|
67
78
|
options;
|
|
68
79
|
|
|
69
|
-
let data;
|
|
80
|
+
let data: Record< string, unknown > | undefined;
|
|
70
81
|
|
|
71
82
|
/**
|
|
72
83
|
* Returns the persisted data as an object, defaulting to an empty object.
|
|
73
84
|
*
|
|
74
|
-
* @return
|
|
85
|
+
* @return Persisted data.
|
|
75
86
|
*/
|
|
76
|
-
function getData() {
|
|
87
|
+
function getData(): Record< string, unknown > {
|
|
77
88
|
if ( data === undefined ) {
|
|
78
89
|
// If unset, getItem is expected to return null. Fall back to
|
|
79
90
|
// empty object.
|
|
@@ -91,16 +102,16 @@ export function createPersistenceInterface( options ) {
|
|
|
91
102
|
}
|
|
92
103
|
}
|
|
93
104
|
|
|
94
|
-
return data
|
|
105
|
+
return data!;
|
|
95
106
|
}
|
|
96
107
|
|
|
97
108
|
/**
|
|
98
109
|
* Merges an updated reducer state into the persisted data.
|
|
99
110
|
*
|
|
100
|
-
* @param
|
|
101
|
-
* @param
|
|
111
|
+
* @param key Key to update.
|
|
112
|
+
* @param value Updated value.
|
|
102
113
|
*/
|
|
103
|
-
function setData( key, value ) {
|
|
114
|
+
function setData( key: string, value: unknown ): void {
|
|
104
115
|
data = { ...data, [ key ]: value };
|
|
105
116
|
storage.setItem( storageKey, JSON.stringify( data ) );
|
|
106
117
|
}
|
|
@@ -114,26 +125,33 @@ export function createPersistenceInterface( options ) {
|
|
|
114
125
|
/**
|
|
115
126
|
* Data plugin to persist store state into a single storage key.
|
|
116
127
|
*
|
|
117
|
-
* @param
|
|
118
|
-
* @param
|
|
128
|
+
* @param registry Data registry.
|
|
129
|
+
* @param pluginOptions Plugin options.
|
|
119
130
|
*
|
|
120
|
-
* @return
|
|
131
|
+
* @return Data plugin.
|
|
121
132
|
*/
|
|
122
|
-
function persistencePlugin(
|
|
133
|
+
function persistencePlugin(
|
|
134
|
+
registry: DataRegistry,
|
|
135
|
+
pluginOptions: PersistencePluginOptions
|
|
136
|
+
): Partial< DataRegistry > {
|
|
123
137
|
const persistence = createPersistenceInterface( pluginOptions );
|
|
124
138
|
|
|
125
139
|
/**
|
|
126
140
|
* Creates an enhanced store dispatch function, triggering the state of the
|
|
127
141
|
* given store name to be persisted when changed.
|
|
128
142
|
*
|
|
129
|
-
* @param
|
|
130
|
-
* @param
|
|
131
|
-
* @param
|
|
143
|
+
* @param getState Function which returns current state.
|
|
144
|
+
* @param storeName Store name.
|
|
145
|
+
* @param keys Optional subset of keys to save.
|
|
132
146
|
*
|
|
133
|
-
* @return
|
|
147
|
+
* @return Enhanced dispatch function.
|
|
134
148
|
*/
|
|
135
|
-
function createPersistOnChange(
|
|
136
|
-
|
|
149
|
+
function createPersistOnChange(
|
|
150
|
+
getState: () => unknown,
|
|
151
|
+
storeName: string,
|
|
152
|
+
keys: boolean | string[]
|
|
153
|
+
): () => void {
|
|
154
|
+
let getPersistedState: ( state: any, action: any ) => any;
|
|
137
155
|
if ( Array.isArray( keys ) ) {
|
|
138
156
|
// Given keys, the persisted state should by produced as an object
|
|
139
157
|
// of the subset of keys. This implementation uses combineReducers
|
|
@@ -141,9 +159,18 @@ function persistencePlugin( registry, pluginOptions ) {
|
|
|
141
159
|
// of the property values changes. This allows a strict reference
|
|
142
160
|
// equality to bypass a persistence set on an unchanging state.
|
|
143
161
|
const reducers = keys.reduce(
|
|
144
|
-
(
|
|
162
|
+
(
|
|
163
|
+
accumulator: Record<
|
|
164
|
+
string,
|
|
165
|
+
( state: any, action: any ) => any
|
|
166
|
+
>,
|
|
167
|
+
key: string
|
|
168
|
+
) =>
|
|
145
169
|
Object.assign( accumulator, {
|
|
146
|
-
[ key ]: (
|
|
170
|
+
[ key ]: (
|
|
171
|
+
state: unknown,
|
|
172
|
+
action: { nextState: Record< string, unknown > }
|
|
173
|
+
) => action.nextState[ key ],
|
|
147
174
|
} ),
|
|
148
175
|
{}
|
|
149
176
|
);
|
|
@@ -152,7 +179,10 @@ function persistencePlugin( registry, pluginOptions ) {
|
|
|
152
179
|
combineReducers( reducers )
|
|
153
180
|
);
|
|
154
181
|
} else {
|
|
155
|
-
getPersistedState = (
|
|
182
|
+
getPersistedState = (
|
|
183
|
+
_state: unknown,
|
|
184
|
+
action: { nextState: unknown }
|
|
185
|
+
) => action.nextState;
|
|
156
186
|
}
|
|
157
187
|
|
|
158
188
|
let lastState = getPersistedState( undefined, {
|
|
@@ -171,7 +201,12 @@ function persistencePlugin( registry, pluginOptions ) {
|
|
|
171
201
|
}
|
|
172
202
|
|
|
173
203
|
return {
|
|
174
|
-
registerStore(
|
|
204
|
+
registerStore(
|
|
205
|
+
storeName: string,
|
|
206
|
+
options: ReduxStoreConfig< any, any, any > & {
|
|
207
|
+
persist?: boolean | string[];
|
|
208
|
+
}
|
|
209
|
+
) {
|
|
175
210
|
if ( ! options.persist ) {
|
|
176
211
|
return registry.registerStore( storeName, options );
|
|
177
212
|
}
|
|
@@ -192,9 +227,13 @@ function persistencePlugin( registry, pluginOptions ) {
|
|
|
192
227
|
// subset of keys.
|
|
193
228
|
// - New keys in what would otherwise be used as initial
|
|
194
229
|
// state are deeply merged as base for persisted value.
|
|
195
|
-
initialState = deepmerge(
|
|
196
|
-
|
|
197
|
-
|
|
230
|
+
initialState = deepmerge(
|
|
231
|
+
initialState as Record< string, unknown >,
|
|
232
|
+
persistedState as Record< string, unknown >,
|
|
233
|
+
{
|
|
234
|
+
isMergeableObject: isPlainObject,
|
|
235
|
+
}
|
|
236
|
+
);
|
|
198
237
|
} else {
|
|
199
238
|
// If there is a mismatch in object-likeness of default
|
|
200
239
|
// initial or persisted state, defer to persisted value.
|
|
@@ -213,7 +252,7 @@ function persistencePlugin( registry, pluginOptions ) {
|
|
|
213
252
|
createPersistOnChange(
|
|
214
253
|
store.getState,
|
|
215
254
|
storeName,
|
|
216
|
-
options.persist
|
|
255
|
+
options.persist!
|
|
217
256
|
)
|
|
218
257
|
);
|
|
219
258
|
|
|
@@ -222,6 +261,6 @@ function persistencePlugin( registry, pluginOptions ) {
|
|
|
222
261
|
};
|
|
223
262
|
}
|
|
224
263
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
264
|
+
export default Object.assign( persistencePlugin, {
|
|
265
|
+
__unstableMigrate: () => {},
|
|
266
|
+
} );
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
+
import type { StorageInterface } from '../../../types';
|
|
4
5
|
import objectStorage from './object';
|
|
5
6
|
|
|
6
|
-
let storage;
|
|
7
|
+
let storage: StorageInterface & { removeItem?: ( key: string ) => void };
|
|
7
8
|
|
|
8
9
|
try {
|
|
9
10
|
// Private Browsing in Safari 10 and earlier will throw an error when
|
|
@@ -11,7 +12,7 @@ try {
|
|
|
11
12
|
// causing a thrown error as condition for using fallback object storage.
|
|
12
13
|
storage = window.localStorage;
|
|
13
14
|
storage.setItem( '__wpDataTestLocalStorage', '' );
|
|
14
|
-
storage.removeItem( '__wpDataTestLocalStorage' );
|
|
15
|
+
storage.removeItem!( '__wpDataTestLocalStorage' );
|
|
15
16
|
} catch ( error ) {
|
|
16
17
|
storage = objectStorage;
|
|
17
18
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { StorageInterface } from '../../../types';
|
|
2
|
+
|
|
3
|
+
let objectStorage: Record< string, string > | undefined;
|
|
4
|
+
|
|
5
|
+
const storage: StorageInterface & { clear: VoidFunction } = {
|
|
6
|
+
getItem( key: string ): string | null {
|
|
7
|
+
if ( ! objectStorage || ! objectStorage[ key ] ) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return objectStorage[ key ];
|
|
12
|
+
},
|
|
13
|
+
setItem( key: string, value: string ) {
|
|
14
|
+
if ( ! objectStorage ) {
|
|
15
|
+
storage.clear();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
objectStorage![ key ] = String( value );
|
|
19
|
+
},
|
|
20
|
+
clear() {
|
|
21
|
+
objectStorage = Object.create( null );
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default storage;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
+
import type { Middleware } from 'redux';
|
|
4
5
|
import isPromise from 'is-promise';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Simplest possible promise redux middleware.
|
|
8
|
-
*
|
|
9
|
-
* @type {import('redux').Middleware}
|
|
10
9
|
*/
|
|
11
|
-
const promiseMiddleware = () => ( next ) => ( action ) => {
|
|
10
|
+
const promiseMiddleware: Middleware = () => ( next ) => ( action ) => {
|
|
12
11
|
if ( isPromise( action ) ) {
|
|
13
12
|
return action.then( ( resolvedAction ) => {
|
|
14
13
|
if ( resolvedAction ) {
|
|
15
14
|
return next( resolvedAction );
|
|
16
15
|
}
|
|
16
|
+
return undefined;
|
|
17
17
|
} );
|
|
18
18
|
}
|
|
19
19
|
|