You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(core): rename resource's request to params (angular#60919)
As decided in the resource RFC, this commit renames the `request` option of
a resource to `params`, including the subsequent argument passed to the
loader. It also corrects the type in the process to properly allow narrowing
of the `undefined` value.
Fixesangular#58871
PR Closeangular#60919
The `resource` function accepts a `ResourceOptions` object with two main properties: `request` and `loader`.
30
+
The `resource` function accepts a `ResourceOptions` object with two main properties: `params` and `loader`.
31
31
32
-
The `request` property defines a reactive computation that produce a request value. Whenever signals read in this computation change, the resource produces a new request value, similar to `computed`.
32
+
The `params` property defines a reactive computation that produces a parameter value. Whenever signals read in this computation change, the resource produces a new parameter value, similar to `computed`.
33
33
34
-
The `loader` property defines a `ResourceLoader`— an async function that retrieves some state. The resource calls the loader every time the `request` computation produces a new value, passing that value to the loader. See [Resource loaders](#resource-loaders) below for more details.
34
+
The `loader` property defines a `ResourceLoader`— an async function that retrieves some state. The resource calls the loader every time the `params` computation produces a new value, passing that value to the loader. See [Resource loaders](#resource-loaders) below for more details.
35
35
36
36
`Resource` has a `value` signal that contains the results of the loader.
37
37
38
38
## Resource loaders
39
39
40
40
When creating a resource, you specify a `ResourceLoader`. This loader is an async function that accepts a single parameter— a `ResourceLoaderParams` object— and returns a value.
41
41
42
-
The `ResourceLoaderParams` object contains three properties: `request`, `previous`, and `abortSignal`.
42
+
The `ResourceLoaderParams` object contains three properties: `params`, `previous`, and `abortSignal`.
|`request`| The value of the resource's `request` computation. |
46
+
|`params`| The value of the resource's `params` computation.|
47
47
|`previous`| An object with a `status` property, containing the previous `ResourceStatus`. |
48
48
|`abortSignal`| An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). See [Aborting requests](#aborting-requests) below for details. |
49
49
50
-
If the `request` computation returns `undefined`, the loader function does not run and the resource status becomes `'idle'`.
50
+
If the `params` computation returns `undefined`, the loader function does not run and the resource status becomes `'idle'`.
51
51
52
52
### Aborting requests
53
53
54
-
A resource aborts an outstanding request if the `request` computation changes while the resource is loading.
54
+
A resource aborts an outstanding loading operation if the `params` computation changes while the resource is loading.
55
55
56
56
You can use the `abortSignal` in `ResourceLoaderParams` to respond to aborted requests. For example, the native `fetch` function accepts an `AbortSignal`:
0 commit comments