import mutate from './mutate'

const game = () => {

  let state = {
    nowPlaying: 0,
    board: [],
    won: false
  }

  let subscribers = []
  const subscribe = (callback) => {
    subscribers.push({ callback })
  }

  const dispatch = (action) => {
    state = mutate(action, state)
    notify(action, state)
  }

  const notify = (action, state) => {
    _.each(subscribers, subscriber => {
      subscriber.callback(action, state)
    })
    return true
  }

  return {
    dispatch,
    subscribe
  }
}

export default game

import mutate from './mutate'

const game = () => {

  let state = {
    nowPlaying: 0,
    board: [],
    won: false
  }

  let subscribers = []
  const subscribe = (callback, actions = []) => {
    subscribers.push({
      callback,
      actions
    })
  }

  const dispatch = (action) => {
    state = mutate(action, state)
    notify(action, state)
  }

  const notify = (action, state) => {
    _.each(subscribers, subscriber => {
      if(!subscriber.actions.length || subscriber.actions.includes(action.type)){
        subscriber.callback(action, state)
      }
    })
    return true
  }

  return {
    dispatch,
    subscribe
  }
}

export default game

Revert "removed quasi-middleware-listeners filter something"
Revert "removed quasi-middleware-listeners filter something"

This reverts commit a9d4cef9d3c231fc05a0cb0fe8bf8873293891b3.
