use crate::element::parser::ElementParser;
use crate::event::Event;
use crate::{
command::WebDynproCommand,
element::system::{ClientInspectorDef, Custom, CustomClientInfo, LoadingPlaceholderDef},
error::WebDynproError,
};
pub struct ClientInspectorNotifyEventCommand {
element_def: ClientInspectorDef,
message: String,
}
impl ClientInspectorNotifyEventCommand {
pub fn new(element_def: ClientInspectorDef, message: &str) -> Self {
Self {
element_def,
message: message.to_string(),
}
}
}
impl WebDynproCommand for ClientInspectorNotifyEventCommand {
type Result = Event;
fn dispatch(&self, parser: &ElementParser) -> Result<Self::Result, WebDynproError> {
parser
.element_from_def(&self.element_def)?
.notify(&self.message)
}
}
pub struct LoadingPlaceholderLoadEventCommand {
element_def: LoadingPlaceholderDef,
}
impl LoadingPlaceholderLoadEventCommand {
pub fn new(element_def: LoadingPlaceholderDef) -> Self {
Self { element_def }
}
}
impl WebDynproCommand for LoadingPlaceholderLoadEventCommand {
type Result = Event;
fn dispatch(&self, parser: &ElementParser) -> Result<Self::Result, WebDynproError> {
parser.element_from_def(&self.element_def)?.load()
}
}
pub struct CustomClientInfoEventCommand {
element: Custom,
info: CustomClientInfo,
}
impl CustomClientInfoEventCommand {
pub fn new(element: Custom, info: CustomClientInfo) -> Self {
Self { element, info }
}
}
impl WebDynproCommand for CustomClientInfoEventCommand {
type Result = Event;
fn dispatch(&self, _parser: &ElementParser) -> Result<Self::Result, WebDynproError> {
Ok(self.element.client_infos(self.info.clone()))
}
}