rust-galmon-web/src/models/global.rs

49 lines
901 B
Rust

use crate::api;
use crate::config::Config;
use crate::models::helper::*;
#[derive(Debug)]
pub struct GlobalT {
config: Config,
}
impl Model for GlobalT {
type FetchData = api::Global;
const NAME: &'static str = "Global";
fn refresh(sr: &ModelHandle<Self>) -> Option<api::FetchTask> {
let sref = sr.clone();
let sd = sr.data();
sr.service().api_global(&sd.config, move |result| {
sref.set_received(result);
})
}
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Global(pub(super) ModelHandle<GlobalT>);
impl std::ops::Deref for Global {
type Target = ModelHandle<GlobalT>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Global {
pub fn new(config: Config) -> Self {
Self(ModelHandle::new(
GlobalT { config },
(),
))
}
pub(super) fn new_shared(config: Config, base: ModelBase) -> Self {
Self(ModelHandle::new(
GlobalT { config },
base,
))
}
}