use crate::events::EventDescriptor;
use crate::*;
pub trait BindDescriptor {
type Event: EventDescriptor;
type ValueTy: Into<JsValue> + Clone;
const TARGET_PROPERTY: &'static str;
const CONVERT_FROM_JS: for<'a> fn(&'a JsValue) -> Option<Self::ValueTy>;
}
macro_rules! impl_bind {
($name:ident: $event:ty, $value:ty, $target:expr, $fn:expr) => {
#[allow(non_camel_case_types)]
pub struct $name;
impl BindDescriptor for $name {
type Event = $event;
type ValueTy = $value;
const TARGET_PROPERTY: &'static str = $target;
const CONVERT_FROM_JS: for<'a> fn(&'a JsValue) -> Option<Self::ValueTy> = $fn;
}
};
}
macro_rules! impl_binds {
($($name:ident: $event:ty, $value:ty, $target:expr, $fn:expr,)*) => {
$(impl_bind!($name: $event, $value, $target, $fn);)*
};
}
impl_binds! {
value: events::input, String, "value", JsValue::as_string,
valueAsNumber: events::input, f64, "valueAsNumber", JsValue::as_f64,
checked: events::change, bool, "checked", JsValue::as_bool,
}