wip: performance looks good, needs more testing

This commit is contained in:
Jonathan Kelley committed 2021-09-22 04:11:27 -04:00
1 parent 84b5ddded5
commit 4b6ca05f2c
9 files changed
+56 -42

No files matched your search

+3 -5
View File
@@ -520,8 +520,6 @@ fn virtual_event_from_websys_event(event: web_sys::Event) -> SyntheticEvent {
/// This function decodes a websys event and produces an EventTrigger
/// With the websys implementation, we attach a unique key to the nodes
fn decode_trigger(event: &web_sys::Event) -> anyhow::Result<UserEvent> {
log::debug!("Handling event!");
let target = event
.target()
.expect("missing target")
@@ -535,7 +533,7 @@ fn decode_trigger(event: &web_sys::Event) -> anyhow::Result<UserEvent> {
let attrs = target.attributes();
for x in 0..attrs.length() {
let attr: Attr = attrs.item(x).unwrap();
log::debug!("attrs include: {:#?}, {:#?}", attr.name(), attr.value());
// log::debug!("attrs include: {:#?}, {:#?}", attr.name(), attr.value());
}
use anyhow::Context;
@@ -558,11 +556,11 @@ fn decode_trigger(event: &web_sys::Event) -> anyhow::Result<UserEvent> {
.context("failed to parse real id")?;
// Call the trigger
log::debug!("decoded scope_id: {}, node_id: {:#?}", gi_id, real_id);
// log::debug!("decoded scope_id: {}, node_id: {:#?}", gi_id, real_id);
let triggered_scope = gi_id;
// let triggered_scope: ScopeId = KeyData::from_ffi(gi_id).into();
log::debug!("Triggered scope is {:#?}", triggered_scope);
// log::debug!("Triggered scope is {:#?}", triggered_scope);
Ok(UserEvent {
name: event_name_from_typ(&typ),
event: virtual_event_from_websys_event(event.clone()),
-2
View File
@@ -152,8 +152,6 @@ pub async fn run_with_props<T: Properties + 'static>(root: FC<T>, root_props: T,
// run the virtualdom work phase until the frame deadline is reached
let mutations = dom.run_with_deadline(|| (&mut deadline).now_or_never().is_some());
log::debug!("received mutations {:#?}", mutations);
// wait for the animation frame to fire so we can apply our changes
work_loop.wait_for_raf().await;
+7 -4
View File
@@ -8,7 +8,7 @@ use web_sys::Window;
pub struct RafLoop {
window: Window,
ric_receiver: async_channel::Receiver<()>,
ric_receiver: async_channel::Receiver<u32>,
raf_receiver: async_channel::Receiver<()>,
ric_closure: Closure<dyn Fn(JsValue)>,
raf_closure: Closure<dyn Fn(JsValue)>,
@@ -25,7 +25,10 @@ impl RafLoop {
let (ric_sender, ric_receiver) = async_channel::unbounded();
let ric_closure: Closure<dyn Fn(JsValue)> = Closure::wrap(Box::new(move |_v: JsValue| {
ric_sender.try_send(()).unwrap()
//
let deadline = _v.dyn_into::<web_sys::IdleDeadline>().unwrap();
let time_remaining = deadline.time_remaining() as u32;
ric_sender.try_send(time_remaining).unwrap()
}));
// execute the polyfill for safari
@@ -46,8 +49,8 @@ impl RafLoop {
/// waits for some idle time and returns a timeout future that expires after the idle time has passed
pub async fn wait_for_idle_time(&self) -> TimeoutFuture {
let ric_fn = self.ric_closure.as_ref().dyn_ref::<Function>().unwrap();
let deadline: u32 = self.window.request_idle_callback(ric_fn).unwrap();
self.ric_receiver.recv().await.unwrap();
let _cb_id: u32 = self.window.request_idle_callback(ric_fn).unwrap();
let deadline = self.ric_receiver.recv().await.unwrap();
let deadline = TimeoutFuture::new(deadline);
deadline
}