diff --git a/docs/core/shared/_VoteDemo.mdx b/docs/core/shared/_VoteDemo.mdx index 6c9db6f78c97..9448d66aafb3 100644 --- a/docs/core/shared/_VoteDemo.mdx +++ b/docs/core/shared/_VoteDemo.mdx @@ -87,18 +87,14 @@ interface Props { } ``` -```tsx title="TotalVotes" collapsed {15} +```tsx title="TotalVotes" collapsed {11} import { schema } from '@data-client/rest'; import { useQuery } from '@data-client/react'; -import { Post } from './PostResource'; +import { PostResource } from './PostResource'; const queryTotalVotes = new schema.Query( - new schema.All(Post), - (posts, { userId } = {}) => { - if (userId !== undefined) - posts = posts.filter(post => post.author.id === userId); - return posts.reduce((total, post) => total + post.votes, 0); - }, + PostResource.getList.schema, + posts => posts.reduce((total, post) => total + post.votes, 0), ); export default function TotalVotes({ userId }: Props) { diff --git a/examples/nextjs/resources/TodoResource.ts b/examples/nextjs/resources/TodoResource.ts index 225a674482fb..306ea9d029c4 100644 --- a/examples/nextjs/resources/TodoResource.ts +++ b/examples/nextjs/resources/TodoResource.ts @@ -22,5 +22,5 @@ export const TodoResource = placeholderResource({ export const queryRemainingTodos = new schema.Query( TodoResource.getList.schema, - (entries) => entries.filter((todo) => !todo.completed).length, + entries => entries.filter(todo => !todo.completed).length, ); diff --git a/examples/todo-app/typetest.ts b/examples/todo-app/typetest.ts index 91e330f916a9..6f01719be16f 100644 --- a/examples/todo-app/typetest.ts +++ b/examples/todo-app/typetest.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions */ import { useQuery, useController, useSuspense } from '@data-client/react'; import { diff --git a/packages/rest/README.md b/packages/rest/README.md index 9d9f1e21912b..754fe60d9619 100644 --- a/packages/rest/README.md +++ b/packages/rest/README.md @@ -77,10 +77,16 @@ const userOneTodos = await TodoResource.getList({ userId: 1 }); const newTodo = await TodoResource.getList.push({ title: 'my todo' }); // POST https://jsonplaceholder.typicode.com/todos?userId=1 -const newUserOneTodo = await TodoResource.getList.push({ userId: 1 }, { title: 'my todo' }); +const newUserOneTodo = await TodoResource.getList.push( + { userId: 1 }, + { title: 'my todo' }, +); // GET https://jsonplaceholder.typicode.com/todos?userId=1&page=2 -const nextPageOfTodos = await TodoResource.getList.getPage({ userId: 1, page: 2 }); +const nextPageOfTodos = await TodoResource.getList.getPage({ + userId: 1, + page: 2, +}); // PUT https://jsonplaceholder.typicode.com/todos/5 todo5 = await TodoResource.update({ id: 5 }, { title: 'my todo' }); @@ -108,10 +114,11 @@ const todoList = useSuspense(TodoResource.getList); ```typescript const ctrl = useController(); const updateTodo = data => ctrl.fetch(TodoResource.update, { id }, data); -const partialUpdateTodo= data => +const partialUpdateTodo = data => ctrl.fetch(TodoResource.partialUpdate, { id }, data); const addTodoToEnd = data => ctrl.fetch(TodoResource.getList.push, data); -const addTodoToBeginning = data => ctrl.fetch(TodoResource.getList.unshift, data); +const addTodoToBeginning = data => + ctrl.fetch(TodoResource.getList.unshift, data); const deleteTodo = data => ctrl.fetch(TodoResource.delete, { id }); ``` @@ -120,7 +127,7 @@ const deleteTodo = data => ctrl.fetch(TodoResource.delete, { id }); ```tsx const queryRemainingTodos = new schema.Query( TodoResource.getList.schema, - (entries) => entries.filter((todo) => !todo.completed).length, + entries => entries.filter(todo => !todo.completed).length, ); const allRemainingTodos = useQuery(queryRemainingTodos); @@ -145,12 +152,12 @@ supports inferring argument types from the path templates. - [Backbone Model](https://backbonejs.org/#Model) - [ImmutableJS Record](https://immutable-js.github.io/immutable-js/docs/#/Record) - ## API #### Networking definition - - [Endpoints](https://dataclient.io/rest/api/Endpoint): [RestEndpoint](https://dataclient.io/rest/api/RestEndpoint) - - [Resources](https://dataclient.io/docs/getting-started/resource): [resource()](https://dataclient.io/rest/api/resource), [hookifyResource()](https://dataclient.io/rest/api/hookifyResource) + +- [Endpoints](https://dataclient.io/rest/api/Endpoint): [RestEndpoint](https://dataclient.io/rest/api/RestEndpoint) +- [Resources](https://dataclient.io/docs/getting-started/resource): [resource()](https://dataclient.io/rest/api/resource), [hookifyResource()](https://dataclient.io/rest/api/hookifyResource)
memoized custom transforms | ✅ | -