0.1.1 • Published 8 years ago
stora v0.1.1
stora
A stand-alone model-update library.
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' ] }0.1.1
8 years ago