Skip to content

Commit

Permalink
docs: Improve endpoint header organization
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Sep 29, 2024
1 parent 3bbe2fd commit e24532f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
17 changes: 10 additions & 7 deletions docs/core/guides/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import StackBlitz from '@site/src/components/StackBlitz';

Server Side Rendering (SSR) can improve the first-load performance of your application. Reactive Data
Client takes this one step further by pre-populating the data store. Unlike other SSR methodologies,
Reactive Data Client becomes interactive the moment the page is visible, making [data mutations](https://dataclient.io/docs/getting-started/mutations) instantaneous. Additionally there is no need for additional data fetches that increase server
Reactive Data Client becomes interactive the moment the page is visible, making [data mutations](../getting-started/mutations.md) instantaneous. Additionally there is no need for additional data fetches that increase server
load and slow client hydration, potentially causing application stutters.

## NextJS SSR {#nextjs}
Expand Down Expand Up @@ -54,27 +54,30 @@ export default function RootLayout({ children }) {

To keep your data fresh and performant, you can use client components and [useSuspense()](../api/useSuspense.md)

```tsx title="app/todos/page.tsx"
```tsx title="app/todos/[userId]/page.tsx"
'use client';
import { useSuspense } from '@data-client/react';
import { TodoResource } from '../../resources/Todo';

export default function InteractivePage() {
const todos = useSuspense(TodoResource.getList);
export default function InteractivePage({ params }: { params: { userId: number } }) {
const todos = useSuspense(TodoResource.getList, params);
return <TodoList todos={todos} />;
}
```

Note that this is identical to how you would write components without SSR. This makes
makes the components usable across platforms.

#### Server Components

However, if your data never changes, you can slightly decrease the javascript bundle sent, by
using a server component. Simply `await` the endpoint:

```tsx title="app/todos/page.tsx"
```tsx title="app/todos/[userId]/page.tsx"
import { TodoResource } from '../../resources/Todo';

export default async function StaticPage() {
const todos = await TodoResource.getList();
export default async function StaticPage({ params }: { params: { userId: number } }) {
const todos = await TodoResource.getList(params);
return <TodoList todos={todos} />;
}
```
Expand Down
12 changes: 5 additions & 7 deletions docs/rest/api/Endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ you intend on using that method.

:::

## testKey(key): boolean {#testKey}
### testKey(key): boolean {#testKey}

Returns `true` if the provided (fetch) [key](#key) matches this endpoint.

This is used for mock interceptors with with [&lt;MockResolver /&gt;](/docs/api/MockResolver)

## name: string {#name}
### name: string {#name}

Used in [key](#key) to distinguish endpoints. Should be globally unique.

Expand All @@ -213,13 +213,13 @@ In these cases you can override `name` or disable function mangling.

:::

## sideEffect: boolean {#sideeffect}
### sideEffect: boolean {#sideeffect}

Used to indicate endpoint might have side-effects (non-idempotent). This restricts it
from being used with [useSuspense()](/docs/api/useSuspense) or [useFetch()](/docs/api/useFetch) as those can hit the
endpoint an unpredictable number of times.

## schema: Schema {#schema}
### schema: Schema {#schema}

Declarative definition of how to [process responses](./schema)

Expand All @@ -243,13 +243,11 @@ const getUser = new Endpoint(
);
```

## EndpointExtraOptions

import EndpointLifecycle from './_EndpointLifecycle.mdx';

<EndpointLifecycle />

## extend(EndpointOptions): Endpoint {#extend}
### extend(options): Endpoint {#extend}

Can be used to further customize the endpoint definition

Expand Down
28 changes: 13 additions & 15 deletions docs/rest/api/RestEndpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,9 @@ async (id: string) => {

:::

## schema?: Schema {#schema}
## Endpoint Lifecycle

### schema?: Schema {#schema}

[Declarative data lifecycle](./schema.md)

Expand All @@ -789,15 +791,7 @@ const getUser = new RestEndpoint({
});
```

## Endpoint Life-Cycles

These are inherited from [Endpoint](./Endpoint.md#lifecycle)

import EndpointLifecycle from './_EndpointLifecycle.mdx';

<EndpointLifecycle />

## key(urlParams): string {#key}
### key(urlParams): string {#key}

Serializes the parameters. This is used to build a lookup key in global stores.

Expand All @@ -807,14 +801,18 @@ Default:
`${this.method} ${this.url(urlParams)}`;
```

## testKey(key): boolean {#testKey}
### testKey(key): boolean {#testKey}

Returns `true` if the provided (fetch) [key](#key) matches this endpoint.

This is used for mock interceptors with with [&lt;MockResolver /&gt;](/docs/api/MockResolver),
[Controller.expireAll()](/docs/api/Controller#expireAll), and [Controller.invalidateAll()](/docs/api/Controller#invalidateAll).

## extend(options): Endpoint {#extend}
import EndpointLifecycle from './_EndpointLifecycle.mdx';

<EndpointLifecycle />

## extend(options): RestEndpoint {#extend}

Can be used to further customize the endpoint definition

Expand Down Expand Up @@ -881,7 +879,7 @@ return (

See [pagination guide](guides/pagination.md) for more info.

### paginated(paginationfield): Endpoint {#paginated}
### paginated(paginationfield) {#paginated}

Creates a new endpoint with an extra `paginationfield` string that will be used to find the specific
page, to append to this endpoint. See [Infinite Scrolling Pagination](guides/pagination.md#infinite-scrolling) for more info.
Expand All @@ -892,7 +890,7 @@ const getNextPage = getList.paginated('cursor');

Schema must also contain a [Collection](./Collection.md)

### paginated(removeCursor): Endpoint {#paginated-function}
### paginated(removeCursor) {#paginated-function}

```typescript
function paginated<E, A extends any[]>(
Expand Down Expand Up @@ -920,7 +918,7 @@ Schema must also contain a [Collection](./Collection.md)
Make sure you use `RestGenerics` to keep types working.

```ts
import { RestEndpoint, RestGenerics } from '@data-client/rest';
import { RestEndpoint, type RestGenerics } from '@data-client/rest';

class GithubEndpoint<
O extends RestGenerics = any,
Expand Down
4 changes: 2 additions & 2 deletions docs/rest/api/_EndpointLifecycle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ that useSuspense() will suspend when data is stale even if it already exists in
Frequency in millisecond to poll at. Requires using [useSubscription()](/docs/api/useSubscription) or
[useLive()](/docs/api/useLive) to have an effect.

### getOptimisticResponse: (snap, ...args) => fakePayload {#getoptimisticresponse}
### getOptimisticResponse: (snap, ...args) => expectedResponse {#getoptimisticresponse}

When provided, any fetches with this endpoint will behave as though the `fakePayload` return value
When provided, any fetches with this endpoint will behave as though the `expectedResponse` return value
from this function was a succesful network response. When the actual fetch completes (regardless
of failure or success), the optimistic update will be replaced with the actual network response.

Expand Down

0 comments on commit e24532f

Please sign in to comment.