@@ -10,49 +10,60 @@ use crate::{
10
10
pub trait Initializer < Ms : Clone + ' static , Mdl , ElC : View < Ms > , GMs > {
11
11
fn into_init (
12
12
self ,
13
- routing_method : routing:: Url ,
13
+ url : routing:: Url ,
14
14
orders : & mut OrdersContainer < Ms , Mdl , ElC , GMs > ,
15
15
) -> Init < Mdl > ;
16
16
}
17
17
impl < Ms : Clone + ' static , Mdl , ElC : View < Ms > , GMs , F > Initializer < Ms , Mdl , ElC , GMs > for F
18
18
where
19
- F : FnOnce ( routing:: Url , & mut OrdersContainer < Ms , Mdl , ElC , GMs > ) -> Init < Mdl > ,
19
+ F : for < ' r , ' a > FnOnce ( routing:: Url , & ' a mut OrdersContainer < Ms , Mdl , ElC , GMs > ) -> Init < Mdl > ,
20
20
{
21
21
fn into_init (
22
22
self ,
23
- routing_method : routing:: Url ,
23
+ url : routing:: Url ,
24
24
orders : & mut OrdersContainer < Ms , Mdl , ElC , GMs > ,
25
25
) -> Init < Mdl > {
26
- self ( routing_method , orders)
26
+ self ( url , orders)
27
27
}
28
28
}
29
29
30
30
/// Used for handling initial routing.
31
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
31
32
pub enum UrlHandling {
32
33
PassToRoutes ,
33
34
None ,
34
35
// todo: Expand later, as-required
35
36
}
36
37
38
+ /// Used for determining behavior at startup.
39
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
40
+ pub enum BootstrapBehavior {
41
+ Takeover ,
42
+ Append ,
43
+ }
44
+
37
45
/// Used as a flexible wrapper for the init function.
38
46
pub struct Init < Mdl > {
39
47
// init: InitFn<Ms, Mdl, ElC, GMs>,
40
- model : Mdl ,
41
- url_handling : UrlHandling ,
48
+ pub model : Mdl ,
49
+ pub url_handling : UrlHandling ,
50
+ pub bootstrap_behavior : BootstrapBehavior ,
42
51
}
43
52
44
53
impl < Mdl > Init < Mdl > {
45
54
pub const fn new ( model : Mdl ) -> Self {
46
55
Self {
47
56
model,
48
57
url_handling : UrlHandling :: PassToRoutes ,
58
+ bootstrap_behavior : BootstrapBehavior :: Append ,
49
59
}
50
60
}
51
61
52
62
pub const fn new_with_url_handling ( model : Mdl , url_handling : UrlHandling ) -> Self {
53
63
Self {
54
64
model,
55
65
url_handling,
66
+ bootstrap_behavior : BootstrapBehavior :: Append ,
56
67
}
57
68
}
58
69
}
@@ -104,22 +115,24 @@ pub struct Builder<
104
115
sink : Option < SinkFn < Ms , Mdl , ElC , GMs > > ,
105
116
view : ViewFn < Mdl , ElC > ,
106
117
mount_point : Option < Element > ,
107
- takeover_mount : bool ,
108
118
routes : Option < RoutesFn < Ms > > ,
109
119
window_events : Option < WindowEvents < Ms , Mdl > > ,
110
120
}
111
121
112
122
impl < Ms : Clone , Mdl , ElC : View < Ms > + ' static , GMs : ' static , I : Initializer < Ms , Mdl , ElC , GMs > >
113
123
Builder < Ms , Mdl , ElC , GMs , I >
114
124
{
115
- pub fn new ( init : I , update : UpdateFn < Ms , Mdl , ElC , GMs > , view : ViewFn < Mdl , ElC > ) -> Self {
125
+ pub ( super ) fn new (
126
+ init : I ,
127
+ update : UpdateFn < Ms , Mdl , ElC , GMs > ,
128
+ view : ViewFn < Mdl , ElC > ,
129
+ ) -> Self {
116
130
Self {
117
131
init,
118
132
update,
119
133
view,
120
134
sink : None ,
121
135
mount_point : None ,
122
- takeover_mount : false ,
123
136
routes : None ,
124
137
window_events : None ,
125
138
}
@@ -153,18 +166,6 @@ impl<Ms: Clone, Mdl, ElC: View<Ms> + 'static, GMs: 'static, I: Initializer<Ms, M
153
166
self
154
167
}
155
168
156
- /// Allows for the [`App`] to takeover all the children of the mount point. The default
157
- /// behavior is that the [`App`] ignores the children and leaves them in place. The new
158
- /// behavior can be useful if SSR is implemented.
159
- ///
160
- /// As of right now, nodes found in the root will be destroyed and recreated once. This can
161
- /// cause duplicated scripts, css, and other tags that should not otherwise be duplicated.
162
- /// Unrecognized tags are also converted into spans, so take note.
163
- pub fn takeover_mount ( mut self , should_takeover : bool ) -> Self {
164
- self . takeover_mount = should_takeover;
165
- self
166
- }
167
-
168
169
/// Registers a function which maps URLs to messages.
169
170
pub fn routes ( mut self , routes : RoutesFn < Ms > ) -> Self {
170
171
self . routes = Some ( routes) ;
@@ -201,7 +202,6 @@ impl<Ms: Clone, Mdl, ElC: View<Ms> + 'static, GMs: 'static, I: Initializer<Ms, M
201
202
self . sink ,
202
203
self . view ,
203
204
self . mount_point . unwrap ( ) ,
204
- self . takeover_mount ,
205
205
self . routes ,
206
206
self . window_events ,
207
207
) ;
@@ -222,6 +222,9 @@ impl<Ms: Clone, Mdl, ElC: View<Ms> + 'static, GMs: 'static, I: Initializer<Ms, M
222
222
} ;
223
223
224
224
app. cfg . initial_orders . replace ( Some ( initial_orders) ) ;
225
+ app. cfg
226
+ . bootstrap_behavior
227
+ . replace ( Some ( init. bootstrap_behavior ) ) ;
225
228
app. data . model . replace ( Some ( init. model ) ) ;
226
229
227
230
app
0 commit comments