Skip to content

Commit

Permalink
Review changes (round 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Diggsey committed Jun 13, 2021
1 parent f15a5cb commit ff52954
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/yew-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gloo = "0.2.1"
route-recognizer = "0.3.0"
regex = { version = "1.5.4", optional = true }
percent-encoding = "2.1.0"
anymap = "0.12"
anymap2 = "0.13.0"

[dependencies.web-sys]
version = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/yew-router/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,6 @@ pub fn replace(route: Route) {
pub fn current() -> Rc<Route> {
HistoryState::with(HistoryState::current_route)
}
pub fn register(callback: Callback<Rc<Route>>) -> HistoryListener {
pub fn attach_listener(callback: Callback<Rc<Route>>) -> HistoryListener {
HistoryState::with(|state| HistoryState::register(state, callback))
}
14 changes: 7 additions & 7 deletions packages/yew-router/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::cell::RefCell;
use std::rc::Rc;

use anymap::AnyMap;
use anymap2::AnyMap;
use yew::Callback;

use super::history::{self, HistoryListener, Route};
use crate::Routable;

type Entry<'a, T> = anymap::Entry<'a, dyn anymap::any::Any, T>;
type Entry<'a, T> = anymap2::Entry<'a, dyn anymap2::any::Any, T>;

#[derive(Debug, Clone)]
#[non_exhaustive]
Expand All @@ -34,7 +34,7 @@ impl<T: Routable> RouterState<T> {
fn try_with<R>(mut f: impl FnMut(Entry<Self>) -> Result<R, T>) -> R {
match Self::with(&mut f) {
Ok(res) => return res,
Err(error) => Self::handle_error(error),
Err(error) => Self::handle_not_found(error),
};
match Self::with(&mut f) {
Ok(res) => res,
Expand All @@ -49,7 +49,7 @@ impl<T: Routable> RouterState<T> {
Ok(Self {
last_route,
subscribers: Vec::new(),
_listener: history::register(Callback::from(Self::update)),
_listener: history::attach_listener(Callback::from(Self::update)),
})
}

Expand Down Expand Up @@ -90,16 +90,16 @@ impl<T: Routable> RouterState<T> {
})
}

fn handle_error(error: T) {
fn handle_not_found(fallback: T) {
// Whenever we fail to recognize a route, we redirect to the default one
history::replace(error.to_route());
history::replace(fallback.to_route());
}

fn update(route: Rc<Route>) {
match Self::with(|entry| Self::update_inner(entry, route)) {
Ok(None) => {}
Ok(Some(f)) => f(),
Err(error) => Self::handle_error(error),
Err(error) => Self::handle_not_found(error),
}
}

Expand Down

0 comments on commit ff52954

Please sign in to comment.