Skip to content

Commit

Permalink
docs: Lots of fixes (#2295)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Nov 29, 2022
1 parent e510c40 commit 2d151e8
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 62 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Coverage Status](https://img.shields.io/codecov/c/gh/coinbase/rest-hooks/master.svg?style=flat-square)](https://app.codecov.io/gh/coinbase/rest-hooks?branch=master)
[![npm downloads](https://img.shields.io/npm/dt/rest-hooks.svg?style=flat-square)](https://www.npmjs.com/package/rest-hooks)
[![bundle size](https://img.shields.io/bundlephobia/minzip/@rest-hooks/react?style=flat-square)](https://bundlephobia.com/result?p=@rest-hooks/react)
[![npm version](https://img.shields.io/npm/v/rest-hooks.svg?style=flat-square)](https://www.npmjs.com/package/rest-hooks)
[![npm version](https://img.shields.io/npm/v/@rest-hooks/react.svg?style=flat-square)](https://www.npmjs.com/package/@rest-hooks/react)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![Chat](https://img.shields.io/discord/768254430381735967.svg?style=flat-square&colorB=758ED3)](https://discord.gg/35nb8Mz)

Expand Down Expand Up @@ -73,11 +73,10 @@ return (
);
```

### And [subscriptions](https://resthooks.io/docs/api/useSubscription)
### And [subscriptions](https://resthooks.io/docs/api/useLive)

```tsx
const price = useSuspense(PriceResource.get, { symbol });
useSubscription(PriceResource.get, { symbol });
const price = useLive(PriceResource.get, { symbol });
return price.value;
```

Expand Down Expand Up @@ -105,9 +104,10 @@ For the small price of 9kb gziped.    [🏁Get started now](https://re

## Features

- [x] ![TS](./packages/rest-hooks/typescript.svg?sanitize=true) Strong [Typescript](https://www.typescriptlang.org/) types
- [x] ![TS](./packages/rest-hooks/typescript.svg?sanitize=true) Strong [Typescript](https://www.typescriptlang.org/) inference
- [x] 🛌 React [Suspense](https://resthooks.io/docs/getting-started/data-dependency#boundaries) support
- [x] 🧵 React 18 [Concurrent mode](https://resthooks.io/docs/guides/render-as-you-fetch) compatible
- [x] 💦 [Partial Hydration Server Side Rendering](https://resthooks.io/docs/guides/ssr)
- [x] 🎣 [Declarative API](https://resthooks.io/docs/getting-started/data-dependency)
- [x] 📝 Composition over configuration
- [x] 💰 [Normalized](https://resthooks.io/docs/getting-started/entity) caching
Expand All @@ -121,7 +121,12 @@ For the small price of 9kb gziped.    [🏁Get started now](https://re
- [x] ♻️ Optional [redux integration](https://resthooks.io/docs/guides/redux)
- [x] 📙 [Storybook mocking](https://resthooks.io/docs/guides/storybook)
- [x] 📱 [React Native](https://facebook.github.io/react-native/) support
- [x] ⚛️ [NextJS](https://resthooks.io/docs/guides/ssr#nextjs) support
- [x] 🚯 [Declarative cache lifetime policy](https://resthooks.io/docs/getting-started/expiry-policy)
- [x] 🧅 [Composable middlewares](https://resthooks.io/docs/api/Manager)
- [x] 💽 Global data consistency guarantees
- [x] 🏇 Automatic race condition elimination
- [x] 👯 Global referential equality guarantees

## Principals of Rest Hooks

Expand Down
12 changes: 12 additions & 0 deletions docs/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,3 +594,15 @@ const todoDetail404Fixture: FixtureEndpoint = {
[Open demo in own tab](https://stackblitz.com/github/coinbase/rest-hooks/tree/master/examples/github-app?file=src%2Fpages%2FIssueList.tsx)

[Explore on github](https://github.com/coinbase/rest-hooks/tree/master/examples/github-app)

### NextJS Demo {#nextjs-demo}

<iframe
src="https://stackblitz.com/github/coinbase/rest-hooks/tree/master/examples/nextjs?embed=1&file=src%2Fpages%2FHome%2FTodoListComponent.tsx&hidedevtools=1&view=both&ctl=1"
width="100%"
height="500"
></iframe>
[Open demo in own tab](https://stackblitz.com/github/coinbase/rest-hooks/tree/master/examples/nextjs?file=pages%2FAssetPrice.tsx)

[Explore on github](https://github.com/coinbase/rest-hooks/tree/master/examples/nextjs)
4 changes: 4 additions & 0 deletions docs/core/api/LogoutManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ sidebar_label: LogoutManager
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<head>
<title>LogoutManager - Handling 401s and other deauthorization triggers</title>
</head>

Logs out when receiving a [401 (Unauthorized)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401) response.

## Usage
Expand Down
1 change: 1 addition & 0 deletions docs/core/api/Manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ relies on state actually existing.
- [NetworkManager](./NetworkManager.md)
- [SubscriptionManager](./SubscriptionManager.md)
- [DevToolsManager](./DevToolsManager.md)
- [LogoutManager](./LogoutManager.md)

## Adding managers to Rest Hooks

Expand Down
5 changes: 5 additions & 0 deletions docs/core/api/NetworkManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ title: NetworkManager
sidebar_label: NetworkManager
---

<head>
<title>NetworkManager - Orchestrating efficient race-condition free fetching</title>
</head>


NetworkManager orchestrates asynchronous fetches. By keeping track of all in-flight requests
it is able to dedupe identical requests if they are made using the throttle flag.

Expand Down
5 changes: 5 additions & 0 deletions docs/core/guides/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ title: Server Side Rendering
import PkgInstall from '@site/src/components/PkgInstall';
import PkgTabs from '@site/src/components/PkgTabs';

<head>
<title>Server Side Rendering Integrations - NextJS, Express</title>
<meta name="docsearch:pagerank" content="10"/>
</head>


## NextJS

Expand Down
10 changes: 8 additions & 2 deletions docs/core/upgrade/upgrading-to-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Many 'advanced' features of rest-hooks are not longer exported by 'rest-hooks' p

### Managers

These only apply if you have a custom [Manager](../api/Manager)
These only apply if you have a custom [Manager](/docs/5.0/api/Manager)

<details><summary>action.meta.url -> action.meta.key</summary>

Expand All @@ -196,7 +196,7 @@ in. (To prevent unwanted side effects.)

<details><summary>useInvalidator() triggers suspense</summary>

You can likely remove [invalidIfStale](/rest/api/Endpoint#invalidifstale-boolean) if used in conjunction with [useInvalidator()](../api/useInvalidator)
You can likely remove [invalidIfStale](/rest/api/Endpoint#invalidifstale-boolean) if used in conjunction with [useInvalidator()](/docs/5.0/api/useInvalidator)

[invalidIfStale](/rest/api/Endpoint#invalidifstale-boolean) is still useful to disable the `stale-while-revalidate` policy.

Expand Down Expand Up @@ -550,3 +550,9 @@ Eventually support for FetchShape will be deprecated, and then removed.
</details>

[Full Release notes](https://github.com/coinbase/rest-hooks/releases/tag/rest-hooks%405.0.0)

## Support

If you have any trouble upgrading, you can get some help from the community discord [![Chat](https://img.shields.io/discord/768254430381735967.svg?style=flat-square&colorB=758ED3)](https://discord.gg/35nb8Mz)

If you find any bugs or other issues, feel free to open a [github ticket](https://github.com/coinbase/rest-hooks/issues/new/choose)
14 changes: 10 additions & 4 deletions docs/core/upgrade/upgrading-to-6.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ These are still supported! They are simply moved to [@rest-hooks/legacy](https:/

has all of these, and is compatible with both `rest-hooks` 5 and 6.
2. Upgrade `rest-hooks` to 6 & `@rest-hooks/legacy` to 3.
3. [Gradually migrate](https://resthooks.io/docs/upgrade/upgrading-to-5#rest-hooksrest) to [@rest-hooks/rest](https://www.npmjs.com/package/@rest-hooks/rest)
3. [Gradually migrate](/docs/upgrade/upgrading-to-5#rest-hooksrest) to [@rest-hooks/rest](https://www.npmjs.com/package/@rest-hooks/rest)

### Importing directly from hidden files is no longer supported

Expand All @@ -59,7 +59,7 @@ with tooling that supports package exports, it will not work at all.

Entities no longer normalize to their class. Class construction is now done during denormalization step.
This means the internal state of Rest Hooks is a [POJO](https://en.wikipedia.org/wiki/Plain_old_Java_object). This
improves serialization. However, it does mean relying on the internal state in a [Manager](https://resthooks.io/docs/api/Manager)
improves serialization. However, it does mean relying on the internal state in a [Manager](/docs/6.6/api/Manager)
to be a class will break. Additionally the expected serialization of Rest Hooks store will be slightly different, which
could affect snapshot tests or persistance efforts like using IndexedDB.

Expand All @@ -69,7 +69,7 @@ could affect snapshot tests or persistance efforts like using IndexedDB.

SimpleRecord was removed (though available in [@rest-hooks/legacy](https://www.npmjs.com/package/@rest-hooks/legacy))

[Object](https://resthooks.io/docs/api/Object) can be used instead
[Object](/rest/api/Object) can be used instead

<BeforeAfterTabs>

Expand Down Expand Up @@ -105,7 +105,7 @@ export const Address = {

### @rest-hooks/rest changes from 2 -> 3

These add on to the [existing changes](https://resthooks.io/docs/upgrade/upgrading-to-5#rest-hooksrest) of @rest-hooks/rest from @rest-hooks/legacy
These add on to the [existing changes](/docs/upgrade/upgrading-to-5#rest-hooksrest) of @rest-hooks/rest from @rest-hooks/legacy

- If `Resource.fromJS()` was used to customize normalization process, use `process()` instead.

Expand Down Expand Up @@ -232,3 +232,9 @@ Removed exports from 'rest-hooks': NestedEntity, schemas, isEntity, Entity, Reso
- peerDep @rest-hooks/endpoint > 2

[Full Release notes](https://github.com/coinbase/rest-hooks/releases/tag/rest-hooks%406.0.0)

## Support

If you have any trouble upgrading, you can get some help from the community discord [![Chat](https://img.shields.io/discord/768254430381735967.svg?style=flat-square&colorB=758ED3)](https://discord.gg/35nb8Mz)

If you find any bugs or other issues, feel free to open a [github ticket](https://github.com/coinbase/rest-hooks/issues/new/choose)
6 changes: 6 additions & 0 deletions docs/core/upgrade/upgrading-to-7.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,9 @@ This will become the recommended way to consume rest hooks when using React. The
still work but eventually remove any additions.

- `import {} from 'rest-hooks'` -> `import {} from '@rest-hooks/react'`

## Support

If you have any trouble upgrading, you can get some help from the community discord [![Chat](https://img.shields.io/discord/768254430381735967.svg?style=flat-square&colorB=758ED3)](https://discord.gg/35nb8Mz)

If you find any bugs or other issues, feel free to open a [github ticket](https://github.com/coinbase/rest-hooks/issues/new/choose)
13 changes: 9 additions & 4 deletions packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ return (
);
```

### And [subscriptions](https://resthooks.io/docs/api/useSubscription)
### And [subscriptions](https://resthooks.io/docs/api/useLive)

```tsx
const price = useSuspense(PriceResource.get, { symbol });
useSubscription(PriceResource.get, { symbol });
const price = useLive(PriceResource.get, { symbol });
return price.value;
```

Expand All @@ -95,9 +94,10 @@ For the small price of 9kb gziped. &nbsp;&nbsp; [🏁Get started now](https://re

## Features

- [x] ![TS](./packages/rest-hooks/typescript.svg?sanitize=true) Strong [Typescript](https://www.typescriptlang.org/) types
- [x] ![TS](./packages/rest-hooks/typescript.svg?sanitize=true) Strong [Typescript](https://www.typescriptlang.org/) inference
- [x] 🛌 React [Suspense](https://resthooks.io/docs/getting-started/data-dependency#boundaries) support
- [x] 🧵 React 18 [Concurrent mode](https://resthooks.io/docs/guides/render-as-you-fetch) compatible
- [x] 💦 [Partial Hydration Server Side Rendering](https://resthooks.io/docs/guides/ssr)
- [x] 🎣 [Declarative API](https://resthooks.io/docs/getting-started/data-dependency)
- [x] 📝 Composition over configuration
- [x] 💰 [Normalized](https://resthooks.io/docs/getting-started/entity) caching
Expand All @@ -111,7 +111,12 @@ For the small price of 9kb gziped. &nbsp;&nbsp; [🏁Get started now](https://re
- [x] ♻️ Optional [redux integration](https://resthooks.io/docs/guides/redux)
- [x] 📙 [Storybook mocking](https://resthooks.io/docs/guides/storybook)
- [x] 📱 [React Native](https://facebook.github.io/react-native/) support
- [x] ⚛️ [NextJS](https://resthooks.io/docs/guides/ssr#nextjs) support
- [x] 🚯 [Declarative cache lifetime policy](https://resthooks.io/docs/getting-started/expiry-policy)
- [x] 🧅 [Composable middlewares](https://resthooks.io/docs/api/Manager)
- [x] 💽 Global data consistency guarantees
- [x] 🏇 Automatic race condition elimination
- [x] 👯 Global referential equality guarantees

## Principals of Rest Hooks

Expand Down
8 changes: 7 additions & 1 deletion packages/rest-hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ For the small price of 8kb gziped. &nbsp;&nbsp; [🏁Get started now](https://re

## Features

- [x] ![TS](./packages/rest-hooks/typescript.svg?sanitize=true) Strong [Typescript](https://www.typescriptlang.org/) types
- [x] ![TS](./packages/rest-hooks/typescript.svg?sanitize=true) Strong [Typescript](https://www.typescriptlang.org/) inference
- [x] 🛌 React [Suspense](https://resthooks.io/docs/getting-started/data-dependency#boundaries) support
- [x] 🧵 React 18 [Concurrent mode](https://resthooks.io/docs/guides/render-as-you-fetch) compatible
- [x] 💦 [Partial Hydration Server Side Rendering](https://resthooks.io/docs/guides/ssr)
- [x] 🎣 [Declarative API](https://resthooks.io/docs/getting-started/data-dependency)
- [x] 📝 Composition over configuration
- [x] 💰 [Normalized](https://resthooks.io/docs/getting-started/entity) caching
Expand All @@ -111,7 +112,12 @@ For the small price of 8kb gziped. &nbsp;&nbsp; [🏁Get started now](https://re
- [x] ♻️ Optional [redux integration](https://resthooks.io/docs/guides/redux)
- [x] 📙 [Storybook mocking](https://resthooks.io/docs/guides/storybook)
- [x] 📱 [React Native](https://facebook.github.io/react-native/) support
- [x] ⚛️ [NextJS](https://resthooks.io/docs/guides/ssr#nextjs) support
- [x] 🚯 [Declarative cache lifetime policy](https://resthooks.io/docs/getting-started/expiry-policy)
- [x] 🧅 [Composable middlewares](https://resthooks.io/docs/api/Manager)
- [x] 💽 Global data consistency guarantees
- [x] 🏇 Automatic race condition elimination
- [x] 👯 Global referential equality guarantees

## Principals of Rest Hooks

Expand Down
43 changes: 27 additions & 16 deletions website/src/components/Playground/MonacoPreloads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@ import React, { memo } from 'react';
function MonacoPreloads() {
return (
<>
{monacoPreloads.map((href, i) => (
<link
key={i}
rel="preload"
href={href}
as={href.endsWith('.js') ? 'script' : 'style'}
/>
))}
{workerPreloads.map((href, i) => (
<link
key={i + monacoPreloads.length}
rel="prefetch"
href={href}
as="script"
/>
))}
<script
dangerouslySetInnerHTML={{ __html: preloadScript }}
type="application/javascript"
/>
</>
);
}
Expand All @@ -35,3 +23,26 @@ const workerPreloads = [
'https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs/base/worker/workerMain.js',
'https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs/language/typescript/tsWorker.js',
];

const preloadScript = `
if (!/bot|googlebot|crawler|spider|robot|crawling|Mobile|Android|BlackBerry/i.test(
navigator.userAgent,
) && !window.monacoPreloaded) {
[${monacoPreloads.map(href => `'${href}'`).join(',')}].forEach(href => {
window.monacoPreloaded = true;
var link = document.createElement("link");
link.href = href;
link.rel = "preload";
link.as = href.endsWith('.js') ? 'script' : 'style';
document.head.appendChild(link);
});
[${workerPreloads.map(href => `'${href}'`).join(',')}].forEach(href => {
window.monacoPreloaded = true;
var link = document.createElement("link");
link.href = href;
link.rel = "prefetch";
link.as = 'script';
document.head.appendChild(link);
});
}
`;
2 changes: 1 addition & 1 deletion website/src/pages/demos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function DemoList() {
style={{ width: '100%', height: 'calc(100vh - 170px)' }}
></iframe>
</TabItem>
<TabItem value="NextJS">
<TabItem value="nextjs">
{/* <a
href="https://github.com/coinbase/rest-hooks/tree/master/examples/github-app"
target="_blank"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ in. (To prevent unwanted side effects.)

<details><summary>useInvalidator() triggers suspense</summary>

You can likely remove [invalidIfStale](/rest/api/Endpoint#invalidifstale-boolean) if used in conjunction with [useInvalidator()](../api/useInvalidator)
You can likely remove [invalidIfStale](/rest/api/Endpoint#invalidifstale-boolean) if used in conjunction with [useInvalidator()](/docs/5.0/api/useInvalidator)

[invalidIfStale](/rest/api/Endpoint#invalidifstale-boolean) is still useful to disable the `stale-while-revalidate` policy.

Expand Down

0 comments on commit 2d151e8

Please sign in to comment.