euv-core 0.48.3

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Lifecycle operations for `Effect`.
impl Effect {
    /// Creates and immediately runs a reactive side effect, auto-tracking all signals and memos read.
    ///
    /// # Arguments
    ///
    /// - `F` - Effect callback executed initially and on every tracked dependency change.
    ///
    /// # Returns
    ///
    /// - `Self` - Handle to the registered effect.
    pub fn new<F>(callback: F) -> Self
    where
        F: FnMut() + 'static,
    {
        let id: EffectId = with_runtime(
            |rt: &mut ReactiveRuntime| rt.create_effect(callback),
            EffectId::default(),
        );
        run_effect(id);
        Self { id }
    }

    /// Returns the underlying `EffectId`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Effect handle.
    ///
    /// # Returns
    ///
    /// - `EffectId` - Underlying arena identifier.
    #[must_use]
    pub fn id(&self) -> EffectId {
        let Self { id } = *self;
        id
    }

    /// Returns the number of active upstream dependencies tracked by this effect in O(1).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Effect handle to inspect.
    ///
    /// # Returns
    ///
    /// - `usize` - Number of currently linked dependency edges, or `0` if disposed.
    #[must_use]
    pub fn dependency_count(&self) -> usize {
        let id: EffectId = self.id();
        with_runtime_ref(|rt: &ReactiveRuntime| rt.effect_dependency_count(id), 0)
    }

    /// Returns an ordered snapshot of `(edge_index, source_tag)` pairs currently linked to this effect.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Effect handle to inspect.
    ///
    /// # Returns
    ///
    /// - `Vec<(u32, u32)>` - Active dependency edge indices and packed source tags in traversal order.
    #[must_use]
    pub fn dependency_edge_snapshot(&self) -> Vec<(u32, u32)> {
        let id: EffectId = self.id();
        with_runtime_ref(
            |rt: &ReactiveRuntime| rt.effect_edge_snapshot(id),
            Vec::new(),
        )
    }

    /// Disposes this effect so it no longer reacts to upstream changes.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Effect handle to dispose.
    pub fn dispose(&self) {
        let id: EffectId = self.id();
        with_runtime(
            |rt: &mut ReactiveRuntime| {
                rt.dispose_effect(id);
            },
            (),
        );
    }
}