choojs / choo-store

Lightweight state structure for choo apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

idea: export actions

ungoldman opened this issue · comments

Given

module.exports = createStore({
  storeName: 'clicks',
  initialState: { count: 0 },
  events: {
    increment: ({ store, emitter }) => {
      store.count++
      emitter.emit('render')
    }
  }
})

I could bind actions to the emitter and make those available for use elsewhere as store.actions[eventName]. So once the store is registered with the app, you could do...

var { actions } = require('./stores/clicks')

module.exports = state => html`
  <body>
    <h1>count is ${state.clicks.count}</h1>
    <button onclick=${() => actions.increment(1)}>Increment</button>
    <button onclick=${() => actions.reset({ render: true })}>Reset</button>
  </body>
`

Notice there is no longer any need for emit in a component!