auric-runtime 0.1.6

Runtime for the Ember-inspired Auric SPA framework
Documentation
use super::RouteDef;
use crate::Context;
use anyhow::Result;

pub struct Router {
    route_defs: Vec<RouteDef>,
}

impl Router {
    pub fn new(route_defs: Vec<RouteDef>) -> Self {
        Self { route_defs }
    }

    pub fn init(&mut self, context: &dyn Context) -> Result<()> {
        // Initialize routes
        for route_def in &self.route_defs {
            let mut route = route_def.route.lock().expect("Failed locking route for initialization");
            route.init(context)?;
        }

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