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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use StatusCode;
use AppError;
use Session;
use View;
use DeserializeOwned;
use Serialize;
use HashMap;
use Future;
/// A server-state-backed reactive component - Larust's Livewire-equivalent.
/// Unlike Livewire, `Self`'s state never crosses the wire: it lives
/// server-side, keyed by the user's session (see `larust-live::state`), and
/// only an opaque component id is ever sent to/from the browser.
///
/// Implementors are typically small `#[derive(Serialize, Deserialize)]`
/// structs holding just the fields a `wire:model`/`wire:model.live` field
/// binds to, plus whatever else `render` needs to recompute its output.
/// Prefer a struct with named fields - even a `wire:click`-only component
/// with no `wire:model` bindings at all - over a fieldless unit struct
/// (`struct Foo;`, which `serde_json` serializes as `Value::Null` rather
/// than a JSON object): a client sending a non-empty `props` object for
/// such a component (a bug, or a crafted request) is rejected with a
/// clean 422, whereas an entirely-empty prop sync (the normal case for a
/// `wire:click`-only component) works either way.
///
/// `mount`/`render`/`call` are `async` (spelled as `-> impl Future<..> +
/// Send` rather than `async fn`, so the `+ Send` bound is explicit rather
/// than relying on an external `#[trait_variant]`-style macro) because a
/// real component routinely needs to do real async work - querying the
/// database in `render` (a search box), or persisting a change to it from
/// an action `wire:click` dispatches to in `call`. A sync-only trait would
/// make that impossible to express here at all.