auric-runtime 0.1.6

Runtime for the Ember-inspired Auric SPA framework
Documentation
use crate::{Config, Context, data::Store, routing::Router};
use std::sync::Arc;

struct ContextImpl {
    config: Config,
    store: Arc<Store>,
}

pub struct App {
    context: ContextImpl,
}

impl App {
    pub fn new(config: Config, mut router: Router, store: Store) -> Self {
        let store = Arc::new(store);
        let context = ContextImpl { config, store };
        router.init(&context).expect("failed initializing router");
        Self { context }
    }
}

impl Context for ContextImpl {
    fn config(&self) -> &Config {
        &self.config
    }

    fn store(&self) -> Arc<Store> {
        self.store.clone()
    }
}

impl Context for App {
    fn config(&self) -> &Config {
        &self.context.config
    }

    fn store(&self) -> Arc<Store> {
        self.context.store.clone()
    }
}