Skip to content

Commit e9b74c6

Browse files
committed
docs: Organize controller methods
1 parent 3b337e7 commit e9b74c6

File tree

2 files changed

+103
-40
lines changed

2 files changed

+103
-40
lines changed

README.md

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,77 @@ For the small price of 9kb gziped.    [🏁Get started now](https://da
276276

277277
- Rendering: [useSuspense()](https://dataclient.io/docs/api/useSuspense), [useLive()](https://dataclient.io/docs/api/useLive), [useCache()](https://dataclient.io/docs/api/useCache), [useDLE()](https://dataclient.io/docs/api/useDLE), [useQuery()](https://dataclient.io/docs/api/useQuery)
278278
- Event handling: [useController()](https://dataclient.io/docs/api/useController) returns [Controller](https://dataclient.io/docs/api/Controller)
279-
- [ctrl.fetch](https://dataclient.io/docs/api/Controller#fetch)
280-
- [ctrl.fetchIfStale](https://dataclient.io/docs/api/Controller#fetchIfStale)
281-
- [ctrl.expireAll](https://dataclient.io/docs/api/Controller#expireAll)
282-
- [ctrl.invalidate](https://dataclient.io/docs/api/Controller#invalidate)
283-
- [ctrl.invalidateAll](https://dataclient.io/docs/api/Controller#invalidateAll)
284-
- [ctrl.resetEntireStore](https://dataclient.io/docs/api/Controller#resetEntireStore)
285-
- [ctrl.set](https://dataclient.io/docs/api/Controller#set)
286-
- [ctrl.setResponse](https://dataclient.io/docs/api/Controller#setResponse)
287-
- [ctrl.setError](https://dataclient.io/docs/api/Controller#setError)
288-
- [ctrl.resolve](https://dataclient.io/docs/api/Controller#resolve)
289-
- [ctrl.subscribe](https://dataclient.io/docs/api/Controller#subscribe)
290-
- [ctrl.unsubscribe](https://dataclient.io/docs/api/Controller#unsubscribe)
279+
<table>
280+
<thead>
281+
<tr>
282+
<th>Method</th>
283+
<th>Subject</th>
284+
</tr>
285+
</thead>
286+
<tbody>
287+
<tr>
288+
<th colSpan="2" align="center">Fetch</th>
289+
</tr>
290+
<tr>
291+
<td><a href="https://dataclient.io/docs/api/Controller#fetch">ctrl.fetch</a></td>
292+
<td>Endpoint + Args</td>
293+
</tr>
294+
<tr>
295+
<td><a href="https://dataclient.io/docs/api/Controller#fetchIfStale">ctrl.fetchIfStale</a></td>
296+
<td>Endpoint + Args</td>
297+
</tr>
298+
<tr>
299+
<th colSpan="2" align="center">Expiry</th>
300+
</tr>
301+
<tr>
302+
<td><a href="https://dataclient.io/docs/api/Controller#expireAll">ctrl.expireAll</a></td>
303+
<td>Endpoint</td>
304+
</tr>
305+
<tr>
306+
<td><a href="https://dataclient.io/docs/api/Controller#invalidate">ctrl.invalidate</a></td>
307+
<td>Endpoint + Args</td>
308+
</tr>
309+
<tr>
310+
<td><a href="https://dataclient.io/docs/api/Controller#invalidateAll">ctrl.invalidateAll</a></td>
311+
<td>Endpoint</td>
312+
</tr>
313+
<tr>
314+
<td><a href="https://dataclient.io/docs/api/Controller#resetEntireStore">ctrl.resetEntireStore</a></td>
315+
<td>Everything</td>
316+
</tr>
317+
<tr>
318+
<th colSpan="2" align="center">Set</th>
319+
</tr>
320+
<tr>
321+
<td><a href="https://dataclient.io/docs/api/Controller#set">ctrl.set</a></td>
322+
<td>Schema + Args</td>
323+
</tr>
324+
<tr>
325+
<td><a href="https://dataclient.io/docs/api/Controller#setResponse">ctrl.setResponse</a></td>
326+
<td>Endpoint + Args</td>
327+
</tr>
328+
<tr>
329+
<td><a href="https://dataclient.io/docs/api/Controller#setError">ctrl.setError</a></td>
330+
<td>Endpoint + Args</td>
331+
</tr>
332+
<tr>
333+
<td><a href="https://dataclient.io/docs/api/Controller#resolve">ctrl.resolve</a></td>
334+
<td>Endpoint + Args</td>
335+
</tr>
336+
<tr>
337+
<th colSpan="2" align="center">Subscription</th>
338+
</tr>
339+
<tr>
340+
<td><a href="https://dataclient.io/docs/api/Controller#subscribe">ctrl.subscribe</a></td>
341+
<td>Endpoint + Args</td>
342+
</tr>
343+
<tr>
344+
<td><a href="https://dataclient.io/docs/api/Controller#unsubscribe">ctrl.unsubscribe</a></td>
345+
<td>Endpoint + Args</td>
346+
</tr>
347+
</tbody>
348+
</table>
349+
291350
- Components: [&lt;DataProvider/>](https://dataclient.io/docs/api/DataProvider), [&lt;AsyncBoundary/>](https://dataclient.io/docs/api/AsyncBoundary), [&lt;ErrorBoundary/>](https://dataclient.io/docs/api/ErrorBoundary), [&lt;MockResolver/>](https://dataclient.io/docs/api/MockResolver)
292351
- Data Mocking: [Fixture](https://dataclient.io/docs/api/Fixtures#successfixture), [Interceptor](https://dataclient.io/docs/api/Fixtures#interceptor), [renderDataClient()](https://dataclient.io/docs/api/makeRenderDataClient)
293352
- Middleware: [LogoutManager](https://dataclient.io/docs/api/LogoutManager), [NetworkManager](https://dataclient.io/docs/api/NetworkManager), [SubscriptionManager](https://dataclient.io/docs/api/SubscriptionManager), [PollingSubscription](https://dataclient.io/docs/api/PollingSubscription), [DevToolsManager](https://dataclient.io/docs/api/DevToolsManager)

docs/core/api/Controller.md

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ class Controller {
4848
}
4949
```
5050

51-
## fetch(endpoint, ...args) {#fetch}
51+
## Action Dispatchers
52+
53+
### fetch(endpoint, ...args) {#fetch}
5254

5355
Fetches the endpoint with given args, updating the Reactive Data Client cache with
5456
the response or error upon completion.
@@ -143,22 +145,22 @@ post.pk();
143145

144146
:::
145147

146-
### Endpoint.sideEffect
148+
#### Endpoint.sideEffect
147149

148150
[sideEffect](/rest/api/Endpoint#sideeffect) changes the behavior
149151

150-
#### true
152+
##### true
151153

152154
- Resolves _before_ [committing](https://react.dev/learn/render-and-commit#step-3-react-commits-changes-to-the-dom) Reactive Data Client cache updates.
153155
- Each call will always cause a new fetch.
154156

155-
#### undefined
157+
##### undefined
156158

157159
- Resolves _after_ [committing](https://react.dev/learn/render-and-commit#step-3-react-commits-changes-to-the-dom) Reactive Data Client cache updates.
158160
- Identical requests are deduplicated globally; allowing only one inflight request at a time.
159161
- To ensure a _new_ request is started, make sure to abort any existing inflight requests.
160162

161-
## fetchIfStale(endpoint, ...args) {#fetchIfStale}
163+
### fetchIfStale(endpoint, ...args) {#fetchIfStale}
162164

163165
Fetches only if endpoint is considered '[stale](../concepts/expiry-policy.md#stale)'.
164166

@@ -190,7 +192,7 @@ An [example](https://stackblitz.com/github/reactive/data-client/tree/master/exam
190192

191193
<StackBlitz app="github-app" file="src/routing/routes.tsx" view="editor" />
192194

193-
## expireAll(\{ testKey }) {#expireAll}
195+
### expireAll(\{ testKey }) {#expireAll}
194196

195197
Sets all responses' [expiry status](../concepts/expiry-policy.md) matching `testKey` to [Stale](../concepts/expiry-policy.md#stale).
196198

@@ -228,7 +230,7 @@ better to [include mutation sideeffects in the mutation response](/rest/guides/s
228230

229231
:::
230232

231-
## invalidate(endpoint, ...args) {#invalidate}
233+
### invalidate(endpoint, ...args) {#invalidate}
232234

233235
Forces refetching and suspense on [useSuspense](./useSuspense.md) with the same Endpoint
234236
and parameters.
@@ -268,7 +270,7 @@ controller.setResponse(MyResource.delete, { id: '5' }, { id: '5' });
268270

269271
:::
270272

271-
## invalidateAll(\{ testKey }) {#invalidateAll}
273+
### invalidateAll(\{ testKey }) {#invalidateAll}
272274

273275
[Invalidates](../concepts/expiry-policy#invalid) all [endpoint keys](/rest/api/RestEndpoint#key) matching `testKey`.
274276

@@ -333,7 +335,7 @@ ReactDOM.createRoot(document.body).render(
333335
);
334336
```
335337

336-
## resetEntireStore() {#resetEntireStore}
338+
### resetEntireStore() {#resetEntireStore}
337339

338340
Resets/clears the entire Reactive Data Client cache. All inflight requests will not resolve.
339341

@@ -361,7 +363,7 @@ function UserName() {
361363
}
362364
```
363365

364-
## set(queryable, ...args, value) {#set}
366+
### set(queryable, ...args, value) {#set}
365367

366368
Updates any [Queryable](/rest/api/schema#queryable) [Schema](/rest/api/schema#schema-overview).
367369

@@ -380,7 +382,7 @@ const id = '2';
380382
ctrl.set(Article, { id }, article => ({ id, votes: article.votes + 1 }));
381383
```
382384

383-
## setResponse(endpoint, ...args, response) {#setResponse}
385+
### setResponse(endpoint, ...args, response) {#setResponse}
384386

385387
Stores `response` in cache for given [Endpoint](/rest/api/Endpoint) and args.
386388

@@ -408,11 +410,11 @@ useEffect(() => {
408410
This shows a proof of concept in React; however a [Manager websockets implementation](../concepts/managers.md#data-stream)
409411
would be much more robust.
410412

411-
## setError(endpoint, ...args, error) {#setError}
413+
### setError(endpoint, ...args, error) {#setError}
412414

413415
Stores the result of [Endpoint](/rest/api/Endpoint) and args as the error provided.
414416

415-
## resolve(endpoint, \{ args, response, fetchedAt, error }) {#resolve}
417+
### resolve(endpoint, \{ args, response, fetchedAt, error }) {#resolve}
416418

417419
Resolves a specific fetch, storing the `response` in cache.
418420

@@ -422,7 +424,7 @@ This means the corresponding optimistic update will no longer be applies.
422424
This is used in [NetworkManager](./NetworkManager.md), and should be used when
423425
processing fetch requests.
424426

425-
## subscribe(endpoint, ...args) {#subscribe}
427+
### subscribe(endpoint, ...args) {#subscribe}
426428

427429
Marks a new subscription to a given [Endpoint](/rest/api/Endpoint). This should increment the subscription.
428430

@@ -440,18 +442,20 @@ useEffect(() => {
440442
}, [controller, key]);
441443
```
442444

443-
## unsubscribe(endpoint, ...args) {#unsubscribe}
445+
### unsubscribe(endpoint, ...args) {#unsubscribe}
444446

445447
Marks completion of subscription to a given [Endpoint](/rest/api/Endpoint). This should
446448
decrement the subscription and if the count reaches 0, more updates won't be received automatically.
447449

448450
[useSubscription](./useSubscription.md) and [useLive](./useLive.md) call this on unmount.
449451

450-
## get(schema, ...args, state) {#get}
452+
## Data Access
453+
454+
### get(schema, ...args, state) {#get}
451455

452456
Looks up any [Queryable](/rest/api/schema#queryable) [Schema](/rest/api/schema#schema-overview) in `state`.
453457

454-
### Example
458+
#### Example
455459

456460
This is used in [useQuery](./useQuery.md) and can be used in
457461
[Managers](./Manager.md) to safely access the store.
@@ -477,7 +481,7 @@ function useQuery<S extends Queryable>(
477481
}
478482
```
479483

480-
## getResponse(endpoint, ...args, state) {#getResponse}
484+
### getResponse(endpoint, ...args, state) {#getResponse}
481485

482486
```ts title="returns"
483487
{
@@ -489,11 +493,11 @@ function useQuery<S extends Queryable>(
489493

490494
Gets the (globally referentially stable) response for a given endpoint/args pair from state given.
491495

492-
### data
496+
#### data
493497

494498
The denormalize response data. Guarantees global referential stability for all members.
495499

496-
### expiryStatus
500+
#### expiryStatus
497501

498502
```ts
499503
export enum ExpiryStatus {
@@ -503,26 +507,26 @@ export enum ExpiryStatus {
503507
}
504508
```
505509

506-
#### Valid
510+
##### Valid
507511

508512
- Will never suspend.
509513
- Might fetch if data is stale
510514

511-
#### InvalidIfStale
515+
##### InvalidIfStale
512516

513517
- Will suspend if data is stale.
514518
- Might fetch if data is stale
515519

516-
#### Invalid
520+
##### Invalid
517521

518522
- Will always suspend
519523
- Will always fetch
520524

521-
### expiresAt
525+
#### expiresAt
522526

523527
A number representing time when it expires. Compare to Date.now().
524528

525-
### Example
529+
#### Example
526530

527531
This is used in [useCache](./useCache.md), [useSuspense](./useSuspense.md) and can be used in
528532
[Managers](./Manager.md) to lookup a response with the state provided.
@@ -572,15 +576,15 @@ export default class MyManager implements Manager {
572576
}
573577
```
574578

575-
## getError(endpoint, ...args, state) {#getError}
579+
### getError(endpoint, ...args, state) {#getError}
576580

577581
Gets the error, if any, for a given endpoint. Returns undefined for no errors.
578582

579-
## snapshot(state, fetchedAt) {#snapshot}
583+
### snapshot(state, fetchedAt) {#snapshot}
580584

581585
Returns a [Snapshot](./Snapshot.md).
582586

583-
## getState() {#getState}
587+
### getState() {#getState}
584588

585589
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)_.
586590

0 commit comments

Comments
 (0)