use mobiler_core::*;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone)]
pub enum Msg {
EnablePush,
PushToken(PluginResponse),
PushEvent(PluginResponse),
Posted(PluginResponse),
}
#[derive(Default, Serialize, Deserialize)]
pub struct Model {
pub token: Option<String>,
pub last_event: Option<String>,
}
impl MyApp {
fn handle(&self, msg: Msg, model: &mut Model, cx: &mut Cx<Msg>) {
match msg {
Msg::EnablePush => {
cx.plugin("push", "register", "", Msg::PushToken);
cx.subscribe("push", "push", "events", "", Msg::PushEvent);
}
Msg::PushToken(r) => {
if r.ok {
model.token = Some(r.output.clone());
cx.post("https://api.example.com/devices", r.output, Msg::Posted);
}
}
Msg::PushEvent(r) => {
if r.ok {
model.last_event = Some(r.output.clone());
}
}
Msg::Posted(_) => {}
}
}
}