yoshuawuyts / barracks

:mountain_railway: action dispatcher for unidirectional data flows
MIT License
177 stars 22 forks source link

Add wrapers quick example #68

Closed YerkoPalma closed 8 years ago

YerkoPalma commented 8 years ago

In the readme there is this quick example

const barracks = require('barracks')

const store = barracks()

store.use({
  onError: (err, state, createSend) => {
    console.error(`error: ${err}`)
  },
  onAction: (data, state, name, caller, createSend) => {
    console.log(`data: ${data}`)
  },
  onStateChange: (data, state, prev, caller, createSend) => {
    console.log(`state: ${prev} -> ${state}`)
  }
})

store.model({
  namespace: 'cakes',
  state: {},
  effects: {},
  reducers: {},
  subscriptions: {}
})

const createSend = store.start({ noSubscriptions: true })
const send = createSend('myDispatcher', true)
document.addEventListener('DOMContentLoaded', () => {
  store.start() // fire up subscriptions
  const state = store.state()
  send('foo:start', { name: 'Loki' })
})

In the use call there is no example for the wrapers, and I'm not sure how they should be used. it only says that they receive a function, but what is the signature of those functions? what do they return? should the app.use() look like this?

store.use({
  wrapSubscriptions: (fn) => {
    return fn()
  }
})

I'm not quite sure on that, so please add an example for the wrapers.

yoshuawuyts commented 8 years ago

Added an example in 2221c54, lmk if that's helpful (:

YerkoPalma commented 8 years ago

Looks good to me. Thanks for the quick response :)