Core Concepts
Vue integration
Use the @rs-x/vue composable to bind expressions directly to Vue components — no manual subscriptions required.
Practical value
Key points
- useRsxExpression accepts a pre-built IExpression from rsx(...).
- useRsxModel wires Vue into your existing rs-x model so the template stays in sync as that model changes.
- Your rs-x model can be a plain object. You do not need to wrap it in Vue reactive(...) just to make rs-x updates work.
- Subscriptions are disposed automatically when the component scope is destroyed.
- Use rsx(..., { leafWatchRule })(model) to narrow which array or map entries trigger updates.
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 initRelated docs
- Vue official websiteDocs, guides, and Vue ecosystem
- Docs overviewCore concepts and API reference
- First expressionBind expressions and subscribe to changes
- CLIInstall, setup, build, and typecheck workflows
- CompilerBuild-time parsing, validation, and compiled expressions
- Batching transactionsGroup updates and emit once
- PerformanceParsing, binding, update costs, and memory