Skip to content

Commit d361883

Browse files
committed
docs: Update invalidation examples with ctrl.set()
1 parent 6ccb310 commit d361883

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

docs/core/api/Controller.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ Updates any [Queryable](/rest/api/schema#queryable) [Schema](/rest/api/schema#sc
370370
```ts
371371
ctrl.set(
372372
Todo,
373+
// which Todo to update
373374
{ id: '5' },
375+
// merge this data into the Todo in the store
374376
{ id: '5', title: 'tell me friends how great Data Client is' },
375377
);
376378
```

docs/core/concepts/expiry-policy.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,11 @@ import { useLoading } from '@data-client/react';
615615
import { TimedEntity } from './api/lastUpdated';
616616
import TimePage from './TimePage';
617617

618+
const InvalidateTimedEntity = new schema.Invalidate(TimedEntity);
618619
export const deleteLastUpdated = new RestEndpoint({
619620
path: '/api/currentTime/:id',
620621
method: 'DELETE',
621-
schema: new schema.Invalidate(TimedEntity),
622+
schema: InvalidateTimedEntity,
622623
});
623624

624625
function ShowTime() {
@@ -649,6 +650,17 @@ function ShowTime() {
649650
>
650651
Invalidate (without fetching DELETE)
651652
</button>
653+
<button
654+
onClick={() =>
655+
ctrl.set(
656+
InvalidateTimedEntity,
657+
{ id: '1' },
658+
{ id: '1' },
659+
)
660+
}
661+
>
662+
Invalidate Entity with ctrl.set
663+
</button>
652664
</div>
653665
);
654666
}
@@ -658,8 +670,8 @@ render(<ShowTime />);
658670
</HooksPlayground>
659671

660672
[Controller.fetch()](../api/Controller.md#fetch) lets us update the server and store.
661-
We can use [Controller.setResponse()](../api/Controller.md#setResponse) for cases where we
662-
simply want to change the local store without updating the server.
673+
We can use [Controller.setResponse()](../api/Controller.md#setResponse) or [Controller.set()](../api/Controller.md#set)
674+
when we want to change the local store directly.
663675

664676
#### Conditional Invalidation based on data
665677

0 commit comments

Comments
 (0)