TransferStateService

Overview

The TransferStateService allows the transfer of an Angular application's state into the static site rendered by Scully.

This allows Scully to use cached data instead of using the original data source (which is most likely an external API).

More over, it allows you to load the state on subsequent route changes after the initial page has been loaded.

A route change fetches the next route's state from the page on the serve, and it is returned to the client. Hence, having a state consumed as part of the build despite any CMS content in production

Usage

useScullyTransferState()

Use this method to have your existing observable data sources automatically included in Scully's TransferState. During development, your observables will behave as usual.

When the static site is served, Scully will use the cached state instead of accessing the original observable data source.

useScullyTransferState<T>(name: string, originalState: Observable<T>): Observable<T>

getState()

This method returns an observable that fires once and then completes. It does executes after the page's navigation has finished.

getState<T>(name: string): Observable<T>

setState()

This method sets values to the property key.

setState<T>(name: string, val: T): void;