Adding in routing::current_url function

This commit is contained in:
Pauan 2018-11-24 10:58:19 -10:00
parent ca6aba0a93
commit 50b7b00f64
1 changed files with 10 additions and 4 deletions

View File

@ -41,16 +41,16 @@ impl<A> State<A> {
}*/
fn current_url() -> String {
fn current_url_string() -> String {
window().location().unwrap().href().unwrap()
}
// TODO inline ?
fn change_url(mutable: &Mutable<Url>) {
let new_url = current_url();
let mut lock = mutable.lock_mut();
let new_url = current_url_string();
// TODO test that this doesn't notify if the URLs are the same
// TODO helper method for this
// TODO can this be made more efficient ?
@ -68,7 +68,7 @@ struct CurrentUrl {
impl CurrentUrl {
#[inline]
fn new() -> Self {
let value = Mutable::new(Url::new(&current_url()));
let value = Mutable::new(Url::new(&current_url_string()));
let callback = {
let value = value.clone();
@ -106,6 +106,12 @@ lazy_static! {
}
#[inline]
pub fn current_url() -> Url {
URL.value.get_cloned()
}
#[inline]
pub fn url() -> impl Signal<Item = Url> {
URL.value.signal_cloned()