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
76
use std::rc::Rc;
pub struct Cmd<DSP> {
pub commands: Vec<Rc<dyn Fn(DSP)>>,
pub should_update_view: bool,
}
impl<DSP> Cmd<DSP>
where
DSP: Clone + 'static,
{
pub fn new<F>(f: F) -> Self
where
F: Fn(DSP) + 'static,
{
Self {
commands: vec![Rc::new(f)],
should_update_view: true,
}
}
pub fn batch(cmds: Vec<Self>) -> Self {
let mut commands = vec![];
for cmd in cmds {
commands.extend(cmd.commands);
}
Self {
commands,
should_update_view: true,
}
}
pub fn none() -> Self {
Cmd {
commands: vec![],
should_update_view: true,
}
}
pub fn emit(self, program: &DSP) {
for cb in self.commands {
let program_clone = program.clone();
cb(program_clone);
}
}
pub fn should_update_view(should_update_view: bool) -> Self {
Self {
commands: vec![],
should_update_view,
}
}
pub fn no_render() -> Self {
Self::should_update_view(false)
}
}