Skip to content

Commit

Permalink
Add migration guide and keep deprecated method
Browse files Browse the repository at this point in the history
  • Loading branch information
mfal committed Nov 7, 2023
1 parent 50f3fde commit 720353b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const NewsItem = ({ id }) => {
// Use tags 🏷️ with support for "tree structures" 🌳
});

// Do not care about any loading states - just use the result 🤩
// Do not care about any loading states just use the result 🤩
return (
<li>
{news.by}: {news.title}
Expand Down Expand Up @@ -93,6 +93,7 @@ const App = () => {
- [Opt-Out Loading](#opt-out-loading)
- [Error handling](#error-handling)
- [Best practices](#best-practices)
- [Migration guides](#migration-guides)

## Installing

Expand Down Expand Up @@ -292,7 +293,7 @@ Default: `true`
If `true`, the previously loaded value will be returned during refresh is in
progress. The loading view will only be triggered during initial load.

If `false`, the loading view will always be triggered - during initial load and
If `false`, the loading view will always be triggered during initial load and
refresh as well.

#### tags
Expand Down Expand Up @@ -412,7 +413,7 @@ resource is created or an existing resource is taken from the resource store. If
a resources has loaded once, it exists in the store and contains the cached
result of the async loader function.

It is noticeable that not the raw result is cached in some "result cache" - **it
It is noticeable that not the raw result is cached in some "result cache" **it
is the resource the keeps the cached result which itself is stored in the
resource store**.

Expand Down Expand Up @@ -757,7 +758,7 @@ const App = () => (
### Gotchas when defining "built-in" loading views

When you are using `.use()` or `usePromise()` in your component, it can not
define its own loading boundary - at least not for directly used Async
define its own loading boundary at least not for directly used Async
Resources.

In this example the fallback component will not be shown:
Expand All @@ -778,7 +779,7 @@ const UserAvatar = ({ userResource, size }) => {

The following approaches can help you to solve this issue:

- Split up your component into two separate components - one private with the
- Split up your component into two separate components one private with the
regular rendering, and another one wrapping it with a loading boundary while
forwarding props to it.

Expand Down Expand Up @@ -1039,3 +1040,10 @@ export const UserProfileName: FC<{ id: string }> = (props) => {
return <>{user.getFullName()}</>;
};
```

## Migration guides

### V1 to V2

- For more naming consistency the `.watch()` method of the Async Resource has
changed to `.use()`. Replace all usages of `watch()` with `use()`.
7 changes: 7 additions & 0 deletions src/resource/AsyncResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ export class AsyncResource<T = unknown> {
return useWatchResourceValue(this, options);
}

/** @deprecated Renamed to `use` in version 2 */
public watch<TOptions extends UseWatchResourceOptions>(
options: TOptions = {} as TOptions,
): UseWatchResourceResult<T, TOptions> {
return this.use(options);
}

public watchState(): AsyncResourceState {
return useWatchObservableValue(this.state);
}
Expand Down

0 comments on commit 720353b

Please sign in to comment.