android-components / mozilla.components.lib.state / Store

Store

open class Store<S : State, A : Action> (source)

A generic store holding an immutable State.

The State can only be modified by dispatching Actions which will create a new state and notify all registered Observers.

Parameters

initialState - The initial state until a dispatched Action creates a new state.

reducer - A function that gets the current State and Action passed in and will return a new State.

Types

Name Summary
Subscription class Subscription<S : State, A : Action>
A Subscription is returned whenever an observer is registered via the observeManually method. Calling unsubscribe on the Subscription will unregister the observer.

Constructors

Name Summary
<init> Store(initialState: S, reducer: Reducer<S, A>)
A generic store holding an immutable State.

Properties

Name Summary
state val state: S
The current State.

Functions

Name Summary
dispatch fun dispatch(action: A): Job
Dispatch an Action to the store in order to trigger a State change.
observeManually fun observeManually(observer: Observer<S>): Subscription<S, A>
Registers an Observer function that will be invoked whenever the State changes.

Extension Functions

Name Summary
channel fun <S : State, A : Action> Store<S, A>.channel(owner: LifecycleOwner = ProcessLifecycleOwner.get()): ReceiveChannel<S>
Creates a conflated Channel for observing State changes in the Store.
observe fun <S : State, A : Action> Store<S, A>.observe(owner: LifecycleOwner, observer: Observer<S>): Unit
Registers an Observer function that will be invoked whenever the state changes. The Store.Subscription will be bound to the passed in LifecycleOwner. Once the Lifecycle state changes to DESTROYED the Observer will be unregistered automatically.fun <S : State, A : Action> Store<S, A>.observe(view: <ERROR CLASS>, observer: Observer<S>): Unit
Registers an Observer function that will be invoked whenever the state changes. The Store.Subscription will be bound to the passed in View. Once the View gets detached the Observer will be unregistered automatically.
observeForever fun <S : State, A : Action> Store<S, A>.observeForever(observer: Observer<S>): Unit
Registers an Observer function that will observe the store indefinitely.

Inheritors

Name Summary
BrowserStore class BrowserStore : Store<BrowserState, BrowserAction>
The BrowserStore holds the BrowserState (state tree).