Stores the environment properties that the Angular application needs.
EnvironmentStore is a singleton service responsible for maintaining a reference to all the technical or functional properties that the application needs. It is the most important service of the library and must be implemented to manage the environment state.
Can be integrated into any application using the provided default implementation or creating a custom one to integrate it with any state manager already used by the application.
Below are examples of the expected behavior and some implementation examples. To learn more about environment store and how to create them you can read the documentation.
Angular Environment Store
EnvironmentStore is a singleton service responsible for maintaining a reference to all the technical or functional properties that the application needs. It is the most important service of the library and must be implemented to manage the environment state.
Can be integrated into any application using the provided default implementation or creating a custom one to integrate it with any state manager already used by the application.
DefaultEnvironmentStore
A simple implementation of the
EnvironmentStore
that uses a BehaviorSubject as state manager.This store is provided by defaut when running
EnvironmentModule.forRoot()
, but can be provided manually.Unless
ENVIRONMENT_INITIAL_STATE
is provided, the initial state of the store is{}
.ENVIRONMENT_INITIAL_STATE
The
ENVIRONMENT_INITIAL_STATE
injection token is used to set the initial store value toDefaultEnvironmentStore
.The default value provided by
EnvironmentModule.forRoot()
is{}
, but can be set in configuration.Use cases
Below are examples of the expected behavior and some implementation examples. To learn more about environment store and how to create them you can read the documentation.
Table of Contents
Create a custom store
To create a custom environment store that uses
ENVIRONMENT_INITIAL_STATE
simply complete the next class.Once implemented must be provided:
EnvironmentModule.forRoot()
.Provide the initial state from local storage
The
ENVIRONMENT_INITIAL_STATE
injection token can be used to load the initial state from the local storage, or any other local persistence layer.