velox-core
Reactive signals, effects and lifecycle primitives for the Velox UI framework.
Overview
velox-core is the floor of the Velox stack: single-threaded reactive state (Signal), effects, computed values, Vue-style ref/watch/computed ergonomics, component lifecycle hooks, dependency injection, and a next_tick queue. It knows nothing about elements, CSS or pixels — velox-dom, velox-style and velox-renderer all sit on top of it. Everything is Rc/RefCell/thread-local by construction and deliberately !Send; the crate's own doctests pin that property with compile_fail guards.
Features
- Signals —
Signal<T>withget/set/update/set_if_changed; subscriber notification is deferred insidebatch - Effects — run once to collect dependencies, then again on every change; stoppable via
EffectHandle - Computed values — derived signals that recompute only when their dependencies change
- Vue-style ergonomics —
ref_value/shallow_ref,computed_ref, andwatch/watch_ref/watch_effectwith(new, old)callbacks - Batching —
batchcollapses manysets into a single subscriber flush - Lifecycle hooks —
on_mounted/on_updated/on_unmounted/on_resizeand per-component cleanup - Provide/inject — typed dependency injection down the component tree, with fallbacks
next_tickqueue — callbacks after the current reactive flush, drained synchronously withflush_sync- Two-way binding — the
VModeltrait, implemented forCell<T>,RefCell<String>,Signal<T>andRef<T> !Sendby design — everything isRc/RefCell/thread-local; no data races by construction
Installation
No feature flags. The only dependency is log 0.4.
Quick start
use ;
use effect;
let count = ref_value;
// Derived state: re-runs whenever `count` changes.
let doubled = computed_ref;
// Effects run once to collect dependencies, then on every change.
let printed = count.clone;
let handle = effect;
// Watchers fire only on change, with (new, old).
watch_ref;
count.set;
assert_eq!;
handle.stop;
Interpolations and event handlers in generated components take &self — state lives in interior-mutable Ref<T> signals, not behind &mut self.
Documentation
- API reference: docs.rs/velox-core
- Book: the Counter tutorial — signals, effects and reactivity in practice
Workspace crates
Velox is a workspace of six published crates. This crate is marked (this crate).
| Crate | What it provides | Documentation |
|---|---|---|
| velox-core · this crate | Reactive primitives: signals, effects, lifecycle hooks | docs.rs |
| velox-dom | VNode types, block + flex layout, positioning, overflow |
docs.rs |
| velox-style | CSS parsing, selectors, cascade; styles applied to VNode |
docs.rs |
| velox-renderer | Rendering backends, event dispatch, hit testing | docs.rs |
| velox-sfc | Single-file component compiler (pest grammar) → Rust | docs.rs |
| veloxc | The CLI and dev server | docs.rs |
Status
Published on crates.io at 0.1.1.
The reactive core is complete and in production use across the stack: signals, effects, computed values, watchers, lifecycle hooks, provide/inject and next_tick all work today. emit/emit_void are intentional no-op placeholders until codegen supplies a real event sink. Everything is deliberately !Send — the crate is single-threaded by design, and its doctests enforce that with compile_fail guards.
License
Licensed under MIT OR Apache-2.0.
Copyright © FAHIM AHMED fahimaloy@tutamail.com