stora

0.1.1 • Public • Published

stora

A stand-alone model-update library.

Build Status npm version dependencies

npm install stora

Component

A component is a piece of state that represents a model.

const todos = {
  state,
  update
}

State

A function that returns a value.

const state = () => ({
  list: [],
  text: ''
})

Update

An object that contains functions to apply over your state.

const update = {
  add: item => state => ({ list: state.list.concat(item) }),
  input: text => state => ({ text: state.text.concat(text) }),
  reset: text => state => ({ text: text })
}

Store

A store contains components.

const store = require('stora')
 
const app = store({
  todos
})

State

Returns a value from a component's state.

app.state('todos/list')
//=> []

Update

Calls an update from a component, with a payload.

app.update('todos/add', 'hello')
//=> { list: [ 'hello' ], text: '' }
 
app.state('todos/list')
//=> [ 'hello' ]

Subscribe

Every time an update occurs, the function passed to subscribe will be called.

app.subscribe(console.log)
app.update('todos/add', 'again')
//=> { type: 'todos/add', payload: 'again' } { list: [ 'hello' ], text: '' } { list: [ 'hello', 'again' ] }

Readme

Keywords

none

Package Sidebar

Install

npm i stora

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

5.6 kB

Total Files

6

Last publish

Collaborators

  • brandonchartier