Constructor
new Resource(name, handlerFn, componentContextopt, optionsopt)
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
name |
string | Resource name. |
|
handlerFn |
function | The function to execute (e.g., fetch call). |
|
componentContext |
object |
<optional> |
The component instance context. |
options |
object |
<optional> |
Resource options (e.g., pollInterval). |
- Source:
Classes
Members
loading
Indicates whether the resource is currently pending.
- Source:
traceRequest :object|null
The trace node for the request currently in flight, so its settlement can point back at it.
Type:
- object | null
- Source:
Methods
fetch(result) → {Promise:.<any:>}
Evaluates the resource result and updates internal state with request ID guard.
Parameters:
| Name | Type | Description |
|---|---|---|
result |
any | The result from the handler (Promise or sync value). |
- Source:
Returns:
mutate(nextValue)
Imperatively sets the local value without a network call (useful for optimistic UI).
Parameters:
| Name | Type | Description |
|---|---|---|
nextValue |
any |
- Source:
read() → {any}
Reads the resource value. Throws Promise if pending (Suspense). Throws Error if rejected (ErrorBoundary). Returns value if resolved.
- Source:
Returns:
- Type
- any
refetch() → {Promise:.<any:>}
Imperatively triggers a re-fetch, bypassing watcher dependency updates.
- Source:
Returns:
teardown()
Cleans up the watcher, aborts pending in-flight requests, and clears the polling timer.
- Source: