Skip to main content

App

Struct App 

Source
pub struct App;
Expand description

A zero-sized application context struct providing access to core euv framework APIs.

This struct serves as a namespace for framework functions, allowing them to be accessed in a more object-oriented style. It contains no fields and all methods are effectively static.

The App struct provides unified access to:

  • Signal management (use_signal)
  • Batched updates (batch)
  • DOM mounting (mount)
  • Scheduled updates (schedule_update)
  • Cleanup registration (use_cleanup)
  • Interval handling (use_interval)
  • Window event handling (use_window_event)

Implementations§

Source§

impl App

Implementation of core framework APIs for the App struct.

This implementation block provides static methods that delegate to the corresponding framework functions. All methods are available directly on the App type without requiring an instance.

Source

pub fn use_signal<T, F>(init: F) -> Signal<T>
where T: Clone + PartialEq + 'static, F: FnOnce() -> T,

Creates a new reactive signal with the given initial value.

Uses the current HookContext to maintain signal identity across re-renders. On the first call at a given hook index, the signal is created with init() and stored. On subsequent re-renders, the existing signal at that index is returned unchanged.

§Arguments
  • FnOnce() -> T - A closure that computes the initial value of the signal.
§Returns
  • Signal<T> - A reactive signal containing the initialized or existing value.
Source

pub fn batch<F, R>(callback: F) -> R
where F: FnOnce() -> R,

Batches signal updates within a closure, deferring DOM dispatch until the outermost batch completes.

Sets SUPPRESS_SCHEDULE to true so that any Signal::set() calls inside the closure mark their dependents dirty precisely but do not queue a microtask dispatch. When the outermost batch completes, a single dispatch is scheduled if any dirty slots were accumulated during the batch, ensuring that all pending updates are processed.

Unlike the legacy full-broadcast approach, this uses precise dependency tracking: only the dynamic nodes that actually depend on the changed signals are marked dirty and re-rendered.

§Arguments
  • FnOnce() -> R - The closure to execute with batched updates.
§Returns
  • R - The result of the closure execution.
Source

pub fn mount<S, F>(selector: S, render_fn: F)
where S: AsRef<str>, F: FnOnce() -> VirtualNode,

Mounts the given virtual DOM tree to a specific element matched by a CSS selector.

Supported selector syntax:

  • "#id" — select by element ID
  • ".class" — select by class name (uses the first match)
  • "tag" — select by tag name (uses the first match)
§Arguments
  • S: AsRef<str> - A CSS selector string to locate the target element.
  • FnOnce() -> VirtualNode + 'static - A closure that returns the virtual DOM tree to render.
Source

pub fn schedule_update(dependents: &[usize])

Schedules a deferred signal update with precise dirty marking.

Marks only the specified dynamic node IDs as dirty, then queues a single microtask dispatch if one is not already pending. When SUPPRESS_SCHEDULE is true, slots are still marked dirty but no dispatch is scheduled, allowing batch to batch precise dirty marks without triggering premature DOM updates.

§Arguments
  • &[usize] - Dynamic node IDs to mark dirty.
Source

pub fn use_cleanup<F>(cleanup: F)
where F: FnOnce() + 'static,

Registers a cleanup callback that will be executed when the current hook context is cleared (e.g., when a match arm switches).

This is useful for cleaning up side effects like intervals, timeouts, or subscriptions that are not automatically managed by signals.

The cleanup callback is only registered once on the first render. On subsequent re-renders at the same hook index, this is a no-op.

§Arguments
  • FnOnce() + 'static - The cleanup callback to execute on context teardown.
Source

pub fn use_interval<F>(millis: i32, callback: F) -> IntervalHandle
where F: FnMut() + 'static,

Creates a recurring interval that invokes the given closure at the specified period, returning an IntervalHandle that is automatically cleared when the hook context is cleared (i.e., when the component unmounts or a match arm switches).

Unlike calling set_interval_with_callback_and_timeout_and_arguments_0

  • Closure::forget() manually, this hook ensures the interval is properly cleaned up, preventing memory leaks and stale callbacks.

The interval is only created once on the first render. On subsequent re-renders at the same hook index, the existing handle is returned unchanged.

§Arguments
  • i32 - The interval period in milliseconds.
  • FnMut() + 'static - The closure to invoke on each interval tick.
§Returns
  • IntervalHandle - A handle that can be used to cancel the interval early.
§Panics

Panics if window() is unavailable on the current platform.

Source

pub fn use_window_event<E, F>(event_name: E, callback: F)
where E: AsRef<str>, F: FnMut() + 'static,

Registers a window.addEventListener callback using event delegation, automatically removed when the hook context is cleared.

Uses the global window event proxy registry so that only one window.addEventListener call is made per event name regardless of how many components listen to the same event. On cleanup, only the handler entry is removed from the proxy registry; the shared window listener remains active for other consumers.

The event listener is only registered once on the first render. On subsequent re-renders at the same hook index, this is a no-op.

§Arguments
  • E: AsRef<str> - The event name to listen for (e.g., “hashchange”, “popstate”, “resize”).
  • FnMut() + 'static - The callback to invoke when the event fires.

Trait Implementations§

Source§

impl Clone for App

Source§

fn clone(&self) -> App

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for App

Source§

impl Debug for App

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for App

Source§

fn default() -> App

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

impl Eq for App

Source§

impl Hash for App

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for App

Source§

fn cmp(&self, other: &App) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for App

Source§

fn eq(&self, other: &App) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for App

Source§

fn partial_cmp(&self, other: &App) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for App

Auto Trait Implementations§

§

impl Freeze for App

§

impl RefUnwindSafe for App

§

impl Send for App

§

impl Sync for App

§

impl Unpin for App

§

impl UnsafeUnpin for App

§

impl UnwindSafe for App

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more