Core Concepts

RxJS integration

Use RxJS Observables directly inside rs-x expressions — emissions flow into the reactive graph and trigger expression updates.

What it means

rs-x treats Observable-like values as reactive sources. When an Observable emits, dependent expressions re-evaluate and fire changed events.

Practical value

You can mix plain model fields and Observables in the same expression without manual subscription plumbing. This is useful for integrating streams with domain models or UI state.

Key points

Basic Observable binding example

Observable values participate in expressions like normal fields.
import { BehaviorSubject } from 'rxjs';
import { rsx } from '@rs-x/expression-parser';

const model = {
  price: new BehaviorSubject(100),
  quantity: 2,
};

// Observable values participate in expressions like normal fields
const totalExpr = rsx<number>('price * quantity')(model);

totalExpr.changed.subscribe(() => {
  console.log('total:', totalExpr.value);
});

model.quantity = 3; // logs "total: 300"
model.price.next(120); // logs "total: 360"

Nested Observable values example

Observable emits array entries that themselves contain Observable properties.
import { BehaviorSubject } from 'rxjs';
import { rsx } from '@rs-x/expression-parser';

// Observable that emits objects which contain Observables
const model = {
  cart: new BehaviorSubject([
    { price: new BehaviorSubject(10) },
    { price: new BehaviorSubject(20) },
  ]),
};

const firstPrice = rsx<number>('cart[0].price')(model);

firstPrice.changed.subscribe(() => {
  console.log('first price:', firstPrice.value);
});

model.cart.value[0].price.next(15); // logs "first price: 15"

Installation example

Install the core runtime packages and RxJS.
# CLI (recommended)
rsx init
npm install rxjs

# Manual
npm install @rs-x/core @rs-x/state-manager @rs-x/expression-parser rxjs