Struct perseus::state::GlobalStateCreator
source · pub struct GlobalStateCreator { /* private fields */ }
Expand description
A creator for global state. This stores user-provided functions that will be invoked to generate global state on the client and the server.
The primary purpose of this is to allow the generation of top-level app state on the server and the client. Notably, this can also be interacted with by plugins.
Implementations§
source§impl GlobalStateCreator
impl GlobalStateCreator
sourcepub fn build_state_fn<S, V>(
self,
val: impl GlobalStateBuildUserFnType<S, V> + Clone + Send + Sync + 'static
) -> Selfwhere
S: Serialize + DeserializeOwned + MakeRx,
V: Into<GeneratorResult<S>>,
pub fn build_state_fn<S, V>( self, val: impl GlobalStateBuildUserFnType<S, V> + Clone + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx, V: Into<GeneratorResult<S>>,
Adds a function to generate global state at build-time.
sourcepub fn build_state_fn(self, _val: impl Fn() + 'static) -> Self
pub fn build_state_fn(self, _val: impl Fn() + 'static) -> Self
Adds a function to generate global state at build-time.
sourcepub fn request_state_fn<S, V>(
self,
val: impl GlobalStateRequestUserFnType<S, V> + Clone + Send + Sync + 'static
) -> Selfwhere
S: Serialize + DeserializeOwned + MakeRx,
V: Into<BlamedGeneratorResult<S>>,
pub fn request_state_fn<S, V>( self, val: impl GlobalStateRequestUserFnType<S, V> + Clone + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx, V: Into<BlamedGeneratorResult<S>>,
Adds a function to generate global state at request-time.
sourcepub fn request_state_fn(self, _val: impl Fn() + 'static) -> Self
pub fn request_state_fn(self, _val: impl Fn() + 'static) -> Self
Adds a function to generate global state at request-time.
sourcepub fn amalgamate_states_fn<S, V>(
self,
val: impl GlobalStateAmalgamationUserFnType<S, V> + Clone + Send + Sync + 'static
) -> Selfwhere
S: Serialize + DeserializeOwned + MakeRx + Send + Sync + 'static,
V: Into<BlamedGeneratorResult<S>>,
pub fn amalgamate_states_fn<S, V>( self, val: impl GlobalStateAmalgamationUserFnType<S, V> + Clone + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx + Send + Sync + 'static, V: Into<BlamedGeneratorResult<S>>,
Adds a function to amalgamate build-time and request-time global state.
sourcepub fn amalgamate_states_fn(self, _val: impl Fn() + 'static) -> Self
pub fn amalgamate_states_fn(self, _val: impl Fn() + 'static) -> Self
Adds a function to amalgamate build-time and request-time global state.
sourcepub async fn get_build_state(&self) -> Result<TemplateState, ServerError>
pub async fn get_build_state(&self) -> Result<TemplateState, ServerError>
Gets the global state at build-time.
sourcepub async fn get_request_state(
&self,
req: Request
) -> Result<TemplateState, ServerError>
pub async fn get_request_state( &self, req: Request ) -> Result<TemplateState, ServerError>
Gets the global state at request-time.
sourcepub async fn amalgamate_states(
&self,
build_state: TemplateState,
request_state: TemplateState
) -> Result<TemplateState, ServerError>
pub async fn amalgamate_states( &self, build_state: TemplateState, request_state: TemplateState ) -> Result<TemplateState, ServerError>
Amalgamates global state that was generated at build-time with that generated at request-time, according to custom user-provided logic.
sourcepub fn uses_request_state(&self) -> bool
pub fn uses_request_state(&self) -> bool
Checks if this state needs to do anything on requests for it.
sourcepub fn uses_build_state(&self) -> bool
pub fn uses_build_state(&self) -> bool
Checks if this state needs to do anything at build time.
sourcepub fn can_amalgamate_states(&self) -> bool
pub fn can_amalgamate_states(&self) -> bool
Checks if this state has custom logic to amalgamate build and request states if both are generated.