createReactiveStoreWithInitialValueAndSlotTracking
Creates a ReactiveStreamStore that combines an initial RPC fetch with an ongoing subscription to keep its state up to date.
The store uses slot-based comparison to ensure that only the most recent value is kept, regardless of whether it came from the initial RPC response or a subscription notification. This prevents stale data from overwriting newer data when the RPC response and subscription notifications arrive out of order.
Things to note:
- The returned store starts in
status: 'idle'. Call ReactiveStreamStore.connect | `connect()` to fire the RPC request and open the subscription. - From
idle, the store transitions throughloadinguntil the first response or notification arrives, then toloadedwith a SolanaRpcResponse containing the value and the slot context at which it was observed. - On error from either source, the store transitions to
status: 'error'preserving the last known value. Only the first error per connection window is captured. - A subsequent
connect()afterloadedorerroraborts the current connection, transitions throughstatus: 'retrying'(preserving stale data), and re-fires the RPC request and subscription with a fresh inner abort signal. - ReactiveStreamStore.reset | `reset()` aborts the current connection and returns the
store to
idle, clearingdataanderror. - Triggering the caller's
abortSignaldisconnects the store permanently; subsequentconnect()calls are no-ops.
Type Parameters
| Type Parameter |
|---|
TRpcValue |
TSubscriptionValue |
TItem |
Parameters
| Parameter | Type | Description |
|---|---|---|
config | CreateReactiveStoreWithInitialValueAndSlotTrackingConfig<TRpcValue, TSubscriptionValue, TItem> | - |
Returns
ReactiveStreamStore<Readonly<{
context: Readonly<{
slot: Slot;
}>;
value: TItem;
}>>
Example
See
ReactiveStreamStore