use tauri::{AppHandle, Error, Wry};
use super::Field;
#[cfg(doc)]
use super::Listen;
#[cfg(feature = "initial_value")]
#[doc(cfg(feature = "initial_value"))]
pub mod state_helper;
#[cfg(any(not(feature = "initial_value"), doc))]
pub trait Parent = Emit;
#[cfg(all(feature = "initial_value", not(doc)))]
pub trait Parent = ManagedEmit;
#[cfg(feature = "initial_value")]
#[doc(cfg(feature = "initial_value"))]
pub trait ManagedEmit: Emit
where
Self: 'static + Send + Sync,
{
fn get_value<F: Field<Self>>(
handle: &AppHandle,
f: impl Fn(&Self) -> F::Type,
) -> Option<F::Type> {
state_helper::directly::<Self, F>(handle, f)
}
}
pub trait Emit: Sized {
fn emit_all(&self, handle: &AppHandle<Wry>) -> Result<(), Error>;
fn emit<F: Field<Self>>(&self, handle: &AppHandle<Wry>) -> Result<(), Error>
where
Self: Parent;
fn update<F: Field<Self>>(
&mut self,
handle: &AppHandle<Wry>,
field: F::Type,
) -> Result<(), Error>
where
Self: Parent;
}