Module

Elmish.State

#StateStrategy

type StateStrategy state = { initialState :: state } -> { getState :: ReactComponentInstance -> Effect state, setState :: ReactComponentInstance -> state -> Effect Unit -> Effect Unit }

This type represents a strategy of storing UI component state. The strategy is a function that takes initial state and returns a monadic equivalent of lens for manipulating the state.

Currently there are two strategies:

  • dedicatedStorage stores state in a dedicated mutable cell. This strategy is used in Elmish.Component.construct.
  • localState stores state locally on the React component instance - i.e. this.setState. This strategy is used in Elmish.Component.wrapWithLocalState.

The former strategy is more reliable, since React is very lax with this.state and this.setState (for example, updates are "eventual", with no time guarantees). However, the former strategy is not pure (requires allocating the storage cell), and thus doesn't work with inline embedding of components.

#dedicatedStorage

dedicatedStorage :: forall state. Effect (StateStrategy state)

Stores state in a dedicated mutable state. See comment on StateStrategy for explanation.

#localState

localState :: forall state. StateStrategy state

Stores state on the React component instance - i.e. this.setState. See comment on StateStrategy.

Modules