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

49 lines
940 B
Rust
Raw Permalink Normal View History

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