@@ -5,7 +5,6 @@ import type {
5
5
Denormalize ,
6
6
Queryable ,
7
7
SchemaArgs ,
8
- NI ,
9
8
} from '@data-client/normalizr' ;
10
9
import {
11
10
ExpiryStatus ,
@@ -27,6 +26,7 @@ import createInvalidate from './createInvalidate.js';
27
26
import createInvalidateAll from './createInvalidateAll.js' ;
28
27
import createReset from './createReset.js' ;
29
28
import createSet from './createSet.js' ;
29
+ import createSetResponse from './createSetResponse.js' ;
30
30
import {
31
31
createUnsubscription ,
32
32
createSubscription ,
@@ -183,9 +183,26 @@ export default class Controller<
183
183
resetEntireStore = ( ) : Promise < void > => this . dispatch ( createReset ( ) ) ;
184
184
185
185
/**
186
- * Stores response in cache for given Endpoint and args.
186
+ * Sets value for the Queryable and args.
187
187
* @see https://dataclient.io/docs/api/Controller#set
188
188
*/
189
+ set = < S extends Queryable > (
190
+ schema : S ,
191
+ ...rest : readonly [ ...SchemaArgs < S > , any ]
192
+ ) : Promise < void > => {
193
+ const value : Denormalize < S > = rest [ rest . length - 1 ] ;
194
+ const action = createSet ( schema , {
195
+ args : rest . slice ( 0 , rest . length - 1 ) as SchemaArgs < S > ,
196
+ value,
197
+ } ) ;
198
+ // TODO: reject with error if this fails in reducer
199
+ return this . dispatch ( action ) ;
200
+ } ;
201
+
202
+ /**
203
+ * Sets response for the Endpoint and args.
204
+ * @see https://dataclient.io/docs/api/Controller#setResponse
205
+ */
189
206
setResponse = <
190
207
E extends EndpointInterface & {
191
208
update ?: EndpointUpdateFunction < E > ;
@@ -195,15 +212,15 @@ export default class Controller<
195
212
...rest : readonly [ ...Parameters < E > , any ]
196
213
) : Promise < void > => {
197
214
const response : ResolveType < E > = rest [ rest . length - 1 ] ;
198
- const action = createSet ( endpoint , {
215
+ const action = createSetResponse ( endpoint , {
199
216
args : rest . slice ( 0 , rest . length - 1 ) as Parameters < E > ,
200
217
response,
201
218
} ) ;
202
219
return this . dispatch ( action ) ;
203
220
} ;
204
221
205
222
/**
206
- * Stores the result of Endpoint and args as the error provided .
223
+ * Sets an error response for the Endpoint and args.
207
224
* @see https://dataclient.io/docs/api/Controller#setError
208
225
*/
209
226
setError = <
@@ -215,7 +232,7 @@ export default class Controller<
215
232
...rest : readonly [ ...Parameters < E > , Error ]
216
233
) : Promise < void > => {
217
234
const response : Error = rest [ rest . length - 1 ] ;
218
- const action = createSet ( endpoint , {
235
+ const action = createSetResponse ( endpoint , {
219
236
args : rest . slice ( 0 , rest . length - 1 ) as Parameters < E > ,
220
237
response,
221
238
error : true ,
@@ -247,7 +264,7 @@ export default class Controller<
247
264
error ?: false | undefined ;
248
265
} ,
249
266
) : Promise < void > => {
250
- return this . dispatch ( createSet ( endpoint , meta as any ) ) ;
267
+ return this . dispatch ( createSetResponse ( endpoint , meta as any ) ) ;
251
268
} ;
252
269
253
270
/**
0 commit comments