use super::observer::PropertyId;
pub trait Proxy: 'static {
fn proxy_state(&self) -> &ProxyState;
fn proxy_type_name(&self) -> &'static str {
self.proxy_state().type_name
}
fn invalidate(&self) {
let properties: Vec<PropertyId> = self.proxy_state().properties.to_vec();
for property in properties {
super::observer::trigger(property);
}
}
}
#[derive(Clone, Debug)]
pub struct ProxyState {
type_name: &'static str,
properties: Box<[PropertyId]>,
}
impl PartialEq for ProxyState {
fn eq(&self, other: &Self) -> bool {
self.type_name == other.type_name
}
}
impl ProxyState {
pub fn new<T: 'static>(properties: &[PropertyId]) -> Self {
Self {
type_name: std::any::type_name::<T>(),
properties: properties.to_vec().into_boxed_slice(),
}
}
pub fn type_name(&self) -> &'static str {
self.type_name
}
pub fn properties(&self) -> &[PropertyId] {
&self.properties
}
}