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.
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{rsx}from'@rs-x/expression-parser';import{watchIndexRecursiveRule}from'@rs-x/state-manager';constmodel={config:{theme:{color:'blue',size:'medium'},},};// Without the rule: only reference replacement fires.constwithoutRule=rsx('config.theme')(model);withoutRule.changed.subscribe(()=>console.log('changed'));model.config.theme.color='red';// does NOT fire — sub-property mutation ignoredmodel.config.theme={color:'green',size:'large'};// fires — reference replaced// With the rule: sub-property mutations also fire.constwithRule=rsx('config.theme')(model,watchIndexRecursiveRule);withRule.changed.subscribe(()=>console.log('changed'));model.config.theme.color='red';// fires — recursive observer on colormodel.config.theme.size='large';// fires — recursive observer on size
Usage with stateManager
import{watchIndexRecursiveRule}from'@rs-x/state-manager';importtype{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.