refactor: create TuonoContext (#413)

This commit is contained in:
Marco Pasqualetti
2025-01-25 15:56:10 +01:00
committed by GitHub
parent d5cc65983e
commit dcedb1c6c0
26 changed files with 253 additions and 110 deletions
+8 -8
View File
@@ -16,8 +16,8 @@ fn has_dynamic_path(route: &str) -> bool {
#[derive(SerdeSerialize)]
/// This is the payload sent to the client for hydration
pub struct Payload<'a> {
router: Location,
props: &'a dyn Serialize,
location: Location,
data: &'a dyn Serialize,
mode: Mode,
#[serde(rename(serialize = "jsBundles"))]
js_bundles: Option<Vec<&'a String>>,
@@ -28,7 +28,7 @@ pub struct Payload<'a> {
}
impl<'a> Payload<'a> {
pub fn new(req: &'a Request, props: &'a dyn Serialize) -> Payload<'a> {
pub fn new(req: &'a Request, data: &'a dyn Serialize) -> Payload<'a> {
let config = GLOBAL_CONFIG
.get()
.expect("Failed to load the current config");
@@ -42,8 +42,8 @@ impl<'a> Payload<'a> {
};
Payload {
router: req.location(),
props,
location: req.location(),
data,
mode,
js_bundles: None,
css_bundles: None,
@@ -79,7 +79,7 @@ impl<'a> Payload<'a> {
let mut js_bundles_sources = vec![&main_bundle.file];
let mut css_bundles_sources = main_bundle.css.iter().collect::<Vec<&String>>();
let pathname = &self.router.pathname();
let pathname = &self.location.pathname();
let bundle_data = manifest.get(*pathname);
@@ -233,8 +233,8 @@ mod tests {
let location = Location::from(uri);
Payload {
router: location,
props: &None::<Option<()>>,
location,
data: &None::<Option<()>>,
mode,
js_bundles: None,
css_bundles: None,