-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Expand file tree
/
Copy pathindex.js
More file actions
108 lines (100 loc) · 2.86 KB
/
Copy pathindex.js
File metadata and controls
108 lines (100 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* WordPress dependencies
*/
import triggerFetch from '@wordpress/api-fetch';
import { controls as dataControls } from '@wordpress/data';
import deprecated from '@wordpress/deprecated';
/**
* Dispatches a control action for triggering an api fetch call.
*
* @param {Object} request Arguments for the fetch request.
*
* @example
* ```js
* import { apiFetch } from '@wordpress/data-controls';
*
* // Action generator using apiFetch
* export function* myAction() {
* const path = '/v2/my-api/items';
* const items = yield apiFetch( { path } );
* // do something with the items.
* }
* ```
*
* @return {Object} The control descriptor.
*/
export function apiFetch( request ) {
return {
type: 'API_FETCH',
request,
};
}
/**
* Control for resolving a selector in a registered data store.
* Alias for the `resolveSelect` built-in control in the `@wordpress/data` package.
*
* @param {Array} args Arguments passed without change to the `@wordpress/data` control.
*/
export function select( ...args ) {
deprecated( '`select` control in `@wordpress/data-controls`', {
alternative: 'built-in `resolveSelect` control in `@wordpress/data`',
} );
return dataControls.resolveSelect( ...args );
}
/**
* Control for calling a selector in a registered data store.
* Alias for the `select` built-in control in the `@wordpress/data` package.
*
* @param {Array} args Arguments passed without change to the `@wordpress/data` control.
*/
export function syncSelect( ...args ) {
deprecated( '`syncSelect` control in `@wordpress/data-controls`', {
alternative: 'built-in `select` control in `@wordpress/data`',
} );
return dataControls.select( ...args );
}
/**
* Control for dispatching an action in a registered data store.
* Alias for the `dispatch` control in the `@wordpress/data` package.
*
* @param {Array} args Arguments passed without change to the `@wordpress/data` control.
*/
export function dispatch( ...args ) {
deprecated( '`dispatch` control in `@wordpress/data-controls`', {
alternative: 'built-in `dispatch` control in `@wordpress/data`',
} );
return dataControls.dispatch( ...args );
}
/**
* The default export is what you use to register the controls with your custom
* store.
*
* @example
* ```js
* // WordPress dependencies
* import { controls } from '@wordpress/data-controls';
* import { registerStore } from '@wordpress/data';
*
* // Internal dependencies
* import reducer from './reducer';
* import * as selectors from './selectors';
* import * as actions from './actions';
* import * as resolvers from './resolvers';
*
* registerStore( 'my-custom-store', {
* reducer,
* controls,
* actions,
* selectors,
* resolvers,
* } );
* ```
*
* @return {Object} An object for registering the default controls with the
* store.
*/
export const controls = {
API_FETCH( { request } ) {
return triggerFetch( request );
},
};