API Reference

watchIndexRecursiveRule

A pre-built IIndexWatchRule whose test() always returns true. Pass it to rsx('expr')(model, watchIndexRecursiveRule) to make any mutation inside the identifier's value fire reevaluation, not just direct reference replacement.

What it does

By default, rs-x watches only the leaf identifier for direct value replacement. For values that are not automatically proxied (plain objects), mutations inside the value do not fire reevaluation.

watchIndexRecursiveRuleextends observation to all sub-properties of the identifier's value. Because test() always returns true, rs-x installs observers for every nested property, recursively.

Note that Array, Map, Set, and Datevalues are already proxied automatically — this rule is most useful when the identifier's value is a plain object.

Import

import { watchIndexRecursiveRule } from '@rs-x/state-manager';

Implementation

It is a singleton constant — a plain object implementing IIndexWatchRule with test set to truePredicate.

// @rs-x/state-manager
export const watchIndexRecursiveRule: IIndexWatchRule = {
  id: 'b95cf4e7-b6d3-475e-af41-fb78d0d58baa',
  context: undefined,
  dispose: emptyFunction,
  test: truePredicate, // always returns true
};

Usage with rsx

import { rsx } from '@rs-x/expression-parser';
import { watchIndexRecursiveRule } from '@rs-x/state-manager';

const model = {
  config: {
    theme: { color: 'blue', size: 'medium' },
  },
};

// Without the rule: only reference replacement fires.
const withoutRule = rsx('config.theme')(model);
withoutRule.changed.subscribe(() => console.log('changed'));

model.config.theme.color = 'red'; // does NOT fire — sub-property mutation ignored
model.config.theme = { color: 'green', size: 'large' }; // fires — reference replaced

// With the rule: sub-property mutations also fire.
const withRule = rsx('config.theme')(model, watchIndexRecursiveRule);
withRule.changed.subscribe(() => console.log('changed'));

model.config.theme.color = 'red'; // fires — recursive observer on color
model.config.theme.size = 'large'; // fires — recursive observer on size

Usage with stateManager

import { watchIndexRecursiveRule } from '@rs-x/state-manager';
import type { IStateManager } from '@rs-x/state-manager';

// Also accepted directly by stateManager.watchState:
stateManager.watchState(model, 'config', {
  indexWatchRule: watchIndexRecursiveRule,
});

When to use

  • The leaf identifier returns a plain object and you want any mutation anywhere inside it to fire reevaluation.
  • You are prototyping and want the broadest possible observation without writing a custom rule.

When not to use

  • The identifier's value is an Array, Map, Set, or Date — these are already proxied automatically.
  • You only want to react to specific sub-property changes — write a custom IIndexWatchRule whose test() returns true only for the properties you care about.