1use crate::events::EventDescriptor;
4use crate::*;
5
6pub trait BindDescriptor {
8 type Event: EventDescriptor;
10 type ValueTy: Into<JsValue> + Clone;
12 const TARGET_PROPERTY: &'static str;
14 const CONVERT_FROM_JS: for<'a> fn(&'a JsValue) -> Option<Self::ValueTy>;
16}
17
18macro_rules! impl_bind {
19 ($name:ident: $event:ty, $value:ty, $target:expr, $fn:expr) => {
20 #[allow(non_camel_case_types)]
21 pub struct $name;
22 impl BindDescriptor for $name {
23 type Event = $event;
24 type ValueTy = $value;
25 const TARGET_PROPERTY: &'static str = $target;
26 const CONVERT_FROM_JS: for<'a> fn(&'a JsValue) -> Option<Self::ValueTy> = $fn;
27 }
28 };
29}
30
31macro_rules! impl_binds {
32 ($($name:ident: $event:ty, $value:ty, $target:expr, $fn:expr,)*) => {
33 $(impl_bind!($name: $event, $value, $target, $fn);)*
34 };
35}
36
37impl_binds! {
38 value: events::input, String, "value", JsValue::as_string,
39 valueAsNumber: events::input, f64, "valueAsNumber", JsValue::as_f64,
40 checked: events::change, bool, "checked", JsValue::as_bool,
41}