fix: attach router listener to subscriber list

This commit is contained in:
Jonathan Kelley committed 2022-01-28 12:04:16 -05:00
1 parent a21e7d4dd1
commit 5ee9d6c434
1 file changed
+10 -1
+10 -1
View File
@@ -43,6 +43,7 @@ impl RouterService {
let location = history.location(); let location = history.location();
let path = location.path(); let path = location.path();
let onchange_listeners = Rc::new(RefCell::new(HashSet::new()));
let slots: Rc<RefCell<Vec<(ScopeId, String)>>> = Default::default(); let slots: Rc<RefCell<Vec<(ScopeId, String)>>> = Default::default();
let pending_events: Rc<RefCell<Vec<RouteEvent>>> = Default::default(); let pending_events: Rc<RefCell<Vec<RouteEvent>>> = Default::default();
let root_found = Rc::new(Cell::new(None)); let root_found = Rc::new(Cell::new(None));
@@ -52,6 +53,7 @@ impl RouterService {
let regen_route = regen_route.clone(); let regen_route = regen_route.clone();
let root_found = root_found.clone(); let root_found = root_found.clone();
let slots = slots.clone(); let slots = slots.clone();
let onchange_listeners = onchange_listeners.clone();
move || { move || {
root_found.set(None); root_found.set(None);
// checking if the route is valid is cheap, so we do it // checking if the route is valid is cheap, so we do it
@@ -60,6 +62,13 @@ impl RouterService {
regen_route(*slot); regen_route(*slot);
} }
for listener in onchange_listeners.borrow_mut().iter() {
log::trace!("regenerating listener {:?}", listener);
regen_route(*listener);
}
// also regenerate the root // also regenerate the root
regen_route(root_scope); regen_route(root_scope);
@@ -74,7 +83,7 @@ impl RouterService {
regen_route, regen_route,
slots, slots,
pending_events, pending_events,
onchange_listeners: Rc::new(RefCell::new(HashSet::new())), onchange_listeners,
cur_path_params: Rc::new(RefCell::new(HashMap::new())), cur_path_params: Rc::new(RefCell::new(HashMap::new())),
} }
} }