pub struct Turbine<M: MutableStore, T: TranslationsManager> {
pub static_dir: PathBuf,
pub static_aliases: HashMap<String, String>,
/* private fields */
}
Expand description
The Perseus state generator.
Fields§
§static_dir: PathBuf
This is stored as a PathBuf
so we can easily check whether or not it
exists.
static_aliases: HashMap<String, String>
The app’s static aliases.
Implementations§
source§impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
source§impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
source§impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
source§impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
sourcepub async fn get_state_for_path(
&self,
path: PathWithoutLocale,
locale: String,
entity_name: &str,
was_incremental: bool,
req: Request
) -> Result<PageDataPartial, ServerError>
pub async fn get_state_for_path( &self, path: PathWithoutLocale, locale: String, entity_name: &str, was_incremental: bool, req: Request ) -> Result<PageDataPartial, ServerError>
Gets the state for the given path. This will render the head, but it will not render the contents, and, as a result, will not engage with any dependencies this page/widget may have. If this is used to get the state of a capsule, the head will of course be empty.
This assumes the given locale is actually supported.
sourcepub async fn get_initial_load_for_path(
&self,
path: PathWithoutLocale,
translator: &Translator,
template: &Entity<SsrNode>,
was_incremental: bool,
req: Request
) -> Result<(PageData, TemplateState), ServerError>
pub async fn get_initial_load_for_path( &self, path: PathWithoutLocale, translator: &Translator, template: &Entity<SsrNode>, was_incremental: bool, req: Request ) -> Result<(PageData, TemplateState), ServerError>
Gets the full page data for the given path. This will generate the state, render the head, and render the content of the page, resolving all widget dependencies.
This takes a translator to allow the caller to derive it in a way that respects the likely need to know the translations string as well, for error page interpolation.
Like .get_state_for_path()
, this returns the page data and the global
state in a tuple.
Pitfalls
This currently uses a layer-based dependency resolution algorithm, as a widget may itself have widgets. However, the widgets a page/widget uses may be dependent on its state, and therefore we cannot enumerate the entire dependency tree without knowing all the states involved. Therefore, we go layer-by-layer. Currently, we wait for each layer to be fully complete before proceeding to the next one, which leads to a layer taking as long as the longest state generation within it. This can lead to poor render times when widgets are highly nested, a pattern that should be avoided as much as possible.
In future, this will build with maximal parallelism by not waiting for each layer to be finished building before proceeding to the next one.
source§impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
sourcepub async fn get_translations(&self, locale: &str) -> ApiResponse
pub async fn get_translations(&self, locale: &str) -> ApiResponse
The endpoint for getting translations.
Translations have the text/plain
MIME type, as they may be in an
entirely arbitrary format, which should be manually parsed.
sourcepub async fn get_subsequent_load(
&self,
raw_path: PathWithoutLocale,
locale: String,
entity_name: String,
was_incremental_match: bool,
req: Request
) -> ApiResponse
pub async fn get_subsequent_load( &self, raw_path: PathWithoutLocale, locale: String, entity_name: String, was_incremental_match: bool, req: Request ) -> ApiResponse
The endpoint for getting page/capsule data through the subsequent load system.
The path provided to this may have trailing slashes, these will be
handled. It is expected to end in .json
(needed for compatibility
with the exporting system).
Subsequent loads have the MIME type application/json
.
sourcepub async fn get_initial_load(
&self,
raw_path: PathMaybeWithLocale,
req: Request
) -> ApiResponse
pub async fn get_initial_load( &self, raw_path: PathMaybeWithLocale, req: Request ) -> ApiResponse
The endpoint for getting the full HTML contents of a page with no round trips (except for suspended states and/or delayed widgets). This is what should be returned to the user when they first ask for a page in the app.
This expects to take a raw path without the locale split out that still needs URL decoding.
If there’s an error anywhere in this function, it will return the HTML of a proper error page.
Initial loads always (even in the case of errors) have the MIME type
text/html
.
source§impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
sourcepub fn tinker(&self) -> Result<(), PluginError>
pub fn tinker(&self) -> Result<(), PluginError>
Runs tinker plugin actions.
source§impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>
sourcepub async fn populate_after_build(&mut self) -> Result<(), ServerError>
pub async fn populate_after_build(&mut self) -> Result<(), ServerError>
Updates some internal fields of the turbine by assuming the app has been
built in the past. This expects a number of things to exist in the
filesystem. Note that calling .build()
will automatically perform
this population.