@wordpress/data 10.28.1-next.0f6f9d12c.0 → 10.29.1-next.e256d081a.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/CHANGELOG.md +2 -0
- package/README.md +12 -9
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1004,12 +1004,13 @@ _Returns_
|
|
|
1004
1004
|
|
|
1005
1005
|
### batch
|
|
1006
1006
|
|
|
1007
|
-
|
|
1007
|
+
The `batch` method allows multiple store updates to occur simultaneously, reducing unnecessary executions of selectors and component re-renders during sequential state changes.
|
|
1008
1008
|
|
|
1009
|
-
-
|
|
1010
|
-
- If the selectors return values that are different than the previous (strict equality), the component rerenders.
|
|
1009
|
+
In WordPress data applications, dispatching consecutive actions typically triggers store listeners and runs selectors, which can lead to re-renders. The `batch` method pauses these listeners and only activates them once at the end, ensuring selectors run only once with the final state.
|
|
1011
1010
|
|
|
1012
|
-
|
|
1011
|
+
This method is particularly effective for optimizing performance with expensive selectors, ensuring atomic operations across multiple stores, and creating single undo/redo entries for several synchronous updates.
|
|
1012
|
+
|
|
1013
|
+
Unlike React’s built-in batching or React Redux’s `batch` function, `registry.batch` operates at the store listener level, completely avoiding unnecessary selector computations.
|
|
1013
1014
|
|
|
1014
1015
|
_Usage_
|
|
1015
1016
|
|
|
@@ -1019,15 +1020,17 @@ import { useRegistry } from '@wordpress/data';
|
|
|
1019
1020
|
function Component() {
|
|
1020
1021
|
const registry = useRegistry();
|
|
1021
1022
|
|
|
1022
|
-
function
|
|
1023
|
-
//
|
|
1023
|
+
function handleComplexUpdate() {
|
|
1024
|
+
// Without batch: listeners are called 3 times, which can result in multiple component re-renders.
|
|
1025
|
+
// With batch: notifies listeners once, resulting in a single component re-render as needed.
|
|
1024
1026
|
registry.batch( () => {
|
|
1025
|
-
registry.dispatch( someStore ).someAction();
|
|
1026
|
-
registry.dispatch( someStore ).someOtherAction();
|
|
1027
|
+
registry.dispatch( 'someStore' ).someAction();
|
|
1028
|
+
registry.dispatch( 'someStore' ).someOtherAction();
|
|
1029
|
+
registry.dispatch( 'someStore' ).thirdAction();
|
|
1027
1030
|
} );
|
|
1028
1031
|
}
|
|
1029
1032
|
|
|
1030
|
-
return <button onClick={
|
|
1033
|
+
return <button onClick={ handleComplexUpdate }>Update</button>;
|
|
1031
1034
|
}
|
|
1032
1035
|
```
|
|
1033
1036
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/data",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.29.1-next.e256d081a.0",
|
|
4
4
|
"description": "Data module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/runtime": "7.25.7",
|
|
34
|
-
"@wordpress/compose": "^7.
|
|
35
|
-
"@wordpress/deprecated": "^4.
|
|
36
|
-
"@wordpress/element": "^6.
|
|
37
|
-
"@wordpress/is-shallow-equal": "^5.
|
|
38
|
-
"@wordpress/priority-queue": "^3.
|
|
39
|
-
"@wordpress/private-apis": "^1.
|
|
40
|
-
"@wordpress/redux-routine": "^5.
|
|
34
|
+
"@wordpress/compose": "^7.29.1-next.e256d081a.0",
|
|
35
|
+
"@wordpress/deprecated": "^4.29.1-next.e256d081a.0",
|
|
36
|
+
"@wordpress/element": "^6.29.1-next.e256d081a.0",
|
|
37
|
+
"@wordpress/is-shallow-equal": "^5.29.1-next.e256d081a.0",
|
|
38
|
+
"@wordpress/priority-queue": "^3.29.1-next.e256d081a.0",
|
|
39
|
+
"@wordpress/private-apis": "^1.29.1-next.e256d081a.0",
|
|
40
|
+
"@wordpress/redux-routine": "^5.29.1-next.e256d081a.0",
|
|
41
41
|
"deepmerge": "^4.3.0",
|
|
42
42
|
"equivalent-key-map": "^0.2.2",
|
|
43
43
|
"is-plain-object": "^5.0.0",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "7d529ba9a461795d5f1572d3856de33f744287c2"
|
|
56
56
|
}
|