state-lens

0.2.0 • Public • Published

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
}

Readme

Keywords

none

Package Sidebar

Install

npm i state-lens

Weekly Downloads

1

Version

0.2.0

License

none

Last publish

Collaborators

  • ashaffer88