Skip to content

Commit 20eb933

Browse files
committed
docs: Use Collection schema for Query example
1 parent 49ac1c4 commit 20eb933

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

docs/core/shared/_VoteDemo.mdx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,14 @@ interface Props {
8787
}
8888
```
8989

90-
```tsx title="TotalVotes" collapsed {15}
90+
```tsx title="TotalVotes" collapsed {11}
9191
import { schema } from '@data-client/rest';
9292
import { useQuery } from '@data-client/react';
93-
import { Post } from './PostResource';
93+
import { PostResource } from './PostResource';
9494

9595
const queryTotalVotes = new schema.Query(
96-
new schema.All(Post),
97-
(posts, { userId } = {}) => {
98-
if (userId !== undefined)
99-
posts = posts.filter(post => post.author.id === userId);
100-
return posts.reduce((total, post) => total + post.votes, 0);
101-
},
96+
PostResource.getList.schema,
97+
posts => posts.reduce((total, post) => total + post.votes, 0),
10298
);
10399

104100
export default function TotalVotes({ userId }: Props) {

examples/nextjs/resources/TodoResource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ export const TodoResource = placeholderResource({
2222

2323
export const queryRemainingTodos = new schema.Query(
2424
TodoResource.getList.schema,
25-
(entries) => entries.filter((todo) => !todo.completed).length,
25+
entries => entries.filter(todo => !todo.completed).length,
2626
);

examples/todo-app/typetest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unused-expressions */
12
import { useQuery, useController, useSuspense } from '@data-client/react';
23

34
import {

packages/rest/README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,16 @@ const userOneTodos = await TodoResource.getList({ userId: 1 });
7777
const newTodo = await TodoResource.getList.push({ title: 'my todo' });
7878

7979
// POST https://jsonplaceholder.typicode.com/todos?userId=1
80-
const newUserOneTodo = await TodoResource.getList.push({ userId: 1 }, { title: 'my todo' });
80+
const newUserOneTodo = await TodoResource.getList.push(
81+
{ userId: 1 },
82+
{ title: 'my todo' },
83+
);
8184

8285
// GET https://jsonplaceholder.typicode.com/todos?userId=1&page=2
83-
const nextPageOfTodos = await TodoResource.getList.getPage({ userId: 1, page: 2 });
86+
const nextPageOfTodos = await TodoResource.getList.getPage({
87+
userId: 1,
88+
page: 2,
89+
});
8490

8591
// PUT https://jsonplaceholder.typicode.com/todos/5
8692
todo5 = await TodoResource.update({ id: 5 }, { title: 'my todo' });
@@ -108,10 +114,11 @@ const todoList = useSuspense(TodoResource.getList);
108114
```typescript
109115
const ctrl = useController();
110116
const updateTodo = data => ctrl.fetch(TodoResource.update, { id }, data);
111-
const partialUpdateTodo= data =>
117+
const partialUpdateTodo = data =>
112118
ctrl.fetch(TodoResource.partialUpdate, { id }, data);
113119
const addTodoToEnd = data => ctrl.fetch(TodoResource.getList.push, data);
114-
const addTodoToBeginning = data => ctrl.fetch(TodoResource.getList.unshift, data);
120+
const addTodoToBeginning = data =>
121+
ctrl.fetch(TodoResource.getList.unshift, data);
115122
const deleteTodo = data => ctrl.fetch(TodoResource.delete, { id });
116123
```
117124

@@ -120,7 +127,7 @@ const deleteTodo = data => ctrl.fetch(TodoResource.delete, { id });
120127
```tsx
121128
const queryRemainingTodos = new schema.Query(
122129
TodoResource.getList.schema,
123-
(entries) => entries.filter((todo) => !todo.completed).length,
130+
entries => entries.filter(todo => !todo.completed).length,
124131
);
125132

126133
const allRemainingTodos = useQuery(queryRemainingTodos);
@@ -145,12 +152,12 @@ supports inferring argument types from the path templates.
145152
- [Backbone Model](https://backbonejs.org/#Model)
146153
- [ImmutableJS Record](https://immutable-js.github.io/immutable-js/docs/#/Record)
147154

148-
149155
## API
150156

151157
#### Networking definition
152-
- [Endpoints](https://dataclient.io/rest/api/Endpoint): [RestEndpoint](https://dataclient.io/rest/api/RestEndpoint)
153-
- [Resources](https://dataclient.io/docs/getting-started/resource): [resource()](https://dataclient.io/rest/api/resource), [hookifyResource()](https://dataclient.io/rest/api/hookifyResource)
158+
159+
- [Endpoints](https://dataclient.io/rest/api/Endpoint): [RestEndpoint](https://dataclient.io/rest/api/RestEndpoint)
160+
- [Resources](https://dataclient.io/docs/getting-started/resource): [resource()](https://dataclient.io/rest/api/resource), [hookifyResource()](https://dataclient.io/rest/api/hookifyResource)
154161

155162
<table>
156163
<caption>
@@ -229,4 +236,4 @@ supports inferring argument types from the path templates.
229236
<td>memoized custom transforms</td>
230237
<td align="center">✅</td>
231238
</tr>
232-
</tbody></table>
239+
</tbody></table>

0 commit comments

Comments
 (0)