wip: refactor
This commit is contained in:
1 parent
9ad5e49654
commit
8b0eb87c72
13 files changed
+96
-128
No files matched your search
@@ -3,6 +3,7 @@ use std::{collections::HashMap, fmt::Debug, rc::Rc, sync::Arc};
|
||||
use dioxus_core::{
|
||||
events::{on::GenericEventInner, EventTrigger, SyntheticEvent},
|
||||
mutations::NodeRefMutation,
|
||||
scheduler::SchedulerMsg,
|
||||
DomEdit, ElementId, ScopeId,
|
||||
};
|
||||
use fxhash::FxHashMap;
|
||||
@@ -24,7 +25,7 @@ pub struct WebsysDom {
|
||||
|
||||
root: Element,
|
||||
|
||||
sender_callback: Rc<dyn Fn(EventTrigger)>,
|
||||
sender_callback: Rc<dyn Fn(SchedulerMsg)>,
|
||||
|
||||
// map of listener types to number of those listeners
|
||||
// This is roughly a delegater
|
||||
@@ -39,7 +40,7 @@ pub struct WebsysDom {
|
||||
last_node_was_text: bool,
|
||||
}
|
||||
impl WebsysDom {
|
||||
pub fn new(root: Element, cfg: WebConfig, sender_callback: Rc<dyn Fn(EventTrigger)>) -> Self {
|
||||
pub fn new(root: Element, cfg: WebConfig, sender_callback: Rc<dyn Fn(SchedulerMsg)>) -> Self {
|
||||
let document = load_document();
|
||||
|
||||
let mut nodes = NodeSlab::new(2000);
|
||||
@@ -277,7 +278,7 @@ impl WebsysDom {
|
||||
// "Result" cannot be received from JS
|
||||
// Instead, we just build and immediately execute a closure that returns result
|
||||
match decode_trigger(event) {
|
||||
Ok(synthetic_event) => trigger.as_ref()(synthetic_event),
|
||||
Ok(synthetic_event) => trigger.as_ref()(SchedulerMsg::UiEvent(synthetic_event)),
|
||||
Err(e) => log::error!("Error decoding Dioxus event attribute. {:#?}", e),
|
||||
};
|
||||
}) as Box<dyn FnMut(&Event)>);
|
||||
@@ -560,12 +561,11 @@ fn decode_trigger(event: &web_sys::Event) -> anyhow::Result<EventTrigger> {
|
||||
let triggered_scope = gi_id;
|
||||
// let triggered_scope: ScopeId = KeyData::from_ffi(gi_id).into();
|
||||
log::debug!("Triggered scope is {:#?}", triggered_scope);
|
||||
Ok(EventTrigger::new(
|
||||
virtual_event_from_websys_event(event.clone()),
|
||||
ScopeId(triggered_scope as usize),
|
||||
Some(ElementId(real_id as usize)),
|
||||
dioxus_core::events::EventPriority::High,
|
||||
))
|
||||
Ok(EventTrigger {
|
||||
event: virtual_event_from_websys_event(event.clone()),
|
||||
mounted_dom_id: Some(ElementId(real_id as usize)),
|
||||
scope: ScopeId(triggered_scope as usize),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn prepare_websys_dom() -> Element {
|
||||
|
||||
@@ -97,8 +97,7 @@ where
|
||||
F: FnOnce(WebConfig) -> WebConfig,
|
||||
{
|
||||
let config = config(WebConfig::default());
|
||||
let fut = run_with_props(root, root_props, config);
|
||||
wasm_bindgen_futures::spawn_local(fut);
|
||||
wasm_bindgen_futures::spawn_local(run_with_props(root, root_props, config));
|
||||
}
|
||||
/// This method is the primary entrypoint for Websys Dioxus apps. Will panic if an error occurs while rendering.
|
||||
/// See DioxusErrors for more information on how these errors could occour.
|
||||
@@ -143,9 +142,8 @@ pub async fn run_with_props<T: Properties + 'static>(root: FC<T>, root_props: T,
|
||||
|
||||
let deadline = work_loop.wait_for_idle_time().await;
|
||||
|
||||
if let Some(mut mutations) = dom.run_with_deadline(deadline).await {
|
||||
work_loop.wait_for_raf().await;
|
||||
websys_dom.process_edits(&mut mutations.edits);
|
||||
}
|
||||
let mut mutations = dom.run_with_deadline(deadline).await;
|
||||
work_loop.wait_for_raf().await;
|
||||
websys_dom.process_edits(&mut mutations[0].edits);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user