@wordpress/data 10.12.0 → 10.13.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 +6 -0
- package/README.md +16 -21
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -42,13 +42,6 @@ const actions = {
|
|
|
42
42
|
discountPercent,
|
|
43
43
|
};
|
|
44
44
|
},
|
|
45
|
-
|
|
46
|
-
fetchFromAPI( path ) {
|
|
47
|
-
return {
|
|
48
|
-
type: 'FETCH_FROM_API',
|
|
49
|
-
path,
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
45
|
};
|
|
53
46
|
|
|
54
47
|
const store = createReduxStore( 'my-shop', {
|
|
@@ -84,17 +77,11 @@ const store = createReduxStore( 'my-shop', {
|
|
|
84
77
|
},
|
|
85
78
|
},
|
|
86
79
|
|
|
87
|
-
controls: {
|
|
88
|
-
FETCH_FROM_API( action ) {
|
|
89
|
-
return apiFetch( { path: action.path } );
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
|
|
93
80
|
resolvers: {
|
|
94
|
-
|
|
81
|
+
getPrice: ( item ) => async ({ dispatch }) => { {
|
|
95
82
|
const path = '/wp/v2/prices/' + item;
|
|
96
|
-
const price =
|
|
97
|
-
|
|
83
|
+
const price = await apiFetch( { path } );
|
|
84
|
+
dispatch.setPrice( item, price );
|
|
98
85
|
},
|
|
99
86
|
},
|
|
100
87
|
} );
|
|
@@ -133,13 +120,21 @@ A **resolver** is a side-effect for a selector. If your selector result may need
|
|
|
133
120
|
|
|
134
121
|
The `resolvers` option should be passed as an object where each key is the name of the selector to act upon, the value a function which receives the same arguments passed to the selector, excluding the state argument. It can then dispatch as necessary to fulfill the requirements of the selector, taking advantage of the fact that most data consumers will subscribe to subsequent state changes (by `subscribe` or `withSelect`).
|
|
135
122
|
|
|
136
|
-
|
|
123
|
+
Resolvers, in combination with [thunks](https://github.com/WordPress/gutenberg/blob/trunk/docs/how-to-guides/thunks.md#thunks-can-be-async), can be used to implement asynchronous data flows for your store.
|
|
137
124
|
|
|
138
|
-
|
|
125
|
+
#### `controls` (deprecated)
|
|
139
126
|
|
|
140
|
-
|
|
127
|
+
To handle asynchronous data flows, it is recommended to use [thunks](https://github.com/WordPress/gutenberg/blob/trunk/docs/how-to-guides/thunks.md#thunks-can-be-async) instead of `controls`.
|
|
141
128
|
|
|
142
|
-
|
|
129
|
+
<details>
|
|
130
|
+
<summary>View <em>controls</em> explanation</summary>
|
|
131
|
+
<br>
|
|
132
|
+
A <em>control</em> defines the execution flow behavior associated with a specific action type. Before <a href="https://github.com/WordPress/gutenberg/blob/trunk/docs/how-to-guides/thunks.md#thunks-can-be-async">thunks</a>, controls were used to implement asynchronous data flows for your store. By defining your action creator or resolvers as a generator which yields specific controlled action types, the execution will proceed as defined by the control handler.
|
|
133
|
+
<br><br>
|
|
134
|
+
The <em>controls</em> option should be passed as an object where each key is the name of the action type to act upon, the value a function which receives the original action object. It should returns either a promise which is to resolve when evaluation of the action should continue, or a value. The value or resolved promise value is assigned on the return value of the yield assignment. If the control handler returns undefined, the execution is not continued.
|
|
135
|
+
<br><br>
|
|
136
|
+
Refer to the <a href="https://github.com/WordPress/gutenberg/tree/HEAD/packages/redux-routine/README.md">documentation of <em>@wordpress/redux-routine</em></a> for more information.
|
|
137
|
+
</details>
|
|
143
138
|
|
|
144
139
|
#### `initialState`
|
|
145
140
|
|
|
@@ -262,7 +257,7 @@ The data module shares many of the same [core principles](https://redux.js.org/i
|
|
|
262
257
|
|
|
263
258
|
The [higher-order components](#higher-order-components) were created to complement this distinction. The intention with splitting `withSelect` and `withDispatch` — where in React Redux they are combined under `connect` as `mapStateToProps` and `mapDispatchToProps` arguments — is to more accurately reflect that dispatch is not dependent upon a subscription to state changes, and to allow for state-derived values to be used in `withDispatch` (via [higher-order component composition](https://github.com/WordPress/gutenberg/tree/HEAD/packages/compose/README.md)).
|
|
264
259
|
|
|
265
|
-
The data module also has built-in solutions for handling asynchronous side-effects, through [resolvers](#resolvers) and [
|
|
260
|
+
The data module also has built-in solutions for handling asynchronous side-effects, through [resolvers](#resolvers) and [thunks](https://github.com/WordPress/gutenberg/blob/trunk/docs/how-to-guides/thunks.md#thunks-can-be-async). These differ slightly from [standard redux async solutions](https://redux.js.org/advanced/async-actions) like [`redux-thunk`](https://github.com/gaearon/redux-thunk) or [`redux-saga`](https://redux-saga.js.org/).
|
|
266
261
|
|
|
267
262
|
Specific implementation differences from Redux and React Redux:
|
|
268
263
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/data",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.13.0",
|
|
4
4
|
"description": "Data module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "cce81c13739c2a8b53d91df90c4f037cb68c2665"
|
|
56
56
|
}
|