@wordpress/data 9.9.0 → 9.10.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.
Files changed (150) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/components/async-mode-provider/context.js +2 -3
  3. package/build/components/async-mode-provider/context.js.map +1 -1
  4. package/build/components/async-mode-provider/index.js +0 -5
  5. package/build/components/async-mode-provider/index.js.map +1 -1
  6. package/build/components/async-mode-provider/use-async-mode.js +1 -3
  7. package/build/components/async-mode-provider/use-async-mode.js.map +1 -1
  8. package/build/components/registry-provider/context.js +3 -6
  9. package/build/components/registry-provider/context.js.map +1 -1
  10. package/build/components/registry-provider/index.js +0 -5
  11. package/build/components/registry-provider/index.js.map +1 -1
  12. package/build/components/registry-provider/use-registry.js +0 -3
  13. package/build/components/registry-provider/use-registry.js.map +1 -1
  14. package/build/components/use-dispatch/index.js +0 -3
  15. package/build/components/use-dispatch/index.js.map +1 -1
  16. package/build/components/use-dispatch/use-dispatch-with-map.js +0 -7
  17. package/build/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
  18. package/build/components/use-dispatch/use-dispatch.js +0 -5
  19. package/build/components/use-dispatch/use-dispatch.js.map +1 -1
  20. package/build/components/use-select/index.js +35 -53
  21. package/build/components/use-select/index.js.map +1 -1
  22. package/build/components/with-dispatch/index.js +2 -7
  23. package/build/components/with-dispatch/index.js.map +1 -1
  24. package/build/components/with-registry/index.js +2 -5
  25. package/build/components/with-registry/index.js.map +1 -1
  26. package/build/components/with-select/index.js +2 -8
  27. package/build/components/with-select/index.js.map +1 -1
  28. package/build/controls.js +4 -10
  29. package/build/controls.js.map +1 -1
  30. package/build/default-registry.js +0 -3
  31. package/build/default-registry.js.map +1 -1
  32. package/build/dispatch.js +0 -3
  33. package/build/dispatch.js.map +1 -1
  34. package/build/factory.js +2 -5
  35. package/build/factory.js.map +1 -1
  36. package/build/index.js +7 -28
  37. package/build/index.js.map +1 -1
  38. package/build/lock-unlock.js +1 -2
  39. package/build/lock-unlock.js.map +1 -1
  40. package/build/plugins/index.js +0 -2
  41. package/build/plugins/index.js.map +1 -1
  42. package/build/plugins/persistence/index.js +13 -37
  43. package/build/plugins/persistence/index.js.map +1 -1
  44. package/build/plugins/persistence/storage/default.js +1 -5
  45. package/build/plugins/persistence/storage/default.js.map +1 -1
  46. package/build/plugins/persistence/storage/object.js +0 -5
  47. package/build/plugins/persistence/storage/object.js.map +1 -1
  48. package/build/promise-middleware.js +0 -5
  49. package/build/promise-middleware.js.map +1 -1
  50. package/build/redux-store/index.js +36 -117
  51. package/build/redux-store/index.js.map +1 -1
  52. package/build/redux-store/metadata/actions.js +8 -17
  53. package/build/redux-store/metadata/actions.js.map +1 -1
  54. package/build/redux-store/metadata/equivalent-key-map.d.js.map +1 -1
  55. package/build/redux-store/metadata/reducer.js +1 -23
  56. package/build/redux-store/metadata/reducer.js.map +1 -1
  57. package/build/redux-store/metadata/selectors.js +8 -22
  58. package/build/redux-store/metadata/selectors.js.map +1 -1
  59. package/build/redux-store/metadata/utils.js +6 -14
  60. package/build/redux-store/metadata/utils.js.map +1 -1
  61. package/build/redux-store/thunk-middleware.js +0 -2
  62. package/build/redux-store/thunk-middleware.js.map +1 -1
  63. package/build/registry.js +29 -73
  64. package/build/registry.js.map +1 -1
  65. package/build/resolvers-cache-middleware.js +2 -8
  66. package/build/resolvers-cache-middleware.js.map +1 -1
  67. package/build/select.js +0 -3
  68. package/build/select.js.map +1 -1
  69. package/build/store/index.js +0 -7
  70. package/build/store/index.js.map +1 -1
  71. package/build/types.js.map +1 -1
  72. package/build/utils/emitter.js +2 -11
  73. package/build/utils/emitter.js.map +1 -1
  74. package/build-module/components/async-mode-provider/context.js +1 -1
  75. package/build-module/components/async-mode-provider/context.js.map +1 -1
  76. package/build-module/components/async-mode-provider/index.js.map +1 -1
  77. package/build-module/components/async-mode-provider/use-async-mode.js +1 -1
  78. package/build-module/components/async-mode-provider/use-async-mode.js.map +1 -1
  79. package/build-module/components/registry-provider/context.js +3 -3
  80. package/build-module/components/registry-provider/context.js.map +1 -1
  81. package/build-module/components/registry-provider/index.js.map +1 -1
  82. package/build-module/components/registry-provider/use-registry.js +2 -2
  83. package/build-module/components/registry-provider/use-registry.js.map +1 -1
  84. package/build-module/components/use-dispatch/index.js.map +1 -1
  85. package/build-module/components/use-dispatch/use-dispatch-with-map.js +2 -4
  86. package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
  87. package/build-module/components/use-dispatch/use-dispatch.js +1 -3
  88. package/build-module/components/use-dispatch/use-dispatch.js.map +1 -1
  89. package/build-module/components/use-select/index.js +35 -46
  90. package/build-module/components/use-select/index.js.map +1 -1
  91. package/build-module/components/with-dispatch/index.js +4 -6
  92. package/build-module/components/with-dispatch/index.js.map +1 -1
  93. package/build-module/components/with-registry/index.js +4 -4
  94. package/build-module/components/with-registry/index.js.map +1 -1
  95. package/build-module/components/with-select/index.js +4 -6
  96. package/build-module/components/with-select/index.js.map +1 -1
  97. package/build-module/controls.js +4 -8
  98. package/build-module/controls.js.map +1 -1
  99. package/build-module/default-registry.js.map +1 -1
  100. package/build-module/dispatch.js +2 -1
  101. package/build-module/dispatch.js.map +1 -1
  102. package/build-module/factory.js +2 -3
  103. package/build-module/factory.js.map +1 -1
  104. package/build-module/index.js +11 -10
  105. package/build-module/index.js.map +1 -1
  106. package/build-module/lock-unlock.js.map +1 -1
  107. package/build-module/plugins/index.js.map +1 -1
  108. package/build-module/plugins/persistence/index.js +15 -30
  109. package/build-module/plugins/persistence/index.js.map +1 -1
  110. package/build-module/plugins/persistence/storage/default.js +0 -2
  111. package/build-module/plugins/persistence/storage/default.js.map +1 -1
  112. package/build-module/plugins/persistence/storage/object.js +0 -5
  113. package/build-module/plugins/persistence/storage/object.js.map +1 -1
  114. package/build-module/promise-middleware.js +1 -3
  115. package/build-module/promise-middleware.js.map +1 -1
  116. package/build-module/redux-store/index.js +38 -101
  117. package/build-module/redux-store/index.js.map +1 -1
  118. package/build-module/redux-store/metadata/actions.js +8 -8
  119. package/build-module/redux-store/metadata/actions.js.map +1 -1
  120. package/build-module/redux-store/metadata/equivalent-key-map.d.js.map +1 -1
  121. package/build-module/redux-store/metadata/reducer.js +1 -21
  122. package/build-module/redux-store/metadata/reducer.js.map +1 -1
  123. package/build-module/redux-store/metadata/selectors.js +9 -13
  124. package/build-module/redux-store/metadata/selectors.js.map +1 -1
  125. package/build-module/redux-store/metadata/utils.js +6 -11
  126. package/build-module/redux-store/metadata/utils.js.map +1 -1
  127. package/build-module/redux-store/thunk-middleware.js +0 -1
  128. package/build-module/redux-store/thunk-middleware.js.map +1 -1
  129. package/build-module/registry.js +30 -67
  130. package/build-module/registry.js.map +1 -1
  131. package/build-module/resolvers-cache-middleware.js +3 -6
  132. package/build-module/resolvers-cache-middleware.js.map +1 -1
  133. package/build-module/select.js +2 -1
  134. package/build-module/select.js.map +1 -1
  135. package/build-module/store/index.js +0 -7
  136. package/build-module/store/index.js.map +1 -1
  137. package/build-module/types.js.map +1 -1
  138. package/build-module/utils/emitter.js +2 -10
  139. package/build-module/utils/emitter.js.map +1 -1
  140. package/build-types/components/use-select/index.d.ts.map +1 -1
  141. package/build-types/index.d.ts +1 -1
  142. package/build-types/index.d.ts.map +1 -1
  143. package/build-types/plugins/persistence/index.d.ts.map +1 -1
  144. package/build-types/private-apis.d.ts +3 -0
  145. package/build-types/private-apis.d.ts.map +1 -0
  146. package/build-types/store/index.d.ts +1 -1
  147. package/package.json +9 -9
  148. package/src/components/use-select/index.js +14 -0
  149. package/src/plugins/persistence/index.js +0 -1
  150. package/tsconfig.tsbuildinfo +1 -1
@@ -43,6 +43,7 @@ export function createRegistrySelector(registrySelector) {
43
43
  // and that has the same API as a regular selector. Binding it in such a way makes it
44
44
  // possible to call the selector directly from another selector.
45
45
  const selector = (...args) => registrySelector(selector.registry.select)(...args);
46
+
46
47
  /**
47
48
  * Flag indicating that the selector is a registry selector that needs the correct registry
48
49
  * reference to be assigned to `selector.registry` to make it work correctly.
@@ -50,11 +51,10 @@ export function createRegistrySelector(registrySelector) {
50
51
  *
51
52
  * @type {boolean}
52
53
  */
53
-
54
-
55
54
  selector.isRegistrySelector = true;
56
55
  return selector;
57
56
  }
57
+
58
58
  /**
59
59
  * Creates a control function that takes additional curried argument with the `registry` object.
60
60
  * While a regular control has signature
@@ -75,7 +75,6 @@ export function createRegistrySelector(registrySelector) {
75
75
  *
76
76
  * @return {Function} Registry control that can be registered with a store.
77
77
  */
78
-
79
78
  export function createRegistryControl(registryControl) {
80
79
  registryControl.isRegistryControl = true;
81
80
  return registryControl;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/factory.js"],"names":["createRegistrySelector","registrySelector","selector","args","registry","select","isRegistrySelector","createRegistryControl","registryControl","isRegistryControl"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,sBAAT,CAAiCC,gBAAjC,EAAoD;AAC1D;AACA;AACA;AACA,QAAMC,QAAQ,GAAG,CAAE,GAAGC,IAAL,KAChBF,gBAAgB,CAAEC,QAAQ,CAACE,QAAT,CAAkBC,MAApB,CAAhB,CAA8C,GAAGF,IAAjD,CADD;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;;;AACCD,EAAAA,QAAQ,CAACI,kBAAT,GAA8B,IAA9B;AAEA,SAAOJ,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASK,qBAAT,CAAgCC,eAAhC,EAAkD;AACxDA,EAAAA,eAAe,CAACC,iBAAhB,GAAoC,IAApC;AAEA,SAAOD,eAAP;AACA","sourcesContent":["/**\n * Creates a selector function that takes additional curried argument with the\n * registry `select` function. While a regular selector has signature\n * ```js\n * ( state, ...selectorArgs ) => ( result )\n * ```\n * that allows to select data from the store's `state`, a registry selector\n * has signature:\n * ```js\n * ( select ) => ( state, ...selectorArgs ) => ( result )\n * ```\n * that supports also selecting from other registered stores.\n *\n * @example\n * ```js\n * import { store as coreStore } from '@wordpress/core-data';\n * import { store as editorStore } from '@wordpress/editor';\n *\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( editorStore ).getCurrentPostId();\n * } );\n *\n * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {\n * // calling another registry selector just like any other function\n * const postType = getCurrentPostType( state );\n * const postId = getCurrentPostId( state );\n *\t return select( coreStore ).getEntityRecordEdits( 'postType', postType, postId );\n * } );\n * ```\n *\n * Note how the `getCurrentPostId` selector can be called just like any other function,\n * (it works even inside a regular non-registry selector) and we don't need to pass the\n * registry as argument. The registry binding happens automatically when registering the selector\n * with a store.\n *\n * @param {Function} registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return {Function} Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector( registrySelector ) {\n\t// Create a selector function that is bound to the registry referenced by `selector.registry`\n\t// and that has the same API as a regular selector. Binding it in such a way makes it\n\t// possible to call the selector directly from another selector.\n\tconst selector = ( ...args ) =>\n\t\tregistrySelector( selector.registry.select )( ...args );\n\n\t/**\n\t * Flag indicating that the selector is a registry selector that needs the correct registry\n\t * reference to be assigned to `selector.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t *\n\t * @type {boolean}\n\t */\n\tselector.isRegistrySelector = true;\n\n\treturn selector;\n}\n\n/**\n * Creates a control function that takes additional curried argument with the `registry` object.\n * While a regular control has signature\n * ```js\n * ( action ) => ( iteratorOrPromise )\n * ```\n * where the control works with the `action` that it's bound to, a registry control has signature:\n * ```js\n * ( registry ) => ( action ) => ( iteratorOrPromise )\n * ```\n * A registry control is typically used to select data or dispatch an action to a registered\n * store.\n *\n * When registering a control created with `createRegistryControl` with a store, the store\n * knows which calling convention to use when executing the control.\n *\n * @param {Function} registryControl Function receiving a registry object and returning a control.\n *\n * @return {Function} Registry control that can be registered with a store.\n */\nexport function createRegistryControl( registryControl ) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"]}
1
+ {"version":3,"names":["createRegistrySelector","registrySelector","selector","args","registry","select","isRegistrySelector","createRegistryControl","registryControl","isRegistryControl"],"sources":["@wordpress/data/src/factory.js"],"sourcesContent":["/**\n * Creates a selector function that takes additional curried argument with the\n * registry `select` function. While a regular selector has signature\n * ```js\n * ( state, ...selectorArgs ) => ( result )\n * ```\n * that allows to select data from the store's `state`, a registry selector\n * has signature:\n * ```js\n * ( select ) => ( state, ...selectorArgs ) => ( result )\n * ```\n * that supports also selecting from other registered stores.\n *\n * @example\n * ```js\n * import { store as coreStore } from '@wordpress/core-data';\n * import { store as editorStore } from '@wordpress/editor';\n *\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( editorStore ).getCurrentPostId();\n * } );\n *\n * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {\n * // calling another registry selector just like any other function\n * const postType = getCurrentPostType( state );\n * const postId = getCurrentPostId( state );\n *\t return select( coreStore ).getEntityRecordEdits( 'postType', postType, postId );\n * } );\n * ```\n *\n * Note how the `getCurrentPostId` selector can be called just like any other function,\n * (it works even inside a regular non-registry selector) and we don't need to pass the\n * registry as argument. The registry binding happens automatically when registering the selector\n * with a store.\n *\n * @param {Function} registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return {Function} Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector( registrySelector ) {\n\t// Create a selector function that is bound to the registry referenced by `selector.registry`\n\t// and that has the same API as a regular selector. Binding it in such a way makes it\n\t// possible to call the selector directly from another selector.\n\tconst selector = ( ...args ) =>\n\t\tregistrySelector( selector.registry.select )( ...args );\n\n\t/**\n\t * Flag indicating that the selector is a registry selector that needs the correct registry\n\t * reference to be assigned to `selector.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t *\n\t * @type {boolean}\n\t */\n\tselector.isRegistrySelector = true;\n\n\treturn selector;\n}\n\n/**\n * Creates a control function that takes additional curried argument with the `registry` object.\n * While a regular control has signature\n * ```js\n * ( action ) => ( iteratorOrPromise )\n * ```\n * where the control works with the `action` that it's bound to, a registry control has signature:\n * ```js\n * ( registry ) => ( action ) => ( iteratorOrPromise )\n * ```\n * A registry control is typically used to select data or dispatch an action to a registered\n * store.\n *\n * When registering a control created with `createRegistryControl` with a store, the store\n * knows which calling convention to use when executing the control.\n *\n * @param {Function} registryControl Function receiving a registry object and returning a control.\n *\n * @return {Function} Registry control that can be registered with a store.\n */\nexport function createRegistryControl( registryControl ) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,sBAAsBA,CAAEC,gBAAgB,EAAG;EAC1D;EACA;EACA;EACA,MAAMC,QAAQ,GAAGA,CAAE,GAAGC,IAAI,KACzBF,gBAAgB,CAAEC,QAAQ,CAACE,QAAQ,CAACC,MAAO,CAAC,CAAE,GAAGF,IAAK,CAAC;;EAExD;AACD;AACA;AACA;AACA;AACA;AACA;EACCD,QAAQ,CAACI,kBAAkB,GAAG,IAAI;EAElC,OAAOJ,QAAQ;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,qBAAqBA,CAAEC,eAAe,EAAG;EACxDA,eAAe,CAACC,iBAAiB,GAAG,IAAI;EAExC,OAAOD,eAAe;AACvB"}
@@ -2,12 +2,13 @@
2
2
  * External dependencies
3
3
  */
4
4
  import turboCombineReducers from 'turbo-combine-reducers';
5
+
5
6
  /**
6
7
  * Internal dependencies
7
8
  */
8
-
9
9
  import defaultRegistry from './default-registry';
10
10
  import * as plugins from './plugins';
11
+
11
12
  /** @typedef {import('./types').StoreDescriptor} StoreDescriptor */
12
13
 
13
14
  export { default as withSelect } from './components/with-select';
@@ -23,6 +24,7 @@ export { controls } from './controls';
23
24
  export { default as createReduxStore } from './redux-store';
24
25
  export { dispatch } from './dispatch';
25
26
  export { select } from './select';
27
+
26
28
  /**
27
29
  * Object of available plugins to use with a registry.
28
30
  *
@@ -30,8 +32,8 @@ export { select } from './select';
30
32
  *
31
33
  * @type {Object}
32
34
  */
33
-
34
35
  export { plugins };
36
+
35
37
  /**
36
38
  * The combineReducers helper function turns an object whose values are different
37
39
  * reducing functions into a single reducing function you can pass to registerReducer.
@@ -71,8 +73,8 @@ export { plugins };
71
73
  * @return {Function} A reducer that invokes every reducer inside the reducers
72
74
  * object, and constructs a state object with the same shape.
73
75
  */
74
-
75
76
  export const combineReducers = turboCombineReducers;
77
+
76
78
  /**
77
79
  * Given a store descriptor, returns an object containing the store's selectors pre-bound to state
78
80
  * so that you only need to supply additional arguments, and modified so that they return promises
@@ -92,8 +94,8 @@ export const combineReducers = turboCombineReducers;
92
94
  *
93
95
  * @return {Object} Object containing the store's promise-wrapped selectors.
94
96
  */
95
-
96
97
  export const resolveSelect = defaultRegistry.resolveSelect;
98
+
97
99
  /**
98
100
  * Given a store descriptor, returns an object containing the store's selectors pre-bound to state
99
101
  * so that you only need to supply additional arguments, and modified so that they throw promises
@@ -105,8 +107,8 @@ export const resolveSelect = defaultRegistry.resolveSelect;
105
107
  *
106
108
  * @return {Object} Object containing the store's suspense-wrapped selectors.
107
109
  */
108
-
109
110
  export const suspendSelect = defaultRegistry.suspendSelect;
111
+
110
112
  /**
111
113
  * Given a listener function, the function will be called any time the state value
112
114
  * of one of the registered stores has changed. If you specify the optional
@@ -131,8 +133,8 @@ export const suspendSelect = defaultRegistry.suspendSelect;
131
133
  * unsubscribe();
132
134
  * ```
133
135
  */
134
-
135
136
  export const subscribe = defaultRegistry.subscribe;
137
+
136
138
  /**
137
139
  * Registers a generic store instance.
138
140
  *
@@ -141,8 +143,8 @@ export const subscribe = defaultRegistry.subscribe;
141
143
  * @param {string} name Store registry name.
142
144
  * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).
143
145
  */
144
-
145
146
  export const registerGenericStore = defaultRegistry.registerGenericStore;
147
+
146
148
  /**
147
149
  * Registers a standard `@wordpress/data` store.
148
150
  *
@@ -153,8 +155,8 @@ export const registerGenericStore = defaultRegistry.registerGenericStore;
153
155
  *
154
156
  * @return {Object} Registered store object.
155
157
  */
156
-
157
158
  export const registerStore = defaultRegistry.registerStore;
159
+
158
160
  /**
159
161
  * Extends a registry to inherit functionality provided by a given plugin. A
160
162
  * plugin is an object with properties aligning to that of a registry, merged
@@ -162,8 +164,8 @@ export const registerStore = defaultRegistry.registerStore;
162
164
  *
163
165
  * @param {Object} plugin Plugin object.
164
166
  */
165
-
166
167
  export const use = defaultRegistry.use;
168
+
167
169
  /**
168
170
  * Registers a standard `@wordpress/data` store descriptor.
169
171
  *
@@ -182,6 +184,5 @@ export const use = defaultRegistry.use;
182
184
  *
183
185
  * @param {StoreDescriptor} store Store descriptor.
184
186
  */
185
-
186
187
  export const register = defaultRegistry.register;
187
188
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/index.js"],"names":["turboCombineReducers","defaultRegistry","plugins","default","withSelect","withDispatch","withRegistry","RegistryProvider","RegistryConsumer","useRegistry","useSelect","useSuspenseSelect","useDispatch","AsyncModeProvider","createRegistry","createRegistrySelector","createRegistryControl","controls","createReduxStore","dispatch","select","combineReducers","resolveSelect","suspendSelect","subscribe","registerGenericStore","registerStore","use","register"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,oBAAP,MAAiC,wBAAjC;AAEA;AACA;AACA;;AACA,OAAOC,eAAP,MAA4B,oBAA5B;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AAEA;;AAEA,SAASC,OAAO,IAAIC,UAApB,QAAsC,0BAAtC;AACA,SAASD,OAAO,IAAIE,YAApB,QAAwC,4BAAxC;AACA,SAASF,OAAO,IAAIG,YAApB,QAAwC,4BAAxC;AACA,SACCC,gBADD,EAECC,gBAFD,EAGCC,WAHD,QAIO,gCAJP;AAKA,SACCN,OAAO,IAAIO,SADZ,EAECC,iBAFD,QAGO,yBAHP;AAIA,SAASC,WAAT,QAA4B,2BAA5B;AACA,SAASC,iBAAT,QAAkC,kCAAlC;AACA,SAASC,cAAT,QAA+B,YAA/B;AACA,SAASC,sBAAT,EAAiCC,qBAAjC,QAA8D,WAA9D;AACA,SAASC,QAAT,QAAyB,YAAzB;AACA,SAASd,OAAO,IAAIe,gBAApB,QAA4C,eAA5C;AACA,SAASC,QAAT,QAAyB,YAAzB;AACA,SAASC,MAAT,QAAuB,UAAvB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASlB,OAAT;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMmB,eAAe,GAAGrB,oBAAxB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMsB,aAAa,GAAGrB,eAAe,CAACqB,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,aAAa,GAAGtB,eAAe,CAACsB,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,SAAS,GAAGvB,eAAe,CAACuB,SAAlC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,oBAAoB,GAAGxB,eAAe,CAACwB,oBAA7C;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,aAAa,GAAGzB,eAAe,CAACyB,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,GAAG,GAAG1B,eAAe,CAAC0B,GAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,QAAQ,GAAG3B,eAAe,CAAC2B,QAAjC","sourcesContent":["/**\n * External dependencies\n */\nimport turboCombineReducers from 'turbo-combine-reducers';\n\n/**\n * Internal dependencies\n */\nimport defaultRegistry from './default-registry';\nimport * as plugins from './plugins';\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 { 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 = turboCombineReducers;\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"]}
1
+ {"version":3,"names":["turboCombineReducers","defaultRegistry","plugins","default","withSelect","withDispatch","withRegistry","RegistryProvider","RegistryConsumer","useRegistry","useSelect","useSuspenseSelect","useDispatch","AsyncModeProvider","createRegistry","createRegistrySelector","createRegistryControl","controls","createReduxStore","dispatch","select","combineReducers","resolveSelect","suspendSelect","subscribe","registerGenericStore","registerStore","use","register"],"sources":["@wordpress/data/src/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport turboCombineReducers from 'turbo-combine-reducers';\n\n/**\n * Internal dependencies\n */\nimport defaultRegistry from './default-registry';\nimport * as plugins from './plugins';\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 { 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 = turboCombineReducers;\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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,oBAAoB,MAAM,wBAAwB;;AAEzD;AACA;AACA;AACA,OAAOC,eAAe,MAAM,oBAAoB;AAChD,OAAO,KAAKC,OAAO,MAAM,WAAW;;AAEpC;;AAEA,SAASC,OAAO,IAAIC,UAAU,QAAQ,0BAA0B;AAChE,SAASD,OAAO,IAAIE,YAAY,QAAQ,4BAA4B;AACpE,SAASF,OAAO,IAAIG,YAAY,QAAQ,4BAA4B;AACpE,SACCC,gBAAgB,EAChBC,gBAAgB,EAChBC,WAAW,QACL,gCAAgC;AACvC,SACCN,OAAO,IAAIO,SAAS,EACpBC,iBAAiB,QACX,yBAAyB;AAChC,SAASC,WAAW,QAAQ,2BAA2B;AACvD,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,cAAc,QAAQ,YAAY;AAC3C,SAASC,sBAAsB,EAAEC,qBAAqB,QAAQ,WAAW;AACzE,SAASC,QAAQ,QAAQ,YAAY;AACrC,SAASd,OAAO,IAAIe,gBAAgB,QAAQ,eAAe;AAC3D,SAASC,QAAQ,QAAQ,YAAY;AACrC,SAASC,MAAM,QAAQ,UAAU;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASlB,OAAO;;AAEhB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMmB,eAAe,GAAGrB,oBAAoB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMsB,aAAa,GAAGrB,eAAe,CAACqB,aAAa;;AAE1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAGtB,eAAe,CAACsB,aAAa;;AAE1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAGvB,eAAe,CAACuB,SAAS;;AAElD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAAGxB,eAAe,CAACwB,oBAAoB;;AAExE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAGzB,eAAe,CAACyB,aAAa;;AAE1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,GAAG,GAAG1B,eAAe,CAAC0B,GAAG;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,QAAQ,GAAG3B,eAAe,CAAC2B,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/lock-unlock.js"],"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gDAAT,QAAiE,yBAAjE;AAEA,OAAO,MAAM;AAAEC,EAAAA,IAAF;AAAQC,EAAAA;AAAR,IACZF,gDAAgD,CAC/C,8GAD+C,EAE/C,iBAF+C,CAD1C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',\n\t\t'@wordpress/data'\n\t);\n"]}
1
+ {"version":3,"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"sources":["@wordpress/data/src/lock-unlock.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',\n\t\t'@wordpress/data'\n\t);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gDAAgD,QAAQ,yBAAyB;AAE1F,OAAO,MAAM;EAAEC,IAAI;EAAEC;AAAO,CAAC,GAC5BF,gDAAgD,CAC/C,8GAA8G,EAC9G,iBACD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/plugins/index.js"],"names":["default","persistence"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAApB,QAAuC,eAAvC","sourcesContent":["export { default as persistence } from './persistence';\n"]}
1
+ {"version":3,"names":["default","persistence"],"sources":["@wordpress/data/src/plugins/index.js"],"sourcesContent":["export { default as persistence } from './persistence';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAAW,QAAQ,eAAe"}
@@ -3,12 +3,13 @@
3
3
  */
4
4
  import { isPlainObject } from 'is-plain-object';
5
5
  import deepmerge from 'deepmerge';
6
+
6
7
  /**
7
8
  * Internal dependencies
8
9
  */
9
-
10
10
  import defaultStorage from './storage/default';
11
11
  import { combineReducers } from '../../';
12
+
12
13
  /** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */
13
14
 
14
15
  /** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */
@@ -20,7 +21,6 @@ import { combineReducers } from '../../';
20
21
  * at least implement `getItem` and `setItem` of
21
22
  * the Web Storage API.
22
23
  * @property {string} storageKey Key on which to set in persistent storage.
23
- *
24
24
  */
25
25
 
26
26
  /**
@@ -28,15 +28,15 @@ import { combineReducers } from '../../';
28
28
  *
29
29
  * @type {Storage}
30
30
  */
31
-
32
31
  const DEFAULT_STORAGE = defaultStorage;
32
+
33
33
  /**
34
34
  * Default plugin storage key.
35
35
  *
36
36
  * @type {string}
37
37
  */
38
-
39
38
  const DEFAULT_STORAGE_KEY = 'WP_DATA';
39
+
40
40
  /**
41
41
  * Higher-order reducer which invokes the original reducer only if state is
42
42
  * inequal from that of the action's `nextState` property, otherwise returning
@@ -46,14 +46,13 @@ const DEFAULT_STORAGE_KEY = 'WP_DATA';
46
46
  *
47
47
  * @return {Function} Enhanced reducer.
48
48
  */
49
-
50
49
  export const withLazySameState = reducer => (state, action) => {
51
50
  if (action.nextState === state) {
52
51
  return state;
53
52
  }
54
-
55
53
  return reducer(state, action);
56
54
  };
55
+
57
56
  /**
58
57
  * Creates a persistence interface, exposing getter and setter methods (`get`
59
58
  * and `set` respectively).
@@ -62,25 +61,23 @@ export const withLazySameState = reducer => (state, action) => {
62
61
  *
63
62
  * @return {Object} Persistence interface.
64
63
  */
65
-
66
64
  export function createPersistenceInterface(options) {
67
65
  const {
68
66
  storage = DEFAULT_STORAGE,
69
67
  storageKey = DEFAULT_STORAGE_KEY
70
68
  } = options;
71
69
  let data;
70
+
72
71
  /**
73
72
  * Returns the persisted data as an object, defaulting to an empty object.
74
73
  *
75
74
  * @return {Object} Persisted data.
76
75
  */
77
-
78
76
  function getData() {
79
77
  if (data === undefined) {
80
78
  // If unset, getItem is expected to return null. Fall back to
81
79
  // empty object.
82
80
  const persisted = storage.getItem(storageKey);
83
-
84
81
  if (persisted === null) {
85
82
  data = {};
86
83
  } else {
@@ -93,29 +90,28 @@ export function createPersistenceInterface(options) {
93
90
  }
94
91
  }
95
92
  }
96
-
97
93
  return data;
98
94
  }
95
+
99
96
  /**
100
97
  * Merges an updated reducer state into the persisted data.
101
98
  *
102
99
  * @param {string} key Key to update.
103
100
  * @param {*} value Updated value.
104
101
  */
105
-
106
-
107
102
  function setData(key, value) {
108
- data = { ...data,
103
+ data = {
104
+ ...data,
109
105
  [key]: value
110
106
  };
111
107
  storage.setItem(storageKey, JSON.stringify(data));
112
108
  }
113
-
114
109
  return {
115
110
  get: getData,
116
111
  set: setData
117
112
  };
118
113
  }
114
+
119
115
  /**
120
116
  * Data plugin to persist store state into a single storage key.
121
117
  *
@@ -124,9 +120,9 @@ export function createPersistenceInterface(options) {
124
120
  *
125
121
  * @return {WPDataPlugin} Data plugin.
126
122
  */
127
-
128
123
  function persistencePlugin(registry, pluginOptions) {
129
124
  const persistence = createPersistenceInterface(pluginOptions);
125
+
130
126
  /**
131
127
  * Creates an enhanced store dispatch function, triggering the state of the
132
128
  * given store name to be persisted when changed.
@@ -137,10 +133,8 @@ function persistencePlugin(registry, pluginOptions) {
137
133
  *
138
134
  * @return {Function} Enhanced dispatch function.
139
135
  */
140
-
141
136
  function createPersistOnChange(getState, storeName, keys) {
142
137
  let getPersistedState;
143
-
144
138
  if (Array.isArray(keys)) {
145
139
  // Given keys, the persisted state should by produced as an object
146
140
  // of the subset of keys. This implementation uses combineReducers
@@ -154,7 +148,6 @@ function persistencePlugin(registry, pluginOptions) {
154
148
  } else {
155
149
  getPersistedState = (state, action) => action.nextState;
156
150
  }
157
-
158
151
  let lastState = getPersistedState(undefined, {
159
152
  nextState: getState()
160
153
  });
@@ -162,28 +155,24 @@ function persistencePlugin(registry, pluginOptions) {
162
155
  const state = getPersistedState(lastState, {
163
156
  nextState: getState()
164
157
  });
165
-
166
158
  if (state !== lastState) {
167
159
  persistence.set(storeName, state);
168
160
  lastState = state;
169
161
  }
170
162
  };
171
163
  }
172
-
173
164
  return {
174
165
  registerStore(storeName, options) {
175
166
  if (!options.persist) {
176
167
  return registry.registerStore(storeName, options);
177
- } // Load from persistence to use as initial state.
178
-
168
+ }
179
169
 
170
+ // Load from persistence to use as initial state.
180
171
  const persistedState = persistence.get()[storeName];
181
-
182
172
  if (persistedState !== undefined) {
183
173
  let initialState = options.reducer(options.initialState, {
184
174
  type: '@@WP/PERSISTENCE_RESTORE'
185
175
  });
186
-
187
176
  if (isPlainObject(initialState) && isPlainObject(persistedState)) {
188
177
  // If state is an object, ensure that:
189
178
  // - Other keys are left intact when persisting only a
@@ -198,21 +187,17 @@ function persistencePlugin(registry, pluginOptions) {
198
187
  // initial or persisted state, defer to persisted value.
199
188
  initialState = persistedState;
200
189
  }
201
-
202
- options = { ...options,
190
+ options = {
191
+ ...options,
203
192
  initialState
204
193
  };
205
194
  }
206
-
207
195
  const store = registry.registerStore(storeName, options);
208
196
  store.subscribe(createPersistOnChange(store.getState, storeName, options.persist));
209
197
  return store;
210
198
  }
211
-
212
199
  };
213
200
  }
214
-
215
201
  persistencePlugin.__unstableMigrate = () => {};
216
-
217
202
  export default persistencePlugin;
218
203
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/plugins/persistence/index.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAT,QAA8B,iBAA9B;AACA,OAAOC,SAAP,MAAsB,WAAtB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,mBAA3B;AACA,SAASC,eAAT,QAAgC,QAAhC;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,eAAe,GAAGF,cAAxB;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMG,mBAAmB,GAAG,SAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,iBAAiB,GAAKC,OAAF,IAAe,CAAEC,KAAF,EAASC,MAAT,KAAqB;AACpE,MAAKA,MAAM,CAACC,SAAP,KAAqBF,KAA1B,EAAkC;AACjC,WAAOA,KAAP;AACA;;AAED,SAAOD,OAAO,CAAEC,KAAF,EAASC,MAAT,CAAd;AACA,CANM;AAQP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,0BAAT,CAAqCC,OAArC,EAA+C;AACrD,QAAM;AAAEC,IAAAA,OAAO,GAAGT,eAAZ;AAA6BU,IAAAA,UAAU,GAAGT;AAA1C,MACLO,OADD;AAGA,MAAIG,IAAJ;AAEA;AACD;AACA;AACA;AACA;;AACC,WAASC,OAAT,GAAmB;AAClB,QAAKD,IAAI,KAAKE,SAAd,EAA0B;AACzB;AACA;AACA,YAAMC,SAAS,GAAGL,OAAO,CAACM,OAAR,CAAiBL,UAAjB,CAAlB;;AACA,UAAKI,SAAS,KAAK,IAAnB,EAA0B;AACzBH,QAAAA,IAAI,GAAG,EAAP;AACA,OAFD,MAEO;AACN,YAAI;AACHA,UAAAA,IAAI,GAAGK,IAAI,CAACC,KAAL,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A,YAAY,GAAGD,cAAf;AACA;;AAEDrC,QAAAA,OAAO,GAAG,EACT,GAAGA,OADM;AAETsC,UAAAA;AAFS,SAAV;AAIA;;AAED,YAAMG,KAAK,GAAGtB,QAAQ,CAACgB,aAAT,CAAwBX,SAAxB,EAAmCxB,OAAnC,CAAd;AAEAyC,MAAAA,KAAK,CAACC,SAAN,CACCpB,qBAAqB,CACpBmB,KAAK,CAAClB,QADc,EAEpBC,SAFoB,EAGpBxB,OAAO,CAACoC,OAHY,CADtB;AAQA,aAAOK,KAAP;AACA;;AAhDK,GAAP;AAkDA;;AAEDvB,iBAAiB,CAACyB,iBAAlB,GAAsC,MAAM,CAAE,CAA9C;;AAEA,eAAezB,iBAAf","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/**\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"]}
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,OA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AAEAvB,iBAAiB,CAACyB,iBAAiB,GAAG,MAAM,CAAC,CAAC;AAE9C,eAAezB,iBAAiB"}
@@ -3,7 +3,6 @@
3
3
  */
4
4
  import objectStorage from './object';
5
5
  let storage;
6
-
7
6
  try {
8
7
  // Private Browsing in Safari 10 and earlier will throw an error when
9
8
  // attempting to set into localStorage. The test here is intentional in
@@ -14,6 +13,5 @@ try {
14
13
  } catch (error) {
15
14
  storage = objectStorage;
16
15
  }
17
-
18
16
  export default storage;
19
17
  //# sourceMappingURL=default.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/plugins/persistence/storage/default.js"],"names":["objectStorage","storage","window","localStorage","setItem","removeItem","error"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAP,MAA0B,UAA1B;AAEA,IAAIC,OAAJ;;AAEA,IAAI;AACH;AACA;AACA;AACAA,EAAAA,OAAO,GAAGC,MAAM,CAACC,YAAjB;AACAF,EAAAA,OAAO,CAACG,OAAR,CAAiB,0BAAjB,EAA6C,EAA7C;AACAH,EAAAA,OAAO,CAACI,UAAR,CAAoB,0BAApB;AACA,CAPD,CAOE,OAAQC,KAAR,EAAgB;AACjBL,EAAAA,OAAO,GAAGD,aAAV;AACA;;AAED,eAAeC,OAAf","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"]}
1
+ {"version":3,"names":["objectStorage","storage","window","localStorage","setItem","removeItem","error"],"sources":["@wordpress/data/src/plugins/persistence/storage/default.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAa,MAAM,UAAU;AAEpC,IAAIC,OAAO;AAEX,IAAI;EACH;EACA;EACA;EACAA,OAAO,GAAGC,MAAM,CAACC,YAAY;EAC7BF,OAAO,CAACG,OAAO,CAAE,0BAA0B,EAAE,EAAG,CAAC;EACjDH,OAAO,CAACI,UAAU,CAAE,0BAA2B,CAAC;AACjD,CAAC,CAAC,OAAQC,KAAK,EAAG;EACjBL,OAAO,GAAGD,aAAa;AACxB;AAEA,eAAeC,OAAO"}
@@ -4,22 +4,17 @@ const storage = {
4
4
  if (!objectStorage || !objectStorage[key]) {
5
5
  return null;
6
6
  }
7
-
8
7
  return objectStorage[key];
9
8
  },
10
-
11
9
  setItem(key, value) {
12
10
  if (!objectStorage) {
13
11
  storage.clear();
14
12
  }
15
-
16
13
  objectStorage[key] = String(value);
17
14
  },
18
-
19
15
  clear() {
20
16
  objectStorage = Object.create(null);
21
17
  }
22
-
23
18
  };
24
19
  export default storage;
25
20
  //# sourceMappingURL=object.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/plugins/persistence/storage/object.js"],"names":["objectStorage","storage","getItem","key","setItem","value","clear","String","Object","create"],"mappings":"AAAA,IAAIA,aAAJ;AAEA,MAAMC,OAAO,GAAG;AACfC,EAAAA,OAAO,CAAEC,GAAF,EAAQ;AACd,QAAK,CAAEH,aAAF,IAAmB,CAAEA,aAAa,CAAEG,GAAF,CAAvC,EAAiD;AAChD,aAAO,IAAP;AACA;;AAED,WAAOH,aAAa,CAAEG,GAAF,CAApB;AACA,GAPc;;AAQfC,EAAAA,OAAO,CAAED,GAAF,EAAOE,KAAP,EAAe;AACrB,QAAK,CAAEL,aAAP,EAAuB;AACtBC,MAAAA,OAAO,CAACK,KAAR;AACA;;AAEDN,IAAAA,aAAa,CAAEG,GAAF,CAAb,GAAuBI,MAAM,CAAEF,KAAF,CAA7B;AACA,GAdc;;AAefC,EAAAA,KAAK,GAAG;AACPN,IAAAA,aAAa,GAAGQ,MAAM,CAACC,MAAP,CAAe,IAAf,CAAhB;AACA;;AAjBc,CAAhB;AAoBA,eAAeR,OAAf","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"]}
1
+ {"version":3,"names":["objectStorage","storage","getItem","key","setItem","value","clear","String","Object","create"],"sources":["@wordpress/data/src/plugins/persistence/storage/object.js"],"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"],"mappings":"AAAA,IAAIA,aAAa;AAEjB,MAAMC,OAAO,GAAG;EACfC,OAAOA,CAAEC,GAAG,EAAG;IACd,IAAK,CAAEH,aAAa,IAAI,CAAEA,aAAa,CAAEG,GAAG,CAAE,EAAG;MAChD,OAAO,IAAI;IACZ;IAEA,OAAOH,aAAa,CAAEG,GAAG,CAAE;EAC5B,CAAC;EACDC,OAAOA,CAAED,GAAG,EAAEE,KAAK,EAAG;IACrB,IAAK,CAAEL,aAAa,EAAG;MACtBC,OAAO,CAACK,KAAK,CAAC,CAAC;IAChB;IAEAN,aAAa,CAAEG,GAAG,CAAE,GAAGI,MAAM,CAAEF,KAAM,CAAC;EACvC,CAAC;EACDC,KAAKA,CAAA,EAAG;IACPN,aAAa,GAAGQ,MAAM,CAACC,MAAM,CAAE,IAAK,CAAC;EACtC;AACD,CAAC;AAED,eAAeR,OAAO"}
@@ -2,12 +2,12 @@
2
2
  * External dependencies
3
3
  */
4
4
  import isPromise from 'is-promise';
5
+
5
6
  /**
6
7
  * Simplest possible promise redux middleware.
7
8
  *
8
9
  * @type {import('redux').Middleware}
9
10
  */
10
-
11
11
  const promiseMiddleware = () => next => action => {
12
12
  if (isPromise(action)) {
13
13
  return action.then(resolvedAction => {
@@ -16,9 +16,7 @@ const promiseMiddleware = () => next => action => {
16
16
  }
17
17
  });
18
18
  }
19
-
20
19
  return next(action);
21
20
  };
22
-
23
21
  export default promiseMiddleware;
24
22
  //# sourceMappingURL=promise-middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/promise-middleware.js"],"names":["isPromise","promiseMiddleware","next","action","then","resolvedAction"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,YAAtB;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,iBAAiB,GAAG,MAAQC,IAAF,IAAcC,MAAF,IAAc;AACzD,MAAKH,SAAS,CAAEG,MAAF,CAAd,EAA2B;AAC1B,WAAOA,MAAM,CAACC,IAAP,CAAeC,cAAF,IAAsB;AACzC,UAAKA,cAAL,EAAsB;AACrB,eAAOH,IAAI,CAAEG,cAAF,CAAX;AACA;AACD,KAJM,CAAP;AAKA;;AAED,SAAOH,IAAI,CAAEC,MAAF,CAAX;AACA,CAVD;;AAYA,eAAeF,iBAAf","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"]}
1
+ {"version":3,"names":["isPromise","promiseMiddleware","next","action","then","resolvedAction"],"sources":["@wordpress/data/src/promise-middleware.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,YAAY;;AAElC;AACA;AACA;AACA;AACA;AACA,MAAMC,iBAAiB,GAAGA,CAAA,KAAQC,IAAI,IAAQC,MAAM,IAAM;EACzD,IAAKH,SAAS,CAAEG,MAAO,CAAC,EAAG;IAC1B,OAAOA,MAAM,CAACC,IAAI,CAAIC,cAAc,IAAM;MACzC,IAAKA,cAAc,EAAG;QACrB,OAAOH,IAAI,CAAEG,cAAe,CAAC;MAC9B;IACD,CAAE,CAAC;EACJ;EAEA,OAAOH,IAAI,CAAEC,MAAO,CAAC;AACtB,CAAC;AAED,eAAeF,iBAAiB"}