Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ interface SetResponseAction {

Sent by [Controller.setResponse()](./Controller.vue.md#setResponse), [NetworkManager](https://dataclient.io/vue/api/NetworkManager)

Read by [NetworkManager](https://dataclient.io/vue/api/NetworkManager), [LogoutManager](./LogoutManager.md)
Read by [NetworkManager](https://dataclient.io/vue/api/NetworkManager), [LogoutManager](./LogoutManager.vue.md)

## RESET

Expand Down
51 changes: 31 additions & 20 deletions .agents/skills/data-client-manager/references/Controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function PostListItem({ post }: { post: PostResource }) {
await ctrl.fetch(PostResource.delete, { id: post.id });
history.push('/');
},
[ctrl, id],
[ctrl, post.id],
);

return (
Expand All @@ -109,7 +109,7 @@ function PostListItem({ post }: { post: PostResource }) {
> When using schemas, the denormalized value is returned
>
> ```ts
> import { useController } from '@data-client/react';
> const controller = useController();
>
> const post = await controller.fetch(
> PostResource.getList.push,
Expand Down Expand Up @@ -175,7 +175,7 @@ when there are many parameterizations in cache.
import { type Controller, useController } from '@data-client/react';

const createTradeHandler = (ctrl: Controller) => async trade => {
await ctrl.fetch(TradeResource.getList.push({ user: user.id }, trade));
await ctrl.fetch(TradeResource.getList.push, { user: user.id }, trade);
ctrl.expireAll(AccountResource.get);
ctrl.expireAll(AccountResource.getList);
};
Expand All @@ -200,7 +200,7 @@ function CreateTrade({ id }: { id: string }) {

### invalidate(endpoint, ...args) {#invalidate}

Forces refetching and suspense on [useSuspense](https://dataclient.io/docs/api/useSuspense) with the same Endpoint
Forces refetching and suspenseon [useSuspense](https://dataclient.io/docs/api/useSuspense) with the same Endpoint
and parameters.

```tsx
Expand All @@ -210,8 +210,10 @@ function ArticleName({ id }: { id: string }) {

return (
<div>
<h1>{article.title}<h1>
<button onClick={() => ctrl.invalidate(ArticleResource.get, { id })}>Fetch &amp; suspend</button>
<h1>{article.title}</h1>
<button onClick={() => ctrl.invalidate(ArticleResource.get, { id })}>
Fetch &amp; suspend
</button>
</div>
);
}
Expand All @@ -229,7 +231,7 @@ function ArticleName({ id }: { id: string }) {
>
> ```ts
> // deletes MyResource(5)
> // this will resuspend MyResource.get({id: '5'})
> // this will refetch MyResource.get({id: '5'})
> // and remove it from MyResource.getList
> controller.setResponse(MyResource.delete, { id: '5' }, { id: '5' });
> ```
Expand All @@ -245,8 +247,10 @@ function ArticleName({ id }: { id: string }) {

return (
<div>
<h1>{article.title}<h1>
<button onClick={() => ctrl.invalidateAll(ArticleResource.get)}>Fetch &amp; suspend</button>
<h1>{article.title}</h1>
<button onClick={() => ctrl.invalidateAll(ArticleResource.get)}>
Fetch &amp; suspend
</button>
</div>
);
}
Expand All @@ -258,7 +262,7 @@ function ArticleName({ id }: { id: string }) {

Here we clear only GET endpoints using the test.com domain. This means other domains remain in cache.

```tsx
```ts
const myDomain = 'http://test.com';
const testKey = (key: string) => key.startsWith(`GET ${myDomain}`);

Expand All @@ -271,11 +275,16 @@ function useLogout() {
It's usually a good idea to also clear cache on 401 (unauthorized) with [LogoutManager](./LogoutManager.md)
as well.

```ts
import { DataProvider, LogoutManager, getDefaultManagers } from '@data-client/react';
```tsx
import {
DataProvider,
LogoutManager,
getDefaultManagers,
} from '@data-client/react';
import { createRoot } from 'react-dom/client';
import { unAuth } from '../authentication';

const myDomain = 'http://test.com';
const testKey = (key: string) => key.startsWith(`GET ${myDomain}`);

const managers = [
Expand Down Expand Up @@ -304,7 +313,7 @@ Resets/clears the entire Reactive Data Client cache. All inflight requests will
This is typically used when logging out or changing authenticated users.

```tsx
const USER_NUMBER_ONE: string = "1111";
const USER_NUMBER_ONE: string = '1111';

function UserName() {
const user = useSuspense(CurrentUserResource.get);
Expand All @@ -317,7 +326,7 @@ function UserName() {
}, [ctrl]);
return (
<div>
<h1>{user.name}<h1>
<h1>{user.name}</h1>
<button onClick={becomeAdmin}>Be Number One</button>
</div>
);
Expand Down Expand Up @@ -494,18 +503,19 @@ This is used in [useQuery](https://dataclient.io/docs/api/useQuery) and can be u
```tsx title="useQuery.ts"
import {
useController,
useCacheState,
StateContext,
type Queryable,
type SchemaArgs,
type DenormalizeNullable,
} from '@data-client/core';
} from '@data-client/react';
import { useContext } from 'react';

/** Oversimplified useQuery */
function useQuery<S extends Queryable>(
schema: S,
...args: SchemaArgs<S>
): DenormalizeNullable<S> | undefined {
const state = useCacheState();
const state = useContext(StateContext);
const controller = useController();

return controller.get(schema, ...args, state);
Expand Down Expand Up @@ -566,11 +576,12 @@ This is used in [useCache](https://dataclient.io/docs/api/useCache), [useSuspens
import {
useController,
StateContext,
EndpointInterface,
} from '@data-client/core';
type EndpointInterface,
} from '@data-client/react';
import { useContext } from 'react';

/** Oversimplified useCache */
function useCache<E extends EntityInterface>(
function useCache<E extends EndpointInterface>(
endpoint: E,
...args: readonly [...Parameters<E>]
) {
Expand Down
Loading
Loading