auric-runtime 0.1.2-rc.1

Runtime module for the `auric` MVC SPA framework
Documentation
use crate::RouteDef;
use std::sync::Arc;
use web_sys::window;

#[derive(Clone)]
pub struct Router {
    #[allow(unused)]
    router: Arc<actix_router::Router<RouteDef>>,
}

impl Default for Router {
    fn default() -> Self {
        let builder = actix_router::Router::build();
        let router = Arc::new(builder.finish());
        Self { router }
    }
}

impl Router {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn init(&self) -> anyhow::Result<()> {
        // Find route for href
        let _href = window()
            .and_then(|win| win.location().href().ok())
            .expect("Could not access window location");
        // TODO

        // Enter route
        // TODO

        // Done
        web_sys::console::log_1(&"Initialized router".into());
        Ok(())
    }
}