auric-runtime 0.1.3

Runtime for the Ember-inspired Auric SPA framework
Documentation
use super::RouteDef;
use anyhow::Result;
use std::sync::Arc;
use web_sys::window;

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

impl Router {
    pub fn new(route_defs: &[RouteDef]) -> Self {
        let mut builder = actix_router::Router::build();
        for route_def in route_defs.iter() {
            builder.path(&route_def.path, route_def.clone());
        }
        let router = Arc::new(builder.finish());
        Self { router }
    }

    pub fn init(&self) -> 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(())
    }
}