Core Concepts

Vue integration

Use the @rs-x/vue composable to bind expressions directly to Vue components — no manual subscriptions required.

What it means

The @rs-x/vue package provides useRsxExpression for pre-built expressions and useRsxModel when you want to bind model fields with less boilerplate.

Practical value

You keep Vue components declarative while rs-x handles fine-grained dependency tracking. Vue updates automatically whenever the expression value changes.

Key points

useRsxExpression — pre-built IExpression example

Build the expression once at module scope and reuse it. The Vue composable subscribes to those pre-built expressions and keeps the displayed values in sync while the inputs mutate the shared model.

Preview

Edit the code and the preview recompiles from that updated source.

Live demo

Code

useRsxModel — component-owned model example

Use useRsxModel(model) when you want Vue to keep the template in sync with an rs-x model. Define the model, call the hook once in setup(), and keep binding that same model in the template.

Preview

Edit the code and the preview recompiles from that updated source.

Live demo

Code

Expression change transactions example

Run the same two async updates with and without a transaction and compare the emitted updates.

Preview

Edit the code and the preview recompiles from that updated source.

Live demo

Code

Vue single-file component example

A complete Vue single-file component example with a plain object model bound through useRsxModel.

<script setup lang="ts">
import { useRsxModel } from '@rs-x/vue';

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

function bump() {
  model.quantity += 1;
}
</script>

<template>
  <div>
    <p>Price: {{ model.price }}</p>
    <p>Quantity: {{ model.quantity }}</p>
    <p>Total: {{ model.price * model.quantity }}</p>

    <button @click="bump">Add one</button>
  </div>

Leaf watch rule example

Track only specific indices in a collection to avoid unnecessary updates.

import { computed } from 'vue';
import { rsx } from '@rs-x/expression-parser';
import type { IIndexWatchRule } from '@rs-x/state-manager';

const model = {
  items: ['apple', 'banana', 'cherry'],
};

const watchFirstOnly: IIndexWatchRule = {
  id: 'first-index-only',
  context: null,
  test(index, target) {
    return Array.isArray(target) && index === 0;
  },
  dispose() {},
};

const listExpr = rsx<string[]>('items', { leafWatchRule: watchFirstOnly })(model);

const firstItem = computed(() => listExpr.value?.[0]);

Installation example

Run rsx init in your Vue project to install the right packages and apply the setup automatically. See the CLI docs.

rsx init