1use crate::{EventSignal, Scope, SendSync, Sendable, SharedSignal, Signal, View};
2
3pub trait Properties {
4 type Setter<'a>
5 where
6 Self: 'a;
7
8 fn setter(&mut self) -> Self::Setter<'_>;
9}
10
11pub trait Events {
12 type Setter<'a>
13 where
14 Self: 'a;
15
16 fn setter(&mut self) -> Self::Setter<'_>;
17}
18
19pub trait BindCallback {
20 type Event;
21
22 fn bind<'a>(&mut self, cx: Scope<'a>, callback: impl FnMut(&Self::Event) + Sendable + 'a);
23}
24
25impl<T: SendSync> BindCallback for EventSignal<T> {
26 type Event = T;
27
28 fn bind<'a>(&mut self, cx: Scope<'a>, callback: impl FnMut(&Self::Event) + Sendable + 'a) {
29 self.subscribe(cx, callback);
30 }
31}
32
33impl<T: SendSync> BindCallback for Option<EventSignal<T>> {
34 type Event = T;
35
36 fn bind<'a>(&mut self, cx: Scope<'a>, callback: impl FnMut(&Self::Event) + Sendable + 'a) {
37 let signal = self.get_or_insert_with(EventSignal::new);
38 signal.subscribe(cx, callback);
39 }
40}
41
42pub trait Bindings {
43 type Setter<'a>
44 where
45 Self: 'a;
46
47 fn setter(&mut self) -> Self::Setter<'_>;
48}
49
50pub trait Bindable<'a> {
51 type Item;
52
53 fn bind(&mut self, cx: Scope<'a>, signal: &'a Signal<Self::Item>);
54}
55
56impl<'a, T: Clone + PartialEq + SendSync + 'static> Bindable<'a> for &'a Signal<T> {
57 type Item = T;
58
59 fn bind(&mut self, cx: Scope<'a>, signal: &'a Signal<Self::Item>) {
60 cx.bind(self, signal);
61 }
62}
63
64impl<'a, T: Clone + PartialEq + SendSync + 'static> Bindable<'a> for SharedSignal<T> {
65 type Item = T;
66
67 fn bind(&mut self, cx: Scope<'a>, signal: &'a Signal<Self::Item>) {
68 let this = cx.alloc(self.clone());
69 cx.bind(this, signal);
70 }
71}
72
73pub trait Parent {
74 fn add_child(&mut self, child: impl View);
75}