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 @@ -475,9 +475,12 @@ const createUser = new RestEndpoint({

More updates:

```typescript title="Component.tsx"
const allusers = useSuspense(userList);
const adminUsers = useSuspense(userList, { admin: true });
```typescript title="Component.vue"
// start both fetches in parallel
useFetch(userList);
useFetch(userList, { admin: true });
const allusers = await useSuspense(userList);
const adminUsers = await useSuspense(userList, { admin: true });
```

The endpoint below ensures the new user shows up immediately in the usages above.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1353,12 +1353,13 @@ const getTodos = new RestEndpoint({
});

const todos = useSuspense(getTodos);
const ctrl = useController();
return (
<PaginatedList
items={todos}
fetchNextPage={() =>
// fetches url `/todos?page=${nextPage}`
ctrl.fetch(TodoResource.getList.getPage, { page: nextPage })
ctrl.fetch(getTodos.getPage, { page: nextPage })
}
/>
);
Expand Down
146 changes: 83 additions & 63 deletions .agents/skills/data-client-rest-setup/references/RestEndpoint.vue.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const getComments = new RestEndpoint({
});

// Hover your mouse over 'comments' to see its type
const comments = useSuspense(getComments, {
const comments = await useSuspense(getComments, {
postId: '5',
sortBy: 'votes',
});
Expand All @@ -164,7 +164,7 @@ const createComment = async data =>

#### Resolution/Return

[schema](#schema) determines the return value when used with data-binding hooks like [useSuspense](https://dataclient.io/vue/api/useSuspense), [useDLE](https://dataclient.io/vue/api/useDLE), [useCache](https://dataclient.io/vue/api/useCache)
[schema](#schema) determines the return value when used with data-binding composables like [useSuspense](https://dataclient.io/vue/api/useSuspense), [useDLE](https://dataclient.io/vue/api/useDLE), [useCache](https://dataclient.io/vue/api/useCache)
or when used with [Controller.fetch](https://dataclient.io/vue/api/Controller#fetch)

```ts title="Todo.ts"
Expand All @@ -182,7 +182,7 @@ import { Todo } from './Todo';

const getTodo = new RestEndpoint({ path: '/', schema: Todo });
// Hover your mouse over 'todo' to see its type
const todo = useSuspense(getTodo);
const todo = await useSuspense(getTodo);

async () => {
const ctrl = useController();
Expand All @@ -191,7 +191,7 @@ async () => {
```

[process](#process) determines the resolution value when the endpoint is called directly. For
`RestEndpoints` without a schema, it also determines the return type of [hooks](https://dataclient.io/vue/api/useSuspense) and [Controller.fetch](https://dataclient.io/vue/api/Controller#fetch).
`RestEndpoints` without a schema, it also determines the return type of [composables](https://dataclient.io/vue/api/useSuspense) and [Controller.fetch](https://dataclient.io/vue/api/Controller#fetch).

```ts path="process.ts"
interface TodoInterface {
Expand Down Expand Up @@ -670,11 +670,11 @@ This is sent to [fetchResponse](#fetchResponse)

Called by [getRequestInit](#getRequestInit) to determine [HTTP Headers](https://developer.mozilla.org/en-US/docs/Web/API/Request/headers)

This is often useful for [authentication](./auth.md)
This is often useful for [authentication](./auth.vue.md)

> **Warning**
>
> Don't use hooks here. If you need to use hooks, try using [hookifyResource](./hookifyResource.md)
> Don't use composables here. If you need to use composables, try using [hookifyResource](./hookifyResource.vue.md)

> **Tip: async**
>
Expand Down Expand Up @@ -1052,9 +1052,12 @@ const createUser = new RestEndpoint({

More updates:

```typescript title="Component.tsx"
const allusers = useSuspense(userList);
const adminUsers = useSuspense(userList, { admin: true });
```typescript title="Component.vue"
// start both fetches in parallel
useFetch(userList);
useFetch(userList, { admin: true });
const allusers = await useSuspense(userList);
const adminUsers = await useSuspense(userList, { admin: true });
```

The endpoint below ensures the new user shows up immediately in the usages above.
Expand Down Expand Up @@ -1271,50 +1274,64 @@ export const TaskResource = resource({
});
```

```tsx title="TaskCard" {5-9}
import { useController } from '@data-client/react';
import { TaskResource, type Task } from './TaskResource';
```html title="TaskCard.vue" {7-16}
<script setup lang="ts">
import { useController } from '@data-client/vue';
import { TaskResource, type Task } from './TaskResource';

export default function TaskCard({ task }: { task: Task }) {
const handleMove = () => ctrl.fetch(
TaskResource.getList.move,
{ id: task.id },
{ id: task.id, status: task.status === 'backlog' ? 'in-progress' : 'backlog' },
);
const props = defineProps<{ task: Task }>();
const ctrl = useController();
return (
<div className="listItem">
<span style={{ flex: 1 }}>{task.title}</span>
<button onClick={handleMove}>
{task.status === 'backlog' ? '\u25bc' : '\u25b2'}
</button>
</div>
);
}
const handleMove = () =>
ctrl.fetch(
TaskResource.getList.move,
{ id: props.task.id },
{
id: props.task.id,
status:
props.task.status === 'backlog' ? 'in-progress' : 'backlog',
},
);
</script>

<template>
<div class="listItem">
<span style="flex: 1">{{ task.title }}</span>
<button @click="handleMove">
{{ task.status === 'backlog' ? '\u25bc' : '\u25b2' }}
</button>
</div>
</template>
```

```tsx title="TaskBoard"
import { useSuspense } from '@data-client/react';
import { TaskResource } from './TaskResource';
import TaskCard from './TaskCard';
```html title="TaskBoard.vue"
<script setup lang="ts">
import { useFetch, useSuspense } from '@data-client/vue';
import { TaskResource } from './TaskResource';
import TaskCard from './TaskCard.vue';

// start both fetches in parallel before awaiting
useFetch(TaskResource.getList, { status: 'backlog' });
useFetch(TaskResource.getList, { status: 'in-progress' });
const backlog = await useSuspense(TaskResource.getList, {
status: 'backlog',
});
const inProgress = await useSuspense(TaskResource.getList, {
status: 'in-progress',
});
</script>

function TaskBoard() {
const backlog = useSuspense(TaskResource.getList, { status: 'backlog' });
const inProgress = useSuspense(TaskResource.getList, { status: 'in-progress' });
return (
<div>
<div className="boardColumn">
<h4>Backlog</h4>
{backlog.map(task => <TaskCard key={task.pk()} task={task} />)}
</div>
<div className="boardColumn">
<h4>Active</h4>
{inProgress.map(task => <TaskCard key={task.pk()} task={task} />)}
</div>
<template>
<div>
<div class="boardColumn">
<h4>Backlog</h4>
<TaskCard v-for="task in backlog" :key="task.pk()" :task="task" />
</div>
);
}
render(<TaskBoard />);
<div class="boardColumn">
<h4>Active</h4>
<TaskCard v-for="task in inProgress" :key="task.pk()" :task="task" />
</div>
</div>
</template>
```

The remove filter is based on the entity's **existing** values in the store.
Expand All @@ -1340,23 +1357,26 @@ await ctrl.fetch(
An endpoint to retrieve the next page using [paginationField](#paginationfield) as the searchParameter key. Schema
must also contain a [Collection](https://dataclient.io/rest/api/Collection)

```tsx
const getTodos = new RestEndpoint({
path: '/todos',
schema: Todo,
paginationField: 'page',
});
```html
<script lang="ts">
const getTodos = new RestEndpoint({
path: '/todos',
schema: Todo,
paginationField: 'page',
});
</script>

const todos = useSuspense(getTodos);
return (
<PaginatedList
items={todos}
fetchNextPage={() =>
// fetches url `/todos?page=${nextPage}`
ctrl.fetch(TodoResource.getList.getPage, { page: nextPage })
}
/>
);
<script setup lang="ts">
const todos = await useSuspense(getTodos);
const ctrl = useController();
// fetches url `/todos?page=${nextPage}`
const fetchNextPage = () =>
ctrl.fetch(getTodos.getPage, { page: nextPage });
</script>

<template>
<PaginatedList :items="todos" :fetchNextPage="fetchNextPage" />
</template>
```

See [pagination guide](https://dataclient.io/rest/guides/pagination) for more info.
Expand Down
2 changes: 1 addition & 1 deletion .agents/skills/data-client-rest-setup/references/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ import { MyResource } from './MyResource';
MyResource.get({ id: 1 });
```

## Auth Headers from React Context
## Auth Headers from React Context {#auth-headers-from-react-context}

> **Warning**
>
Expand Down
Loading
Loading