Expand description
Utilities for working with Perseus’ state platform.
Modules
This module contains implementations of common Rust collections that work
well with Perseus’ reactive state platform. So that this is as extensible as
possible, all the code in this module follows a general pattern, so that you
can easily create your own implementations as necessary!
Structs
The output of the build seed system, which should be generated by a user
function for each template.
A representation of a frozen app.
A representation of the global state in an app. This will be initialized as
a string of whatever was given by the server, until a page requests it and
deserializes it properly (since we can’t know the type until that happens).
A creator for global state. This stores user-provided functions that will be
invoked to generate global state on the client and the server.
A frozen state store that uses IndexedDB as a backend. This will only store
a single frozen state at a time, removing all previously stored states every
time a new one is set.
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, 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, though this
isn’t recommended.
An entry for a single page in the PSS. This type has no concern for the
actual type of the page state it stores.
A wrapper for fallible reactive state.
The intermediate reactive type for
RxResult
. You shouldn’t need to
interface with this manually.An analogue of
std::convert::Infallible
that can be serialized and
deserialized, since Serde currently does not implement those traits on the
standard library’s Infallible
. Until this issue is
resolved, this must be used instead in the state platform.The information any function that generates state will be provided.
A wrapper for template state stored as a
Value
. This loses the
underlying type information, but allows for serialization. This is a
necessary compromise, since, without types being first-class citizens in
Rust, full template type management appears presently impossible.The user’s preferences on state thawing.
A marker for when the type of template state is unknown.
Enums
The backend for the different types of global state.
The user’s preferences on page state thawing. Templates have three places
they can fetch state from: the page state store (called active state), the
frozen state, and the server. They’re typically prioritized in that order,
but if thawing occurs later in an app, it may be desirable to override
active state in favor of frozen state. These preferences allow setting an
inclusion or exclusion list.
The various things the PSS can contain for a single page. It might have
state, a head, both, or neither.
The page state of a PSS entry. This is used to determine whether or not we
need to request data from the server.
Traits
A convenience super-trait for
Freeze
able things that can be downcast to
concrete types.A trait for reactive
struct
s that can be made unreactive and serialized to
a String
. struct
s that implement this should implement MakeUnrx
for
simplicity, but they technically don’t have to (they always do in Perseus
macro-generated code).A trait for
struct
s that can be made reactive. Typically, this will be
derived with the #[make_rx]
macro, though it can be implemented manually
if you have more niche requirements.A trait for reactive
struct
s that can be made un-reactive. This is the
opposite of MakeRx
, and is intended particularly for state freezing. Like
MakeRx
, this will usually be derived automatically with the #[make_rx]
macro, but you can also implement it manually.A marker trait for types that you want to be able to use with the Perseus
state platform, without using
#[make_rx]
. If you want to use unreactive
state, implement this, and you’ll automatically be able to use your
unreactive type without problems!Functions
A utility function for calling suspense handlers and managing their errors.
This automatically implements the pattern of allowing suspense handlers to
return arbitrary errors that will be set, enabling the more convenient use
of
?
in those handlers.A utility function for calling suspense handlers and managing their errors.
This automatically implements the pattern of allowing suspense handlers to
return arbitrary errors that will be set, enabling the more convenient use
of
?
in those handlers.Type Definitions
A type alias for template state that has been converted into a
Value
without retaining the information of the original type, which is done
internally to eliminate the need for generics, which cannot be used
internally in Perseus for user state. The actual type is restored at the
last minute when it’s needed.