feat: rebuild doesn't return errors
This commit is contained in:
1 parent
df8aa77198
commit
f457b71131
18 files changed
+233
-189
No files matched your search
@@ -153,7 +153,7 @@ impl<'bump> DiffMachine<'bump> {
|
||||
/// This method implements a depth-first iterative tree traversal.
|
||||
///
|
||||
/// We do depth-first to maintain high cache locality (nodes were originally generated recursively).
|
||||
pub async fn work(&mut self) -> Result<()> {
|
||||
pub async fn work(&mut self) {
|
||||
// defer to individual functions so the compiler produces better code
|
||||
// large functions tend to be difficult for the compiler to work with
|
||||
while let Some(instruction) = self.stack.pop() {
|
||||
@@ -190,8 +190,6 @@ impl<'bump> DiffMachine<'bump> {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn mount(&mut self, and: MountType<'bump>) {
|
||||
|
||||
+24
-22
@@ -602,8 +602,31 @@ pub mod on {
|
||||
}
|
||||
|
||||
pub trait KeyboardEventInner {
|
||||
fn alt_key(&self) -> bool;
|
||||
|
||||
fn char_code(&self) -> u32;
|
||||
|
||||
/// Identify which "key" was entered.
|
||||
///
|
||||
/// This is the best method to use for all languages. They key gets mapped to a String sequence which you can match on.
|
||||
/// The key isn't an enum because there are just so many context-dependent keys.
|
||||
///
|
||||
/// A full list on which keys to use is available at:
|
||||
/// <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values>
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// match event.key().as_str() {
|
||||
/// "Esc" | "Escape" => {}
|
||||
/// "ArrowDown" => {}
|
||||
/// "ArrowLeft" => {}
|
||||
/// _ => {}
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
fn key(&self) -> String;
|
||||
|
||||
/// Get the key code as an enum Variant.
|
||||
///
|
||||
/// This is intended for things like arrow keys, escape keys, function keys, and other non-international keys.
|
||||
@@ -627,35 +650,14 @@ pub mod on {
|
||||
/// Check if the ctrl key was pressed down
|
||||
fn ctrl_key(&self) -> bool;
|
||||
|
||||
/// Identify which "key" was entered.
|
||||
///
|
||||
/// This is the best method to use for all languages. They key gets mapped to a String sequence which you can match on.
|
||||
/// The key isn't an enum because there are just so many context-dependent keys.
|
||||
///
|
||||
/// A full list on which keys to use is available at:
|
||||
/// <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values>
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// match event.key().as_str() {
|
||||
/// "Esc" | "Escape" => {}
|
||||
/// "ArrowDown" => {}
|
||||
/// "ArrowLeft" => {}
|
||||
/// _ => {}
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
fn key(&self) -> String;
|
||||
fn get_modifier_state(&self, key_code: &str) -> bool;
|
||||
|
||||
// fn key(&self) -> String;
|
||||
fn locale(&self) -> String;
|
||||
fn location(&self) -> usize;
|
||||
fn meta_key(&self) -> bool;
|
||||
fn repeat(&self) -> bool;
|
||||
fn shift_key(&self) -> bool;
|
||||
fn which(&self) -> usize;
|
||||
fn get_modifier_state(&self, key_code: usize) -> bool;
|
||||
}
|
||||
|
||||
pub trait FocusEventInner {
|
||||
|
||||
@@ -139,8 +139,8 @@ impl<'a> Mutations<'a> {
|
||||
|
||||
// refs are only assigned once
|
||||
pub struct NodeRefMutation<'a> {
|
||||
element: &'a mut Option<once_cell::sync::OnceCell<Box<dyn Any>>>,
|
||||
element_id: ElementId,
|
||||
pub element: &'a mut Option<once_cell::sync::OnceCell<Box<dyn Any>>>,
|
||||
pub element_id: ElementId,
|
||||
}
|
||||
|
||||
impl<'a> std::fmt::Debug for NodeRefMutation<'a> {
|
||||
|
||||
@@ -124,26 +124,12 @@ impl VirtualDom {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn launch_in_place(root: FC<()>) -> Self {
|
||||
let mut s = Self::new(root);
|
||||
s.rebuild().unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
/// Creates a new virtualdom and immediately rebuilds it in place, not caring about the RealDom to write into.
|
||||
///
|
||||
pub fn launch_with_props_in_place<P: Properties + 'static>(root: FC<P>, root_props: P) -> Self {
|
||||
let mut s = Self::new_with_props(root, root_props);
|
||||
s.rebuild().unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
pub fn base_scope(&self) -> &Scope {
|
||||
unsafe { self.shared.get_scope(self.base_scope).unwrap() }
|
||||
self.shared.get_scope(self.base_scope).unwrap()
|
||||
}
|
||||
|
||||
pub fn get_scope(&self, id: ScopeId) -> Option<&Scope> {
|
||||
unsafe { self.shared.get_scope(id) }
|
||||
self.shared.get_scope(id)
|
||||
}
|
||||
|
||||
/// Performs a *full* rebuild of the virtual dom, returning every edit required to generate the actual dom rom scratch
|
||||
@@ -152,7 +138,7 @@ impl VirtualDom {
|
||||
///
|
||||
/// Events like garabge collection, application of refs, etc are not handled by this method and can only be progressed
|
||||
/// through "run". We completely avoid the task scheduler infrastructure.
|
||||
pub fn rebuild<'s>(&'s mut self) -> Result<Mutations<'s>> {
|
||||
pub fn rebuild<'s>(&'s mut self) -> Mutations<'s> {
|
||||
let mut fut = self.rebuild_async().boxed_local();
|
||||
|
||||
loop {
|
||||
@@ -163,7 +149,11 @@ impl VirtualDom {
|
||||
}
|
||||
|
||||
/// Rebuild the dom from the ground up
|
||||
pub async fn rebuild_async<'s>(&'s mut self) -> Result<Mutations<'s>> {
|
||||
///
|
||||
/// This method is asynchronous to prevent the application from blocking while the dom is being rebuilt. Computing
|
||||
/// the diff and creating nodes can be expensive, so we provide this method to avoid blocking the main thread. This
|
||||
/// method can be useful when needing to perform some crucial periodic tasks.
|
||||
pub async fn rebuild_async<'s>(&'s mut self) -> Mutations<'s> {
|
||||
let mut diff_machine = DiffMachine::new(Mutations::new(), self.base_scope, &self.shared);
|
||||
|
||||
let cur_component = self
|
||||
@@ -176,7 +166,7 @@ impl VirtualDom {
|
||||
diff_machine
|
||||
.stack
|
||||
.create_node(cur_component.frames.fin_head(), MountType::Append);
|
||||
diff_machine.work().await.unwrap();
|
||||
diff_machine.work().await;
|
||||
} else {
|
||||
// todo: should this be a hard error?
|
||||
log::warn!(
|
||||
@@ -185,11 +175,20 @@ impl VirtualDom {
|
||||
);
|
||||
}
|
||||
|
||||
Ok(diff_machine.mutations)
|
||||
diff_machine.mutations
|
||||
}
|
||||
|
||||
// diff the dom with itself
|
||||
pub async fn diff_async<'s>(&'s mut self) -> Result<Mutations<'s>> {
|
||||
pub fn diff_sync<'s>(&'s mut self) -> Mutations<'s> {
|
||||
let mut fut = self.diff_async().boxed_local();
|
||||
|
||||
loop {
|
||||
if let Some(edits) = (&mut fut).now_or_never() {
|
||||
break edits;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn diff_async<'s>(&'s mut self) -> Mutations<'s> {
|
||||
let mut diff_machine = DiffMachine::new(Mutations::new(), self.base_scope, &self.shared);
|
||||
|
||||
let cur_component = self
|
||||
@@ -204,15 +203,15 @@ impl VirtualDom {
|
||||
new: cur_component.frames.fin_head(),
|
||||
});
|
||||
|
||||
diff_machine.work().await.unwrap();
|
||||
diff_machine.work().await;
|
||||
|
||||
Ok(diff_machine.mutations)
|
||||
diff_machine.mutations
|
||||
}
|
||||
|
||||
/// Runs the virtualdom immediately, not waiting for any suspended nodes to complete.
|
||||
///
|
||||
/// This method will not wait for any suspended nodes to complete.
|
||||
pub fn run_immediate<'s>(&'s mut self) -> Result<Mutations<'s>> {
|
||||
pub fn run_immediate<'s>(&'s mut self) -> Mutations<'s> {
|
||||
todo!()
|
||||
// use futures_util::FutureExt;
|
||||
// let mut is_ready = || false;
|
||||
|
||||
Reference in new issue
Block a user