Skip to content

Commit

Permalink
Allow fragments and dynamic views in RouterBase (#471)
Browse files Browse the repository at this point in the history
Allow fragments and dynamic views in Router
  • Loading branch information
lukechu10 authored Aug 27, 2022
1 parent 75be1ca commit cfe8ef2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/sycamore-core/src/generic_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ pub trait GenericNode: fmt::Debug + Clone + PartialEq + Eq + Hash + 'static {
fn remove_self(&self);

/// Add a event handler to the event `name`.
/// The event should be removed once the scope is disposed, as to prevent accessing scope
/// variables after the scope is disposed.
fn event<'a, F: FnMut(Self::EventType) + 'a>(&self, cx: Scope<'a>, name: &str, handler: F);

/// Update inner text of the node. If the node has elements, all the elements are replaced with
Expand Down
10 changes: 7 additions & 3 deletions packages/sycamore-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,17 @@ where
}
}));
let route_signal = create_memo(cx, move || route.match_path(&pathname.get()));
// Delegate click events from child <a> tags.
let view = view(cx, route_signal);
// Delegate click events from child <a> tags.
if let Some(node) = view.as_node() {
node.event(cx, "click", integration.click_handler());
} else {
// TODO: support fragments and dynamic nodes
unimplemented!("support fragments and dynamic nodes for Router")
let view = view.clone();
create_effect_scoped(cx, move |cx| {
for node in view.clone().flatten() {
node.event(cx, "click", integration.click_handler());
}
});
}
view
}
Expand Down

0 comments on commit cfe8ef2

Please sign in to comment.