@wordpress/data 8.5.0 → 9.0.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 (48) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/build/components/use-select/index.js +90 -55
  3. package/build/components/use-select/index.js.map +1 -1
  4. package/build/components/with-dispatch/index.js +2 -0
  5. package/build/components/with-dispatch/index.js.map +1 -1
  6. package/build/components/with-select/index.js +2 -0
  7. package/build/components/with-select/index.js.map +1 -1
  8. package/build/registry.js +16 -7
  9. package/build/registry.js.map +1 -1
  10. package/build-module/components/use-select/index.js +90 -55
  11. package/build-module/components/use-select/index.js.map +1 -1
  12. package/build-module/components/with-dispatch/index.js +2 -0
  13. package/build-module/components/with-dispatch/index.js.map +1 -1
  14. package/build-module/components/with-select/index.js +2 -0
  15. package/build-module/components/with-select/index.js.map +1 -1
  16. package/build-module/registry.js +16 -7
  17. package/build-module/registry.js.map +1 -1
  18. package/build-types/components/use-select/index.d.ts.map +1 -1
  19. package/build-types/components/with-dispatch/index.d.ts +3 -1
  20. package/build-types/components/with-dispatch/index.d.ts.map +1 -1
  21. package/build-types/components/with-select/index.d.ts +3 -1
  22. package/build-types/components/with-select/index.d.ts.map +1 -1
  23. package/build-types/default-registry.d.ts +1 -1
  24. package/build-types/plugins/persistence/storage/object.d.ts +0 -3
  25. package/build-types/plugins/persistence/storage/object.d.ts.map +1 -1
  26. package/build-types/redux-store/metadata/reducer.d.ts +5 -5
  27. package/build-types/redux-store/metadata/reducer.d.ts.map +1 -1
  28. package/build-types/registry.d.ts.map +1 -1
  29. package/build-types/store/index.d.ts +0 -9
  30. package/build-types/store/index.d.ts.map +1 -1
  31. package/build-types/types.d.ts +16 -16
  32. package/build-types/types.d.ts.map +1 -1
  33. package/package.json +9 -9
  34. package/src/components/use-dispatch/test/use-dispatch.js +0 -2
  35. package/src/components/use-select/index.js +87 -57
  36. package/src/components/use-select/test/index.js +246 -164
  37. package/src/components/use-select/test/suspense.js +0 -2
  38. package/src/components/with-dispatch/index.js +2 -0
  39. package/src/components/with-dispatch/test/index.js +0 -2
  40. package/src/components/with-select/index.js +2 -0
  41. package/src/components/with-select/test/index.js +0 -2
  42. package/src/redux-store/metadata/test/selectors.js +0 -1
  43. package/src/redux-store/test/index.js +0 -2
  44. package/src/registry.js +20 -8
  45. package/src/test/controls.js +0 -2
  46. package/src/test/privateAPIs.js +0 -13
  47. package/src/test/registry.js +32 -30
  48. package/tsconfig.tsbuildinfo +1 -1
@@ -10,14 +10,5 @@ declare namespace coreDataStore {
10
10
  };
11
11
  subscribe(): () => () => void;
12
12
  };
13
- function instantiate(registry: any): {
14
- getSelectors(): {
15
- [k: string]: (key: any, ...args: any[]) => any;
16
- };
17
- getActions(): {
18
- [k: string]: (key: any, ...args: any[]) => any;
19
- };
20
- subscribe(): () => () => void;
21
- };
22
13
  }
23
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.js"],"names":[],"mappings":";;;IAEC;;;;;;;;MAoDC;IApDD;;;;;;;;MAoDC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.js"],"names":[],"mappings":";;;IAEC;;;;;;;;MAoDC"}
@@ -2,13 +2,13 @@
2
2
  * External dependencies
3
3
  */
4
4
  import type { combineReducers as reduxCombineReducers } from 'redux';
5
- declare type MapOf<T> = {
5
+ type MapOf<T> = {
6
6
  [name: string]: T;
7
7
  };
8
- export declare type ActionCreator = Function | Generator;
9
- export declare type Resolver = Function | Generator;
10
- export declare type Selector = Function;
11
- export declare type AnyConfig = ReduxStoreConfig<any, any, any>;
8
+ export type ActionCreator = Function | Generator;
9
+ export type Resolver = Function | Generator;
10
+ export type Selector = Function;
11
+ export type AnyConfig = ReduxStoreConfig<any, any, any>;
12
12
  export interface StoreInstance<Config extends AnyConfig> {
13
13
  getSelectors: () => SelectorsOf<Config>;
14
14
  getActions: () => ActionCreatorsOf<Config>;
@@ -32,12 +32,12 @@ export interface ReduxStoreConfig<State, ActionCreators extends MapOf<ActionCrea
32
32
  selectors?: Selectors;
33
33
  controls?: MapOf<Function>;
34
34
  }
35
- export declare type UseSelectReturn<F extends MapSelect | StoreDescriptor<any>> = F extends MapSelect ? ReturnType<F> : F extends StoreDescriptor<any> ? CurriedSelectorsOf<F> : never;
36
- export declare type UseDispatchReturn<StoreNameOrDescriptor> = StoreNameOrDescriptor extends StoreDescriptor<any> ? ActionCreatorsOf<ConfigOf<StoreNameOrDescriptor>> : StoreNameOrDescriptor extends undefined ? DispatchFunction : any;
37
- export declare type DispatchFunction = <StoreNameOrDescriptor>(store: StoreNameOrDescriptor) => StoreNameOrDescriptor extends StoreDescriptor<any> ? ActionCreatorsOf<ConfigOf<StoreNameOrDescriptor>> : any;
38
- export declare type MapSelect = (select: SelectFunction, registry: DataRegistry) => any;
39
- export declare type SelectFunction = <S>(store: S) => CurriedSelectorsOf<S>;
40
- export declare type CurriedSelectorsOf<S> = S extends StoreDescriptor<ReduxStoreConfig<any, any, infer Selectors>> ? {
35
+ export type UseSelectReturn<F extends MapSelect | StoreDescriptor<any>> = F extends MapSelect ? ReturnType<F> : F extends StoreDescriptor<any> ? CurriedSelectorsOf<F> : never;
36
+ export type UseDispatchReturn<StoreNameOrDescriptor> = StoreNameOrDescriptor extends StoreDescriptor<any> ? ActionCreatorsOf<ConfigOf<StoreNameOrDescriptor>> : StoreNameOrDescriptor extends undefined ? DispatchFunction : any;
37
+ export type DispatchFunction = <StoreNameOrDescriptor>(store: StoreNameOrDescriptor) => StoreNameOrDescriptor extends StoreDescriptor<any> ? ActionCreatorsOf<ConfigOf<StoreNameOrDescriptor>> : any;
38
+ export type MapSelect = (select: SelectFunction, registry: DataRegistry) => any;
39
+ export type SelectFunction = <S>(store: S) => CurriedSelectorsOf<S>;
40
+ export type CurriedSelectorsOf<S> = S extends StoreDescriptor<ReduxStoreConfig<any, any, infer Selectors>> ? {
41
41
  [key in keyof Selectors]: CurriedState<Selectors[key]>;
42
42
  } : never;
43
43
  /**
@@ -61,7 +61,7 @@ export declare type CurriedSelectorsOf<S> = S extends StoreDescriptor<ReduxStore
61
61
  * interdependent generic parameters.
62
62
  * For more context, see https://github.com/WordPress/gutenberg/pull/41578
63
63
  */
64
- declare type CurriedState<F> = F extends SelectorWithCustomCurrySignature ? F['CurriedSignature'] : F extends (state: any, ...args: infer P) => infer R ? (...args: P) => R : F;
64
+ type CurriedState<F> = F extends SelectorWithCustomCurrySignature ? F['CurriedSignature'] : F extends (state: any, ...args: infer P) => infer R ? (...args: P) => R : F;
65
65
  /**
66
66
  * Utility to manually specify curried selector signatures.
67
67
  *
@@ -114,11 +114,11 @@ export interface DataEmitter {
114
114
  resume: () => void;
115
115
  isPaused: boolean;
116
116
  }
117
- export declare type ConfigOf<S> = S extends StoreDescriptor<infer C> ? C : never;
118
- export declare type ActionCreatorsOf<Config extends AnyConfig> = Config extends ReduxStoreConfig<any, infer ActionCreators, any> ? ActionCreators : never;
119
- declare type SelectorsOf<Config extends AnyConfig> = Config extends ReduxStoreConfig<any, any, infer Selectors> ? {
117
+ export type ConfigOf<S> = S extends StoreDescriptor<infer C> ? C : never;
118
+ export type ActionCreatorsOf<Config extends AnyConfig> = Config extends ReduxStoreConfig<any, infer ActionCreators, any> ? ActionCreators : never;
119
+ type SelectorsOf<Config extends AnyConfig> = Config extends ReduxStoreConfig<any, any, infer Selectors> ? {
120
120
  [name in keyof Selectors]: Function;
121
121
  } : never;
122
- export declare type combineReducers = typeof reduxCombineReducers;
122
+ export type combineReducers = typeof reduxCombineReducers;
123
123
  export {};
124
124
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,IAAI,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAErE,aAAK,KAAK,CAAE,CAAC,I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B,EAAE,QAAQ,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,EAAE,CAAE,KAAK,EAAE,eAAe,CAAE,GAAG,CAAE,KAAM,IAAI,CAAC;CACpD;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,SAAS,EAAE,CAAE,QAAQ,EAAE,MAAM,IAAI,KAAM,MAAM,IAAI,CAAC;IAClD,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;CAClB;AAID,MAAM,MAAM,QAAQ,CAAE,CAAC,IAAK,CAAC,SAAS,eAAe,CAAE,MAAM,CAAC,CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAE7E,MAAM,MAAM,gBAAgB,CAAE,MAAM,SAAS,SAAS,IACrD,MAAM,SAAS,gBAAgB,CAAE,GAAG,EAAE,MAAM,cAAc,EAAE,GAAG,CAAE,GAC9D,cAAc,GACd,KAAK,CAAC;AAEV,KAAK,WAAW,CAAE,MAAM,SAAS,SAAS,IAAK,MAAM,SAAS,gBAAgB,CAC7E,GAAG,EACH,GAAG,EACH,MAAM,SAAS,CACf,GACE;KAAI,IAAI,IAAI,MAAM,SAAS,GAAI,QAAQ;CAAE,GACzC,KAAK,CAAC;AAET,MAAM,MAAM,eAAe,GAAG,OAAO,oBAAoB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/data",
3
- "version": "8.5.0",
3
+ "version": "9.0.0",
4
4
  "description": "Data module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -29,13 +29,13 @@
29
29
  "sideEffects": false,
30
30
  "dependencies": {
31
31
  "@babel/runtime": "^7.16.0",
32
- "@wordpress/compose": "^6.5.0",
33
- "@wordpress/deprecated": "^3.28.0",
34
- "@wordpress/element": "^5.5.0",
35
- "@wordpress/is-shallow-equal": "^4.28.0",
36
- "@wordpress/priority-queue": "^2.28.0",
37
- "@wordpress/private-apis": "^0.10.0",
38
- "@wordpress/redux-routine": "^4.28.0",
32
+ "@wordpress/compose": "^6.7.0",
33
+ "@wordpress/deprecated": "^3.30.0",
34
+ "@wordpress/element": "^5.7.0",
35
+ "@wordpress/is-shallow-equal": "^4.30.0",
36
+ "@wordpress/priority-queue": "^2.30.0",
37
+ "@wordpress/private-apis": "^0.12.0",
38
+ "@wordpress/redux-routine": "^4.30.0",
39
39
  "deepmerge": "^4.3.0",
40
40
  "equivalent-key-map": "^0.2.2",
41
41
  "is-plain-object": "^5.0.0",
@@ -50,5 +50,5 @@
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "gitHead": "d5e03a74b79e3ca84afda24375474a103a063ee4"
53
+ "gitHead": "d5c28a67b11e91e3e4b8e90346bfcb90909364d6"
54
54
  }
@@ -12,8 +12,6 @@ import createReduxStore from '../../../redux-store';
12
12
  import { createRegistry } from '../../../registry';
13
13
  import { RegistryProvider } from '../../registry-provider';
14
14
 
15
- jest.useRealTimers();
16
-
17
15
  describe( 'useDispatch', () => {
18
16
  const counterStore = {
19
17
  reducer: ( state = 0, action ) => {
@@ -42,48 +42,85 @@ function Store( registry, suspense ) {
42
42
  let lastMapResult;
43
43
  let lastMapResultValid = false;
44
44
  let lastIsAsync;
45
- let subscribe;
46
-
47
- const createSubscriber = ( stores ) => ( listener ) => {
48
- // Invalidate the value right after subscription was created. React will
49
- // call `getValue` after subscribing, to detect store updates that happened
50
- // in the interval between the `getValue` call during render and creating
51
- // the subscription, which is slightly delayed. We need to ensure that this
52
- // second `getValue` call will compute a fresh value.
53
- lastMapResultValid = false;
54
-
55
- const onStoreChange = () => {
56
- // Invalidate the value on store update, so that a fresh value is computed.
45
+ let subscriber;
46
+
47
+ const createSubscriber = ( stores ) => {
48
+ // The set of stores the `subscribe` function is supposed to subscribe to. Here it is
49
+ // initialized, and then the `updateStores` function can add new stores to it.
50
+ const activeStores = [ ...stores ];
51
+
52
+ // The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could
53
+ // be called multiple times to establish multiple subscriptions. That's why we need to
54
+ // keep a set of active subscriptions;
55
+ const activeSubscriptions = new Set();
56
+
57
+ function subscribe( listener ) {
58
+ // Invalidate the value right after subscription was created. React will
59
+ // call `getValue` after subscribing, to detect store updates that happened
60
+ // in the interval between the `getValue` call during render and creating
61
+ // the subscription, which is slightly delayed. We need to ensure that this
62
+ // second `getValue` call will compute a fresh value.
57
63
  lastMapResultValid = false;
58
- listener();
59
- };
60
64
 
61
- const onChange = () => {
62
- if ( lastIsAsync ) {
63
- renderQueue.add( queueContext, onStoreChange );
64
- } else {
65
- onStoreChange();
65
+ const onStoreChange = () => {
66
+ // Invalidate the value on store update, so that a fresh value is computed.
67
+ lastMapResultValid = false;
68
+ listener();
69
+ };
70
+
71
+ const onChange = () => {
72
+ if ( lastIsAsync ) {
73
+ renderQueue.add( queueContext, onStoreChange );
74
+ } else {
75
+ onStoreChange();
76
+ }
77
+ };
78
+
79
+ const unsubs = [];
80
+ function subscribeStore( storeName ) {
81
+ unsubs.push( registry.subscribe( onChange, storeName ) );
66
82
  }
67
- };
68
83
 
69
- const unsubs = stores.map( ( storeName ) => {
70
- return registry.subscribe( onChange, storeName );
71
- } );
84
+ for ( const storeName of activeStores ) {
85
+ subscribeStore( storeName );
86
+ }
87
+
88
+ activeSubscriptions.add( subscribeStore );
89
+
90
+ return () => {
91
+ activeSubscriptions.delete( subscribeStore );
92
+
93
+ for ( const unsub of unsubs.values() ) {
94
+ // The return value of the subscribe function could be undefined if the store is a custom generic store.
95
+ unsub?.();
96
+ }
97
+ // Cancel existing store updates that were already scheduled.
98
+ renderQueue.cancel( queueContext );
99
+ };
100
+ }
101
+
102
+ // Check if `newStores` contains some stores we're not subscribed to yet, and add them.
103
+ function updateStores( newStores ) {
104
+ for ( const newStore of newStores ) {
105
+ if ( activeStores.includes( newStore ) ) {
106
+ continue;
107
+ }
108
+
109
+ // New `subscribe` calls will subscribe to `newStore`, too.
110
+ activeStores.push( newStore );
72
111
 
73
- return () => {
74
- // The return value of the subscribe function could be undefined if the store is a custom generic store.
75
- for ( const unsub of unsubs ) {
76
- unsub?.();
112
+ // Add `newStore` to existing subscriptions.
113
+ for ( const subscription of activeSubscriptions ) {
114
+ subscription( newStore );
115
+ }
77
116
  }
78
- // Cancel existing store updates that were already scheduled.
79
- renderQueue.cancel( queueContext );
80
- };
81
- };
117
+ }
82
118
 
83
- return ( mapSelect, resubscribe, isAsync ) => {
84
- const selectValue = () => mapSelect( select, registry );
119
+ return { subscribe, updateStores };
120
+ };
85
121
 
86
- function updateValue( selectFromStore ) {
122
+ return ( mapSelect, isAsync ) => {
123
+ function updateValue() {
87
124
  // If the last value is valid, and the `mapSelect` callback hasn't changed,
88
125
  // then we can safely return the cached value. The value can change only on
89
126
  // store update, and in that case value will be invalidated by the listener.
@@ -91,19 +128,30 @@ function Store( registry, suspense ) {
91
128
  return lastMapResult;
92
129
  }
93
130
 
94
- const mapResult = selectFromStore();
131
+ const listeningStores = { current: null };
132
+ const mapResult = registry.__unstableMarkListeningStores(
133
+ () => mapSelect( select, registry ),
134
+ listeningStores
135
+ );
136
+
137
+ if ( ! subscriber ) {
138
+ subscriber = createSubscriber( listeningStores.current );
139
+ } else {
140
+ subscriber.updateStores( listeningStores.current );
141
+ }
95
142
 
96
143
  // If the new value is shallow-equal to the old one, keep the old one so
97
144
  // that we don't trigger unwanted updates that do a `===` check.
98
145
  if ( ! isShallowEqual( lastMapResult, mapResult ) ) {
99
146
  lastMapResult = mapResult;
100
147
  }
148
+ lastMapSelect = mapSelect;
101
149
  lastMapResultValid = true;
102
150
  }
103
151
 
104
152
  function getValue() {
105
153
  // Update the value in case it's been invalidated or `mapSelect` has changed.
106
- updateValue( selectValue );
154
+ updateValue();
107
155
  return lastMapResult;
108
156
  }
109
157
 
@@ -115,30 +163,12 @@ function Store( registry, suspense ) {
115
163
  renderQueue.cancel( queueContext );
116
164
  }
117
165
 
118
- // Either initialize the `subscribe` function, or create a new one if `mapSelect`
119
- // changed and has dependencies.
120
- // Usage without dependencies, `useSelect( ( s ) => { ... } )`, will subscribe
121
- // only once, at mount, and won't resubscibe even if `mapSelect` changes.
122
- if ( ! subscribe || ( resubscribe && mapSelect !== lastMapSelect ) ) {
123
- // Find out what stores the `mapSelect` callback is selecting from and
124
- // use that list to create subscriptions to specific stores.
125
- const listeningStores = { current: null };
126
- updateValue( () =>
127
- registry.__unstableMarkListeningStores(
128
- selectValue,
129
- listeningStores
130
- )
131
- );
132
- subscribe = createSubscriber( listeningStores.current );
133
- } else {
134
- updateValue( selectValue );
135
- }
166
+ updateValue();
136
167
 
137
168
  lastIsAsync = isAsync;
138
- lastMapSelect = mapSelect;
139
169
 
140
170
  // Return a pair of functions that can be passed to `useSyncExternalStore`.
141
- return { subscribe, getValue };
171
+ return { subscribe: subscriber.subscribe, getValue };
142
172
  };
143
173
  }
144
174
 
@@ -151,7 +181,7 @@ function useMappingSelect( suspense, mapSelect, deps ) {
151
181
  const isAsync = useAsyncMode();
152
182
  const store = useMemo( () => Store( registry, suspense ), [ registry ] );
153
183
  const selector = useCallback( mapSelect, deps );
154
- const { subscribe, getValue } = store( selector, !! deps, isAsync );
184
+ const { subscribe, getValue } = store( selector, isAsync );
155
185
  const result = useSyncExternalStore( subscribe, getValue, getValue );
156
186
  useDebugValue( result );
157
187
  return result;