0.2.0 • Published 8 years ago

state-lens v0.2.0

Weekly downloads
6
License
-
Repository
github
Last release
8 years ago

state-lens

js-standard-style

State cursor/lens thing

Installation

$ npm install state-lens

Usage

Just an experiment right now to create a minimal state lens/cursor thing to use for local state in deku.

Deku component wrapper

function localize (component) {
  if ('function' === typeof component) {
    component = {render: component}
  }

  const {onCreate = () => {}, onRemove = () => {}, initialState = () => ({})} = component

  component.onCreate = (model) => {
    model.dispatch(model.props.state.create(initialState(model)))
    return onCreate(model)
  }

  component.onRemove = (model) => {
    model.dispatch(model.props.state.destroy())
    return onRemove(model)
  }

  return component
}