Skip to content

Commit 9c9ead9

Browse files
BHUVANSH855alxhub
authored andcommitted
docs: document resource stream usage
1 parent f7cb609 commit 9c9ead9

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎adev/src/content/guide/signals/resource.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ The `ResourceLoaderParams` object contains three properties: `params`, `previous
5757

5858
If the `params` computation returns `undefined`, the loader function does not run and the resource status becomes `'idle'`.
5959

60+
### Streaming resources
61+
62+
Use `loader` when a resource performs a single asynchronous operation, such as fetching data from an HTTP endpoint.
63+
64+
Use `stream` when your data source can emit multiple values over time. Unlike `loader`, which resolves once for each request, `stream` returns a signal whose value can continue to update as new data becomes available.
65+
66+
Streaming resources are useful for continuously updating data sources such as WebSockets, Server-Sent Events (SSE), or Firestore `onSnapshot` listeners.
67+
68+
```typescript
69+
const userUpdates = signal({value: 'Alice'});
70+
71+
const userResource = resource({
72+
stream: () => userUpdates,
73+
});
74+
75+
// Later, when new data arrives:
76+
userUpdates.set({value: 'Bob'});
77+
```
78+
6079
### Aborting requests
6180

6281
A resource aborts an outstanding loading operation if the `params` computation changes while the resource is loading.

0 commit comments

Comments
 (0)