Skip to main content

Scope

Struct Scope 

Source
pub struct Scope { /* private fields */ }
Expand description

A DOM island, including the lifetime of all of its reactive bindings. Dropping the scope stops behavior; existing markup remains in the document.

Implementations§

Source§

impl Scope

Source

pub fn text<T: ToString>( &mut self, target: impl ElementTarget, read: impl Fn() -> T + 'static, ) -> Result<(), JsValue>

Replace a text leaf’s content reactively. Values are text, never HTML.

Source

pub fn text_node<T: ToString>( &mut self, text: &Text, read: impl Fn() -> T + 'static, ) -> Result<(), JsValue>

Bind a native text node, preserving its identity and all sibling nodes.

Source

pub fn attr( &mut self, target: impl ElementTarget, name: &str, read: impl Fn() -> Option<String> + 'static, ) -> Result<(), JsValue>

Bind an attribute. None removes it, including boolean attributes.

Source

pub fn class( &mut self, target: impl ElementTarget, name: &str, read: impl Fn() -> bool + 'static, ) -> Result<(), JsValue>

Source

pub fn on( &mut self, target: impl ElementTarget, event: &str, handler: impl FnMut(Event) + 'static, ) -> Result<(), JsValue>

Listen to a DOM event. All signal writes in one handler are batched.

Source

pub fn checked( &mut self, target: impl InputTarget, read: impl Fn() -> bool + 'static, ) -> Result<(), JsValue>

Source

pub fn value( &mut self, target: impl InputTarget, read: impl Fn() -> String + 'static, ) -> Result<(), JsValue>

Bind the current input property, including changes after user edits.

Source§

impl Scope

Source

pub fn finish_prepare_subtree(&self) -> Result<(), JsValue>

Finish this prepared subtree inside an externally owned transaction. Unlike finish_prepare, an inactive parent does not defer fallible setup. The caller must keep work inactive until all participants can commit.

Source

pub fn try_commit(&self) -> Result<(), JsValue>

Finish browser setup and activate owned work. Prepared ancestors still gate activation. Failure is returned to the mounting caller.

Source§

impl Scope

Source

pub fn slot<R: Into<Option<Content>>>( &mut self, target: impl ElementTarget, read: impl Fn() -> R + 'static, ) -> Result<(), JsValue>

Mount optional content in an empty host. An unchanged factory retains its DOM and local state; None removes it. Read signals inside read to select content reactively. Each host owns an independent instance.

Source

pub fn slot_with<K: PartialEq + 'static>( &mut self, target: impl ElementTarget, read: impl Fn() -> Option<(K, Content)> + 'static, ) -> Result<(), JsValue>

Like Self::slot, with an explicit reset key in addition to factory identity. Failed preparation leaves the previous instance alive.

Source§

impl Scope

Source

pub fn keyed<T, K>( &mut self, target: impl ElementTarget, items: impl Fn() -> Vec<T> + 'static, key: impl Fn(&T) -> K + 'static, render: impl Fn(Signal<T>) -> Result<Scope, JsValue> + 'static, ) -> Result<(), JsValue>
where T: Clone + PartialEq + 'static, K: Ord + Clone + 'static,

Reconcile a list by stable keys, retaining nodes, focus, and row scopes. render runs once per inserted key. The row signal delivers later values. This binding owns the container’s children. Duplicate keys are errors.

Source§

impl Scope

Source

pub fn property<V: Into<JsValue>>( &mut self, target: impl ElementTarget, name: &str, read: impl Fn() -> V + 'static, ) -> Result<(), JsValue>

Assign a JavaScript value to a custom element property after activation and definition. Objects retain identity; equal values skip the setter. Pending definitions retain neither the element nor Rust state after drop. A setter can have arbitrary external effects and is not transactional.

Source§

impl Scope

Source

pub fn mount_point( &mut self, container: &Element, ) -> Result<MountPoint, JsValue>

Append an empty insertion range to a container. Dropping this scope removes the anchors, but not the nodes of views still inside them: callers retain and dispose any child views they mount there.

Source

pub fn attach_at(&mut self, target: &MountPoint) -> Result<(), JsValue>

Insert this prepared view at the end of target without activating it. A root view is removed when the scope drops; a fragment removes its own range. Retain the scope and finish preparation before committing.

Source§

impl Scope

Source

pub fn new(root: Element) -> Self

Source

pub fn at(selector: &str) -> Result<Self, JsValue>

Attach to existing, ordinary HTML.

Source

pub fn from_template(selector: &str) -> Result<Self, JsValue>

Clone a standard HTML <template> containing exactly one root element. Templates contain plain HTML; Rust wires up the cloned elements.

Source

pub fn root(&self) -> &Element

Source

pub fn owner(&self) -> OwnerHandle

Source

pub fn dispose(&self)

Stop owned work immediately, even while an integration retains the scope.

Source

pub fn commit(&self)

Activate prepared work after insertion succeeds. Ancestors must also commit. Logs setup failure and disposes the owner. Use Self::try_commit when the caller must propagate a setup error.

Source

pub fn retain(&mut self, guard: impl Any)

Retain an integration guard for this scope without replacing component state.

Source

pub fn attach(&mut self, container: &Element) -> Result<(), JsValue>

Insert a prepared view. Its root will be removed on drop. Does not commit.

Source

pub fn adopt(&mut self, child: Scope)

Adopt a component attached to existing markup, retaining its lifetime.

Source

pub fn mount_child( &mut self, target: impl ElementTarget, child: Scope, ) -> Result<(), JsValue>

Append a component and adopt its lifetime. Dropping the parent detaches its bindings and removes the mounted child’s root from the document.

Source

pub fn select(&self, selector: &str) -> Result<Element, JsValue>

Select within this island. :scope addresses the root itself.

Trait Implementations§

Source§

impl Drop for Scope

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Scope

§

impl !Send for Scope

§

impl !Sync for Scope

§

impl !UnwindSafe for Scope

§

impl Freeze for Scope

§

impl Unpin for Scope

§

impl UnsafeUnpin for Scope

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 = !

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

fn try_from(value: U) -> Result<T, !>

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