You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/perseus/src/page_state_store.rs
+6-6
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@ use std::cell::RefCell;
2
2
use std::collections::HashMap;
3
3
use std::rc::Rc;
4
4
5
-
usecrate::{rx_state::Freeze,state::AnyFreeze};
5
+
usecrate::state::AnyFreeze;
6
6
7
7
/// A container for page state in Perseus. This is designed as a context store, in which one of each type can be stored. Therefore, it acts very similarly to Sycamore's context system,
8
8
/// though it's specifically designed for each page to store one reactive properties object. In theory, you could interact with this entirely independently of Perseus' state interface,
@@ -36,18 +36,18 @@ impl PageStateStore {
36
36
self.map.borrow().contains_key(url)
37
37
}
38
38
}
39
-
// Good for convenience, and there's no reason we can't do this
40
-
implFreezeforPageStateStore{
39
+
implPageStateStore{
40
+
/// Freezes the component entries into a new `HashMap` of `String`s to avoid extra layers of deserialization.
41
41
// TODO Avoid literally cloning all the page states here if possible
Copy file name to clipboardExpand all lines: packages/perseus/src/template.rs
+15-6
Original file line number
Diff line number
Diff line change
@@ -41,8 +41,8 @@ pub struct FrozenApp {
41
41
pubglobal_state:String,
42
42
/// The frozen route.
43
43
pubroute:String,
44
-
/// The frozen page state store.
45
-
pubpage_state_store:String,
44
+
/// The frozen page state store. We store this as a `HashMap` as this level so that we can avoid another deserialization.
45
+
pubpage_state_store:HashMap<String,String>,
46
46
}
47
47
48
48
/// This encapsulates all elements of context currently provided to Perseus templates. While this can be used manually, there are macros
@@ -67,6 +67,8 @@ pub struct RenderCtx {
67
67
/// Because we store `dyn Any` in here, we initialize it as `Option::None`, and then the template macro (which does the heavy lifting for global state) will find that it can't downcast
68
68
/// to the user's global state type, which will prompt it to deserialize whatever global state it was given and then write that here.
69
69
pubglobal_state:Rc<RefCell<Box<dynAnyFreeze>>>,
70
+
/// A previous state the app was once in, still serialized. This will be rehydrated graudally by the template macro.
71
+
pubfrozen_app:Option<Rc<FrozenApp>>,
70
72
}
71
73
implFreezeforRenderCtx{
72
74
/// 'Freezes' the relevant parts of the render configuration to a serialized `String` that can later be used to re-initialize the app to the same state at the time of freezing.
/// Executes the user-given function that renders the template on the client-side ONLY. This takes in an extsing global state.
293
+
#[allow(clippy::too_many_arguments)]
291
294
pubfnrender_for_template_client(
292
295
&self,
293
296
props:PageProps,
@@ -296,6 +299,7 @@ impl<G: Html> Template<G> {
296
299
router_state:RouterState,
297
300
page_state_store:PageStateStore,
298
301
global_state:Rc<RefCell<Box<dynAnyFreeze>>>,
302
+
frozen_app:Option<Rc<FrozenApp>>,
299
303
) -> View<G>{
300
304
view!{
301
305
// We provide the translator through context, which avoids having to define a separate variable for every translation due to Sycamore's `template!` macro taking ownership with `move` closures
0 commit comments