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

49 lines
913 B
Rust

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