1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use std::any::Any;
use super::super::{Instance, Props};
use super::{Children, View};
pub trait Component: 'static + Any {
fn render(&self, instance: &Instance, props: &Props, children: &Children) -> View;
#[inline(always)]
fn name(&self) -> &'static str {
"Unknown"
}
#[inline]
fn initial_state(&self, _props: &Props) -> Props {
Props::new()
}
#[inline]
fn context(&self, _props: &Props) -> Props {
Props::new()
}
#[inline]
fn inherit_context(&self, context: Props, _parent_context: &Props) -> Props {
context
}
#[inline(always)]
fn will_mount(&self, _instance: &Instance) {}
#[inline(always)]
fn will_unmount(&self, _instance: &Instance) {}
#[inline(always)]
fn will_update(&self, _instance: &Instance) {}
#[inline(always)]
fn receive_props(
&self,
_instance: &Instance,
_next_state: &Props,
_next_props: &Props,
_next_children: &Children,
) {
}
#[inline]
fn should_update(
&self,
_prev_state: &Props,
_prev_props: &Props,
_prev_children: &Children,
_next_state: &Props,
_next_props: &Props,
_next_children: &Children,
) -> bool {
true
}
}
impl PartialEq for Component {
#[inline]
fn eq(&self, other: &Component) -> bool {
self.get_type_id() == other.get_type_id()
}
}