yoshuawuyts / barracks

:mountain_railway: action dispatcher for unidirectional data flows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add wrapers quick example

YerkoPalma opened this issue · comments

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.

commented

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

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