velox-core 0.1.2

Core reactive primitives for the Velox UI framework
Documentation
  • Coverage
  • 83.49%
    91 out of 109 items documented2 out of 98 items with examples
  • Size
  • Source code size: 165.3 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 860.2 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • fahimaloy/velox
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • fahimaloy

velox-core

Reactive signals, effects and lifecycle primitives for the Velox UI framework.

Crates.io Downloads docs.rs License: MIT OR Apache-2.0 CI

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> with get/set/update/set_if_changed; subscriber notification is deferred inside batch
  • 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, and watch/watch_ref/watch_effect with (new, old) callbacks
  • Batching — batch collapses many sets into a single subscriber flush
  • Lifecycle hooks — on_mounted/on_updated/on_unmounted/on_resize and per-component cleanup
  • Provide/inject — typed dependency injection down the component tree, with fallbacks
  • next_tick queue — callbacks after the current reactive flush, drained synchronously with flush_sync
  • Two-way binding — the VModel trait, implemented for Cell<T>, RefCell<String>, Signal<T> and Ref<T>
  • !Send by design — everything is Rc/RefCell/thread-local; no data races by construction

Installation

cargo add velox-core

No feature flags. The only dependency is log 0.4.

Quick start

use velox_core::{computed_ref, ref_value, watch_ref};
use velox_core::signal::effect;

let count = ref_value(0);

// Derived state: re-runs whenever `count` changes.
let doubled = computed_ref({
    let count = count.clone();
    move || count.get() * 2
});

// Effects run once to collect dependencies, then on every change.
let printed = count.clone();
let handle = effect(move || println!("count = {}", printed.get()));

// Watchers fire only on change, with (new, old).
watch_ref(&count, |new, old| println!("{old} -> {new}"));

count.set(41);
assert_eq!(doubled.get(), 82);

handle.stop();

Interpolations and event handlers in generated components take &self — state lives in interior-mutable Ref<T> signals, not behind &mut self.

Documentation

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