WIP fix to event reader reactivity
This commit is contained in:
parent
350c00c52a
commit
5272be399b
|
@ -13,10 +13,12 @@ use dioxus::{
|
||||||
core::{ScopeId, ScopeState},
|
core::{ScopeId, ScopeState},
|
||||||
hooks::use_on_destroy,
|
hooks::use_on_destroy,
|
||||||
};
|
};
|
||||||
|
use std::any::TypeId;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub(crate) struct EcsSubscriptions {
|
pub(crate) struct EcsSubscriptions {
|
||||||
pub resources: Box<HashMap<ComponentId, HashSet<ScopeId>>>,
|
pub resources: Box<HashMap<ComponentId, HashSet<ScopeId>>>,
|
||||||
|
pub events: Box<HashMap<TypeId, (Box<dyn Fn(&World) -> bool>, HashSet<ScopeId>)>>,
|
||||||
pub world_and_queries: Box<HashSet<ScopeId>>,
|
pub world_and_queries: Box<HashSet<ScopeId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,15 +118,12 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Don't think this actually works. EcsSubscriptions needs to handle this.
|
|
||||||
pub fn use_event_reader<'a, E: Event>(cx: &'a ScopeState) -> EventIterator<'a, E> {
|
pub fn use_event_reader<'a, E: Event>(cx: &'a ScopeState) -> EventIterator<'a, E> {
|
||||||
|
// TODO: Register the subscription
|
||||||
|
|
||||||
let event_reader = cx.use_hook(|| ManualEventReader::default());
|
let event_reader = cx.use_hook(|| ManualEventReader::default());
|
||||||
let events = EcsContext::get_world(cx).resource::<Events<E>>();
|
let events = EcsContext::get_world(cx).resource::<Events<E>>();
|
||||||
let new_events = event_reader.read(events);
|
event_reader.read(events)
|
||||||
if new_events.len() != 0 {
|
|
||||||
(cx.schedule_update())();
|
|
||||||
}
|
|
||||||
new_events
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UseQuery<'a, Q: ReadOnlyWorldQuery, F: ReadOnlyWorldQuery> {
|
pub struct UseQuery<'a, Q: ReadOnlyWorldQuery, F: ReadOnlyWorldQuery> {
|
||||||
|
|
|
@ -93,6 +93,14 @@ fn schedule_ui_renders_from_ecs_subscriptions(ui_root: &mut UiRoot, world: &Worl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (new_events_exist, scope_ids) in ecs_subscriptions.events.values() {
|
||||||
|
if new_events_exist(world) {
|
||||||
|
for scope_id in scope_ids {
|
||||||
|
ui_root.virtual_dom.mark_dirty(*scope_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_ui(root_entity: Entity, ui_root: &mut UiRoot, world: &mut World) {
|
fn render_ui(root_entity: Entity, ui_root: &mut UiRoot, world: &mut World) {
|
||||||
|
|
Loading…
Reference in a new issue