Skip to main content

ReactiveRuntime

Struct ReactiveRuntime 

Source
pub struct ReactiveRuntime {
    pub owners: SlotMap<Owner, Scope>,
    pub nodes: SlotMap<NodeId, ReactiveNode>,
    pub owner_stack: Vec<Owner>,
    pub current_tracker: Option<NodeId>,
    pub pending: Vec<NodeId>,
    pub deferred: Vec<NodeId>,
    pub flushing: bool,
    pub component_owners: HashMap<*const (), Vec<Owner>>,
    pub fn_ptr_mounts: HashMap<*const (), Vec<MountId>>,
    pub mount_id_counter: u64,
    pub pending_mounts: Vec<Box<dyn FnOnce()>>,
    /* private fields */
}
Expand description

The reactive runtime itself. One per thread (held in a thread_local! slot in mod.rs).

All public reactive operations route through here. The pattern is always:

  1. Open a short with_borrow_mut to read or mutate owners / nodes / current_*.
  2. If user code needs to run (effect / computed closure), drop the borrow first by cloning the necessary handles out, then call the closure.
  3. Re-open a short borrow to restore book-keeping.

This keeps the RefCell borrow window narrow enough that user code running inside a closure can re-enter the runtime (read signals, write signals, register new effects) without panicking.

Fields§

§owners: SlotMap<Owner, Scope>§nodes: SlotMap<NodeId, ReactiveNode>§owner_stack: Vec<Owner>

Owner stack: the topmost is the “current” owner — new signals, effects, computed values, and lifecycle hooks register against it. Push when entering a Owner::with (or #[component]) scope, pop on exit.

§current_tracker: Option<NodeId>

The effect/computed currently being computed, if any. Signal reads inside this effect register a sources/subscribers link against it.

§pending: Vec<NodeId>

Queue of effect/computed nodes scheduled to re-run on the next flush. Populated by signal writes; drained by [flush_pending].

§deferred: Vec<NodeId>

Nodes that were scheduled to run but whose owner is paused. Sit here until their owner is resumed; on resume, drain back into Self::pending so the deferred work fires. See Owner::pause / Owner::resume for the lifecycle.

§flushing: bool

True while [flush_pending] is actively draining pending. Used to avoid recursive flushes (signal writes inside a running effect just enqueue; we keep draining the queue until empty rather than recursing).

§component_owners: HashMap<*const (), Vec<Owner>>

Component-fn-pointer → list of live owners that ran that fn. Populated by register_component; consulted by the A6 hot- reload path to find which owners to dispose when a fn body gets subsecond-patched.

§fn_ptr_mounts: HashMap<*const (), Vec<MountId>>

Component-fn-pointer → list of remountable mount sites that ran that fn. Mirror of component_owners indexed by MountId instead of Owner so it survives the dispose + re-create cycle on each hot-reload remount (the owner is fresh every time, the mount id is stable).

§mount_id_counter: u64

Monotonic counter for fresh MountIds.

§pending_mounts: Vec<Box<dyn FnOnce()>>

Pending on_mount callbacks, in the order they were registered. Drained by super::flush_mounts — which the renderer (A3) will call after appending a component’s view to its parent.

Implementations§

Source§

impl ReactiveRuntime

Source

pub fn new() -> Self

Source

pub fn current_owner(&self) -> Option<Owner>

Current top-of-stack owner. None outside any owner scope (the pre-mount state, basically only relevant for tests).

Trait Implementations§

Source§

impl Default for ReactiveRuntime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.