euv_ui/hook/use_mounted/impl.rs
1use super::*;
2
3/// Inherent implementation of [`UseMounted`].
4impl UseMounted {
5 /// Creates a handle with the flag starting at `false`.
6 ///
7 /// # Returns
8 ///
9 /// - `UseMounted` - The fresh handle.
10 pub(crate) fn new() -> Self {
11 Self {
12 mounted: Signal::create(false),
13 }
14 }
15
16 /// Returns the current flag as a snapshot.
17 ///
18 /// # Returns
19 ///
20 /// - `bool` - `true` once the DOM has been committed.
21 pub fn is_mounted(&self) -> bool {
22 self.get_mounted().get()
23 }
24
25 /// Raises the flag once the DOM has been committed.
26 ///
27 /// The wait is a macrotask rather than a microtask on purpose: the
28 /// renderer commits a signal-driven update in a microtask, so a
29 /// microtask scheduled from inside a render could run before that
30 /// commit and would see a DOM that is not there yet.
31 pub(crate) fn attach(&self) {
32 let mounted: Signal<bool> = self.get_mounted();
33 after_mount(move || {
34 mounted.set(true);
35 });
36 }
37}