|
@@ -62,12 +62,10 @@ impl RouterService {
|
|
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
|
|
for (slot, root) in slots.borrow_mut().iter().rev() {
|
|
for (slot, root) in slots.borrow_mut().iter().rev() {
|
|
- // log::trace!("regenerating slot {:?} for root '{}'", slot, root);
|
|
|
|
regen_route(*slot);
|
|
regen_route(*slot);
|
|
}
|
|
}
|
|
|
|
|
|
for listener in onchange_listeners.borrow_mut().iter() {
|
|
for listener in onchange_listeners.borrow_mut().iter() {
|
|
- // log::trace!("regenerating listener {:?}", listener);
|
|
|
|
regen_route(*listener);
|
|
regen_route(*listener);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -91,31 +89,24 @@ impl RouterService {
|
|
}
|
|
}
|
|
|
|
|
|
pub fn push_route(&self, route: &str) {
|
|
pub fn push_route(&self, route: &str) {
|
|
- // log::trace!("Pushing route: {}", route);
|
|
|
|
self.history.borrow_mut().push(route);
|
|
self.history.borrow_mut().push(route);
|
|
}
|
|
}
|
|
|
|
|
|
pub fn register_total_route(&self, route: String, scope: ScopeId, fallback: bool) {
|
|
pub fn register_total_route(&self, route: String, scope: ScopeId, fallback: bool) {
|
|
let clean = clean_route(route);
|
|
let clean = clean_route(route);
|
|
- // log::trace!("Registered route '{}' with scope id {:?}", clean, scope);
|
|
|
|
self.slots.borrow_mut().push((scope, clean));
|
|
self.slots.borrow_mut().push((scope, clean));
|
|
}
|
|
}
|
|
|
|
|
|
pub fn should_render(&self, scope: ScopeId) -> bool {
|
|
pub fn should_render(&self, scope: ScopeId) -> bool {
|
|
- // log::trace!("Should render scope id {:?}?", scope);
|
|
|
|
if let Some(root_id) = self.root_found.get() {
|
|
if let Some(root_id) = self.root_found.get() {
|
|
- // log::trace!(" we already found a root with scope id {:?}", root_id);
|
|
|
|
if root_id == scope {
|
|
if root_id == scope {
|
|
- // log::trace!(" yes - it's a match");
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- // log::trace!(" no - it's not a match");
|
|
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
let location = self.history.borrow().location();
|
|
let location = self.history.borrow().location();
|
|
let path = location.path();
|
|
let path = location.path();
|
|
- // log::trace!(" current path is '{}'", path);
|
|
|
|
|
|
|
|
let roots = self.slots.borrow();
|
|
let roots = self.slots.borrow();
|
|
|
|
|
|
@@ -124,23 +115,15 @@ impl RouterService {
|
|
// fallback logic
|
|
// fallback logic
|
|
match root {
|
|
match root {
|
|
Some((id, route)) => {
|
|
Some((id, route)) => {
|
|
- // log::trace!(
|
|
|
|
- // " matched given scope id {:?} with route root '{}'",
|
|
|
|
- // scope,
|
|
|
|
- // route,
|
|
|
|
- // );
|
|
|
|
if let Some(params) = route_matches_path(route, path) {
|
|
if let Some(params) = route_matches_path(route, path) {
|
|
- // log::trace!(" and it matches the current path '{}'", path);
|
|
|
|
self.root_found.set(Some(*id));
|
|
self.root_found.set(Some(*id));
|
|
*self.cur_path_params.borrow_mut() = params;
|
|
*self.cur_path_params.borrow_mut() = params;
|
|
true
|
|
true
|
|
} else {
|
|
} else {
|
|
if route == "" {
|
|
if route == "" {
|
|
- // log::trace!(" and the route is the root, so we will use that without a better match");
|
|
|
|
self.root_found.set(Some(*id));
|
|
self.root_found.set(Some(*id));
|
|
true
|
|
true
|
|
} else {
|
|
} else {
|
|
- // log::trace!(" and the route '{}' is not the root nor does it match the current path", route);
|
|
|
|
false
|
|
false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -158,12 +141,10 @@ impl RouterService {
|
|
}
|
|
}
|
|
|
|
|
|
pub fn subscribe_onchange(&self, id: ScopeId) {
|
|
pub fn subscribe_onchange(&self, id: ScopeId) {
|
|
- // log::trace!("Subscribing onchange for scope id {:?}", id);
|
|
|
|
self.onchange_listeners.borrow_mut().insert(id);
|
|
self.onchange_listeners.borrow_mut().insert(id);
|
|
}
|
|
}
|
|
|
|
|
|
pub fn unsubscribe_onchange(&self, id: ScopeId) {
|
|
pub fn unsubscribe_onchange(&self, id: ScopeId) {
|
|
- // log::trace!("Subscribing onchange for scope id {:?}", id);
|
|
|
|
self.onchange_listeners.borrow_mut().remove(&id);
|
|
self.onchange_listeners.borrow_mut().remove(&id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -186,36 +167,20 @@ fn route_matches_path(route: &str, path: &str) -> Option<HashMap<String, String>
|
|
let route_pieces = route.split('/').collect::<Vec<_>>();
|
|
let route_pieces = route.split('/').collect::<Vec<_>>();
|
|
let path_pieces = clean_path(path).split('/').collect::<Vec<_>>();
|
|
let path_pieces = clean_path(path).split('/').collect::<Vec<_>>();
|
|
|
|
|
|
- // log::trace!(
|
|
|
|
- // " checking route pieces {:?} vs path pieces {:?}",
|
|
|
|
- // route_pieces,
|
|
|
|
- // path_pieces,
|
|
|
|
- // );
|
|
|
|
-
|
|
|
|
if route_pieces.len() != path_pieces.len() {
|
|
if route_pieces.len() != path_pieces.len() {
|
|
- // log::trace!(" the routes are different lengths");
|
|
|
|
return None;
|
|
return None;
|
|
}
|
|
}
|
|
|
|
|
|
let mut matches = HashMap::new();
|
|
let mut matches = HashMap::new();
|
|
for (i, r) in route_pieces.iter().enumerate() {
|
|
for (i, r) in route_pieces.iter().enumerate() {
|
|
- // log::trace!(" checking route piece '{}' vs path", r);
|
|
|
|
// If this is a parameter then it matches as long as there's
|
|
// If this is a parameter then it matches as long as there's
|
|
// _any_thing in that spot in the path.
|
|
// _any_thing in that spot in the path.
|
|
if r.starts_with(':') {
|
|
if r.starts_with(':') {
|
|
- // log::trace!(
|
|
|
|
- // " route piece '{}' starts with a colon so it matches anything",
|
|
|
|
- // r,
|
|
|
|
- // );
|
|
|
|
let param = &r[1..];
|
|
let param = &r[1..];
|
|
matches.insert(param.to_string(), path_pieces[i].to_string());
|
|
matches.insert(param.to_string(), path_pieces[i].to_string());
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- // log::trace!(
|
|
|
|
- // " route piece '{}' must be an exact match for path piece '{}'",
|
|
|
|
- // r,
|
|
|
|
- // path_pieces[i],
|
|
|
|
- // );
|
|
|
|
|
|
+
|
|
if path_pieces[i] != *r {
|
|
if path_pieces[i] != *r {
|
|
return None;
|
|
return None;
|
|
}
|
|
}
|