-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📝 Transfer preload data to render via context.
- Loading branch information
Showing
8 changed files
with
94 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod app; | ||
pub mod pages; | ||
pub mod preload_data; | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
mod web_entry; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use yew::prelude::*; | ||
|
||
use crate::app::PageData; | ||
|
||
#[derive(Debug, PartialEq, Clone)] | ||
pub struct PreloadData { | ||
pub preload: PageData, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Clone)] | ||
pub enum PreloadDataAction {} | ||
|
||
impl Reducible for PreloadData { | ||
type Action = PreloadDataAction; | ||
|
||
fn reduce(self: std::rc::Rc<Self>, _action: Self::Action) -> std::rc::Rc<Self> { | ||
self | ||
} | ||
} | ||
|
||
pub type PreloadDataContext = UseReducerHandle<PreloadData>; | ||
|
||
#[derive(Properties, Debug, PartialEq)] | ||
pub struct ProviderProps { | ||
pub preload_data: PageData, | ||
|
||
#[prop_or_default] | ||
pub children: Html, | ||
} | ||
|
||
#[function_component] | ||
pub fn Provider(props: &ProviderProps) -> Html { | ||
let state = use_reducer(|| PreloadData { | ||
preload: props.preload_data.clone(), | ||
}); | ||
|
||
html! { | ||
<ContextProvider<PreloadDataContext> context={state}> | ||
{props.children.clone()} | ||
</ContextProvider<PreloadDataContext>> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters