Skip to main content

42 docs tagged with "state"

View All Tags

@rx-angular/state

@rx-angular/state (RxState) is a lightweight library for managing reactive

@rx-angular/state/selections

A set of RxJS operators for selecting state in an efficient, distinct way. They are the building blocks RxState uses internally for its select surface, and they are exported so you can use them directly inside your own RxJS pipelines.

CompareFn

The function which is used by KeyCompareMap to determine if changes are distinct or not. Should return true if values are equal.

distinctUntilSomeChanged

RxJS operator that emits items from the source Observable that are distinct by comparison from the previous item, comparing each key in the keys array. It is named distinctUntilSomeChanged because it iterates the keys and uses Array.prototype.some to decide whether values are distinct.

Get started with rxState

This guide walks you through creating your first rxState() instance, seeding initial state, connecting async sources, and binding state into a signals-first template.

How to refactor manual subscriptions to rxEffects

This is a case study: take a side effect wired up with manual subscribe/cleanup and refactor it to rxEffects, which ties the effect to the component lifecycle for you. rxEffects is the sanctioned replacement for the removed hold() on the functional RxState surface.

KeyCompareMap

The KeyCompareMap is used to configure custom comparison for defined keys.

Manage side effects with rxEffects

Goal: run Observable- or Promise-based side effects in a component without manual subscribe / takeUntil(destroy$) / ngOnDestroy bookkeeping. rxEffects owns the subscriptions and cleans them up when the host is destroyed.

Partial updates

RxState has partial updates built in. Every change sent to the state over set or connect is treated as a partial update: an instance typed with T accepts Partial on both methods, and the change is merged into the current state.

rxActions

The functional way to create an RxActions instance: a typed set of event channels that turns an actions interface into a dispatcher (login(...)), an observable stream (login$), and a side-effect binder (onLogin(...)) for each key. It is imported from the @rx-angular/state/actions secondary entry point and must be called within an injection context; the instance is destroyed automatically when the host component/directive/service is destroyed.

rxEffects

rxEffects is the functional creation function for RxEffects, a small helper that runs Observable- or Promise-based side effects and cleans up their subscriptions automatically when the current injection context is destroyed. It replaces manual subscribe / takeUntil(destroy$) / ngOnDestroy boilerplate.

rxState

The functional way to create and configure an RxState instance. rxState() is a wrapper around the class-based RxState service that binds its lifecycle to the current injection context; the instance is destroyed automatically when the host component/directive/service is destroyed. It is the modern default for local reactive state; the class API is the legacy surface.

RxState

RxState is a light-weight reactive state management service for managing local state in Angular. This page documents the class-based API, the legacy surface. For new code, prefer the functional rxState() creator, which wraps this class and binds its lifecycle to the injection context automatically.

RxState configuration

RxState instances read two settings from the DI tree: the scheduler that drives state computation and the accumulator that merges each change into the state. Both are provided with the provideRxStateConfig provider function and its configuration features.

select

RxJS operator that reads a slice of state as a shared, replayed, distinct Observable. It removes the need to think about late subscribers, multiple subscribers, or repeated emissions of the same value. select has several overloads: read the whole state, apply operators, access a (possibly nested) key by path, or transform a key/slice with a projection function.

selectSlice

RxJS operator that emits only the provided keys from the source Observable. Each key is filtered to emit only defined values and checked for distinct emissions; comparison is done for each key in the keys array. A selection is only emitted when it is valid (every selected key must exist and be defined in the source), so the operator always yields a complete slice with all values present.

stateful

RxJS operator that turns an arbitrary source Observable into a stateful one: it emits only distinct and defined values, and shares/replays the result for multiple subscribers. It behaves like the Observable pipe method (pass zero or more RxJS operators and they are composed in order) while adding the repetitive state-processing guarantees on top.