@@ -48,7 +48,9 @@ class Controller {
48
48
}
49
49
```
50
50
51
- ## fetch(endpoint, ...args) {#fetch}
51
+ ## Action Dispatchers
52
+
53
+ ### fetch(endpoint, ...args) {#fetch}
52
54
53
55
Fetches the endpoint with given args, updating the Reactive Data Client cache with
54
56
the response or error upon completion.
@@ -143,22 +145,22 @@ post.pk();
143
145
144
146
:::
145
147
146
- ### Endpoint.sideEffect
148
+ #### Endpoint.sideEffect
147
149
148
150
[ sideEffect] ( /rest/api/Endpoint#sideeffect ) changes the behavior
149
151
150
- #### true
152
+ ##### true
151
153
152
154
- Resolves _ before_ [ committing] ( https://react.dev/learn/render-and-commit#step-3-react-commits-changes-to-the-dom ) Reactive Data Client cache updates.
153
155
- Each call will always cause a new fetch.
154
156
155
- #### undefined
157
+ ##### undefined
156
158
157
159
- Resolves _ after_ [ committing] ( https://react.dev/learn/render-and-commit#step-3-react-commits-changes-to-the-dom ) Reactive Data Client cache updates.
158
160
- Identical requests are deduplicated globally; allowing only one inflight request at a time.
159
161
- To ensure a _ new_ request is started, make sure to abort any existing inflight requests.
160
162
161
- ## fetchIfStale(endpoint, ...args) {#fetchIfStale}
163
+ ### fetchIfStale(endpoint, ...args) {#fetchIfStale}
162
164
163
165
Fetches only if endpoint is considered '[ stale] ( ../concepts/expiry-policy.md#stale ) '.
164
166
@@ -190,7 +192,7 @@ An [example](https://stackblitz.com/github/reactive/data-client/tree/master/exam
190
192
191
193
<StackBlitz app =" github-app " file =" src/routing/routes.tsx " view =" editor " />
192
194
193
- ## expireAll(\{ testKey }) {#expireAll}
195
+ ### expireAll(\{ testKey }) {#expireAll}
194
196
195
197
Sets all responses' [ expiry status] ( ../concepts/expiry-policy.md ) matching ` testKey ` to [ Stale] ( ../concepts/expiry-policy.md#stale ) .
196
198
@@ -228,7 +230,7 @@ better to [include mutation sideeffects in the mutation response](/rest/guides/s
228
230
229
231
:::
230
232
231
- ## invalidate(endpoint, ...args) {#invalidate}
233
+ ### invalidate(endpoint, ...args) {#invalidate}
232
234
233
235
Forces refetching and suspense on [ useSuspense] ( ./useSuspense.md ) with the same Endpoint
234
236
and parameters.
@@ -268,7 +270,7 @@ controller.setResponse(MyResource.delete, { id: '5' }, { id: '5' });
268
270
269
271
:::
270
272
271
- ## invalidateAll(\{ testKey } ) { #invalidateAll }
273
+ ### invalidateAll(\{ testKey } ) { #invalidateAll }
272
274
273
275
[Invalidates](../concepts/expiry-policy#invalid) all [endpoint keys](/rest/api/RestEndpoint#key) matching `testKey`.
274
276
@@ -333,7 +335,7 @@ ReactDOM.createRoot(document.body).render(
333
335
);
334
336
```
335
337
336
- ## resetEntireStore() { #resetEntireStore }
338
+ ### resetEntireStore() { #resetEntireStore }
337
339
338
340
Resets/clears the entire Reactive Data Client cache. All inflight requests will not resolve.
339
341
@@ -361,7 +363,7 @@ function UserName() {
361
363
}
362
364
```
363
365
364
- ## set(queryable, ...args, value) { #set }
366
+ ### set(queryable, ...args, value) { #set }
365
367
366
368
Updates any [Queryable](/rest/api/schema#queryable) [Schema](/rest/api/schema#schema-overview).
367
369
@@ -380,7 +382,7 @@ const id = '2';
380
382
ctrl.set(Article, { id } , article => ({ id , votes : article .votes + 1 } ));
381
383
```
382
384
383
- ## setResponse(endpoint, ...args, response) { #setResponse }
385
+ ### setResponse(endpoint, ...args, response) { #setResponse }
384
386
385
387
Stores `response` in cache for given [Endpoint](/rest/api/Endpoint) and args.
386
388
@@ -408,11 +410,11 @@ useEffect(() => {
408
410
This shows a proof of concept in React; however a [Manager websockets implementation](../concepts/managers.md#data-stream)
409
411
would be much more robust.
410
412
411
- ## setError(endpoint, ...args, error) { #setError }
413
+ ### setError(endpoint, ...args, error) { #setError }
412
414
413
415
Stores the result of [Endpoint](/rest/api/Endpoint) and args as the error provided.
414
416
415
- ## resolve(endpoint, \{ args , response , fetchedAt , error } ) { #resolve }
417
+ ### resolve(endpoint, \{ args , response , fetchedAt , error } ) { #resolve }
416
418
417
419
Resolves a specific fetch, storing the `response` in cache.
418
420
@@ -422,7 +424,7 @@ This means the corresponding optimistic update will no longer be applies.
422
424
This is used in [NetworkManager](./NetworkManager.md), and should be used when
423
425
processing fetch requests.
424
426
425
- ## subscribe(endpoint, ...args) { #subscribe }
427
+ ### subscribe(endpoint, ...args) { #subscribe }
426
428
427
429
Marks a new subscription to a given [Endpoint](/rest/api/Endpoint). This should increment the subscription.
428
430
@@ -440,18 +442,20 @@ useEffect(() => {
440
442
} , [controller, key]);
441
443
```
442
444
443
- ## unsubscribe(endpoint, ...args) { #unsubscribe }
445
+ ### unsubscribe(endpoint, ...args) { #unsubscribe }
444
446
445
447
Marks completion of subscription to a given [Endpoint](/rest/api/Endpoint). This should
446
448
decrement the subscription and if the count reaches 0, more updates won't be received automatically.
447
449
448
450
[useSubscription](./useSubscription.md) and [useLive](./useLive.md) call this on unmount.
449
451
450
- ## get(schema, ...args, state) { #get }
452
+ ## Data Access
453
+
454
+ ### get(schema, ...args, state) { #get }
451
455
452
456
Looks up any [Queryable](/rest/api/schema#queryable) [Schema](/rest/api/schema#schema-overview) in `state`.
453
457
454
- ### Example
458
+ #### Example
455
459
456
460
This is used in [useQuery](./useQuery.md) and can be used in
457
461
[Managers](./Manager.md) to safely access the store.
@@ -477,7 +481,7 @@ function useQuery<S extends Queryable>(
477
481
}
478
482
```
479
483
480
- ## getResponse(endpoint, ...args, state) { #getResponse }
484
+ ### getResponse(endpoint, ...args, state) { #getResponse }
481
485
482
486
```ts title="returns"
483
487
{
@@ -489,11 +493,11 @@ function useQuery<S extends Queryable>(
489
493
490
494
Gets the (globally referentially stable) response for a given endpoint/args pair from state given.
491
495
492
- ### data
496
+ #### data
493
497
494
498
The denormalize response data. Guarantees global referential stability for all members.
495
499
496
- ### expiryStatus
500
+ #### expiryStatus
497
501
498
502
```ts
499
503
export enum ExpiryStatus {
@@ -503,26 +507,26 @@ export enum ExpiryStatus {
503
507
}
504
508
```
505
509
506
- #### Valid
510
+ ##### Valid
507
511
508
512
- Will never suspend.
509
513
- Might fetch if data is stale
510
514
511
- #### InvalidIfStale
515
+ ##### InvalidIfStale
512
516
513
517
- Will suspend if data is stale.
514
518
- Might fetch if data is stale
515
519
516
- #### Invalid
520
+ ##### Invalid
517
521
518
522
- Will always suspend
519
523
- Will always fetch
520
524
521
- ### expiresAt
525
+ #### expiresAt
522
526
523
527
A number representing time when it expires. Compare to Date.now().
524
528
525
- ### Example
529
+ #### Example
526
530
527
531
This is used in [useCache](./useCache.md), [useSuspense](./useSuspense.md) and can be used in
528
532
[Managers](./Manager.md) to lookup a response with the state provided.
@@ -572,15 +576,15 @@ export default class MyManager implements Manager {
572
576
}
573
577
```
574
578
575
- ## getError(endpoint, ...args, state) { #getError }
579
+ ### getError(endpoint, ...args, state) { #getError }
576
580
577
581
Gets the error, if any, for a given endpoint. Returns undefined for no errors.
578
582
579
- ## snapshot(state, fetchedAt) { #snapshot }
583
+ ### snapshot(state, fetchedAt) { #snapshot }
580
584
581
585
Returns a [Snapshot](./Snapshot.md).
582
586
583
- ## getState() { #getState }
587
+ ### getState() { #getState }
584
588
585
589
Gets the internal state of Reactive Data Client that has _already been [committed](https://react.dev/learn/render-and-commit#step-3-react-commits-changes-to-the-dom)_.
586
590
0 commit comments