Module

Elmish.State

Package
purescript-elmish
Repository
collegevine/purescript-elmish

#StateStrategy Source

type StateStrategy state = { initialState :: state } -> { getState :: ReactComponentInstance -> Effect state, initialize :: ReactComponentInstance -> Effect Unit, 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 Source

dedicatedStorage :: forall state. Effect (StateStrategy state)

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

#localState Source

localState :: forall state. StateStrategy state

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