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
impl Scope
Sourcepub fn text<T: ToString>(
&mut self,
target: impl ElementTarget,
read: impl Fn() -> T + 'static,
) -> Result<(), JsValue>
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.
Sourcepub fn text_node<T: ToString>(
&mut self,
text: &Text,
read: impl Fn() -> T + 'static,
) -> Result<(), JsValue>
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.
Sourcepub fn attr(
&mut self,
target: impl ElementTarget,
name: &str,
read: impl Fn() -> Option<String> + 'static,
) -> Result<(), JsValue>
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.
pub fn class( &mut self, target: impl ElementTarget, name: &str, read: impl Fn() -> bool + 'static, ) -> Result<(), JsValue>
Sourcepub fn on(
&mut self,
target: impl ElementTarget,
event: &str,
handler: impl FnMut(Event) + 'static,
) -> Result<(), JsValue>
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.
pub fn checked( &mut self, target: impl InputTarget, read: impl Fn() -> bool + 'static, ) -> Result<(), JsValue>
Source§impl Scope
impl Scope
Sourcepub fn finish_prepare_subtree(&self) -> Result<(), JsValue>
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.
Sourcepub fn try_commit(&self) -> Result<(), JsValue>
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
impl Scope
Sourcepub fn slot<R: Into<Option<Content>>>(
&mut self,
target: impl ElementTarget,
read: impl Fn() -> R + 'static,
) -> Result<(), JsValue>
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§impl Scope
impl Scope
Sourcepub 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>
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>
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
impl Scope
Sourcepub fn property<V: Into<JsValue>>(
&mut self,
target: impl ElementTarget,
name: &str,
read: impl Fn() -> V + 'static,
) -> Result<(), JsValue>
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
impl Scope
Sourcepub fn mount_point(
&mut self,
container: &Element,
) -> Result<MountPoint, JsValue>
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§impl Scope
impl Scope
pub fn new(root: Element) -> Self
Sourcepub fn from_template(selector: &str) -> Result<Self, JsValue>
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.
pub fn root(&self) -> &Element
pub fn owner(&self) -> OwnerHandle
Sourcepub fn dispose(&self)
pub fn dispose(&self)
Stop owned work immediately, even while an integration retains the scope.
Sourcepub fn commit(&self)
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.
Sourcepub fn retain(&mut self, guard: impl Any)
pub fn retain(&mut self, guard: impl Any)
Retain an integration guard for this scope without replacing component state.
Sourcepub fn attach(&mut self, container: &Element) -> Result<(), JsValue>
pub fn attach(&mut self, container: &Element) -> Result<(), JsValue>
Insert a prepared view. Its root will be removed on drop. Does not commit.
Sourcepub fn adopt(&mut self, child: Scope)
pub fn adopt(&mut self, child: Scope)
Adopt a component attached to existing markup, retaining its lifetime.
Sourcepub fn mount_child(
&mut self,
target: impl ElementTarget,
child: Scope,
) -> Result<(), JsValue>
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.