Skip to content

Commit

Permalink
Improve wording in README and documentation comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kyarik committed Dec 26, 2020
1 parent e9bda43 commit 7d80222
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ lazyResource<T>(loader: () => Promise<T>, options?: ResourceOptions): Resource<T

**Description**

`lazyResource` is used to create a lazy resource. It's lazy because it will not start loading the resource immediately. Instead, it will start loading it only when the `load` method is called. The resource can be read at any point inside a React component - if it has not loaded at the time it is called, the component will suspend.
`lazyResource` is used to create a lazy resource. It's lazy because it will not start loading the resource immediately. Instead, it will start loading it only when the `load` method is called. The resource can be read at any point inside a React component - if it has not loaded at the time it is read, the component will suspend.

**Example**

Expand Down Expand Up @@ -79,7 +79,7 @@ interface Resource<T> {

- `load: () => Promise<T>` begins loading the resource by calling the provided loader function. This method is idempotent - calling it after the first time has no effect. However, If the resource fails to load and `Resource#clearError()` is called (or `clearResourceErrors`), then calling this method will again begin loading the resource.

- `read: () => T` returns the loaded resource. If the resource is still loading when this method is called, it will throw the resource promise, which will make the React component suspend and show the fallback of the nearest `<Suspense>` ancestor. If the resource failed to load, then this method will throw the error with which the promise rejected, causing the nearest error boundary ancestor to be hit. This method must be called inside a React component and it can only be called after the resource started loading with `Resource#load()`.
- `read: () => T` returns the loaded resource. If the resource is still loading when this method is called, it will throw the resource promise, which will make the React component suspend and show the fallback of the nearest `<Suspense>` ancestor. If the resource failed to load, then this method will throw the error with which the promise rejected, causing the fallback of the nearest error boundary ancestor to be shown, if any. This method must be called inside a React component and it can only be called after the resource started loading with `Resource#load()`.

### `ResourceOptions`

Expand Down
2 changes: 1 addition & 1 deletion src/lazyResource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const resourcesWithError = new Set<Resource<unknown>>();
* Creates a lazy resource. It's lazy because it will not start loading the
* resource immediately. Instead, it will start loading it only when the `load`
* method is called. The resource can be read at any point inside a React
* component - if it has not loaded at the time it is called, the component
* component - if it has not loaded at the time it is read, the component
* will suspend.
* @param loader the loader function to load a resource of type `T`. This is a
* regular function that returns a promise.
Expand Down
8 changes: 4 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export interface Resource<T> {
* method is called, it will throw the resource promise, which will make the
* React component suspend and show the fallback of the nearest `<Suspense>`
* ancestor. If the resource failed to load, then this method will throw the
* error with which the promise rejected, causing the nearest error boundary
* ancestor to be hit. This method must be called inside a React component
* and it can only be called after the resource started loading with
* `Resource#load()`.
* error with which the promise rejected, causing the fallback of nearest
* error boundary ancestor to be shown, if any. This method must be called
* inside a React component and it can only be called after the resource
* started loading with `Resource#load()`.
*/
read: () => T;
}
Expand Down

0 comments on commit 7d80222

Please sign in to comment.