use super::{AccessorListener, IPropertyAccessor, PropertyAccessorBase};
use crate::data::BindingNotification;
use crate::BoxedValue;
use std::rc::Rc;
pub struct DataValidationBase {
pub base: PropertyAccessorBase,
pub inner: Rc<dyn IPropertyAccessor>,
}
impl DataValidationBase {
pub fn new(inner: Rc<dyn IPropertyAccessor>) -> Self {
Self { base: PropertyAccessorBase::new(), inner }
}
pub fn subscribe_core(&self, inner_value_changed: AccessorListener) {
self.inner.subscribe(inner_value_changed);
}
pub fn unsubscribe_core(&self) {
self.inner.dispose();
}
pub fn inner_value_changed(&self, value: Option<BoxedValue>) {
let notification = wrap_notification(value);
self.base.publish_value(Some(notification));
}
}
pub(crate) fn wrap_notification(value: Option<BoxedValue>) -> BoxedValue {
match value {
Some(v) if v.is::<BindingNotification>() => v,
other => Rc::new(BindingNotification::new(other)),
}
}