// Local variables

let subscribers = {}
let state = {}
let handlers

// Local methods

const init = (stateHandler, initialState = {}) => {
  handlers = stateHandler
  state = initialState
}

const subscribe = (actionType, cb) => {
  if (!(actionType in subscribers)) {
    subscribers[actionType] = []
  }
  subscribers[actionType].push(cb)
  return () => {
    subscribers = unsubscribe(subscribers, actionType, cb)
  }
}

const dispatch = (actionType, data) => {
  const timestamp = Date.now()
  state = handlers[actionType](state, data)

  if (!(actionType in subscribers)) return
  subscribers[actionType].forEach(cb => {
    cb({ type: actionType, timestamp, state, data })
  })
}

const getState = () => state

// Local methods

const unsubscribe = (subscribers, actionType, cb) => {
  if (!(actionType in subscribers)) return
  return subscribers[actionType].filter(sub => sub !== cb)
}

// Export

export {init, subscribe, dispatch, getState}

@@ -17,29 +17,8 @@
 es%0A%0A
-let subscribers = %7B%7D%0A
 let 
@@ -170,25 +170,24 @@
 %0A%0Aconst 
-subscribe
+dispatch
  = (acti
@@ -186,34 +186,36 @@
  = (actionType, 
-cb
+data
 ) =%3E %7B%0A  if (!(a
@@ -223,32 +223,29 @@
 tionType in 
-subscrib
+handl
 ers)) %7B%0A    
@@ -248,628 +248,201 @@
     
-subscribers%5BactionType%5D = %5B%5D%0A  %7D%0A  subscribers%5B
+throw new Error(%60Unknown 
 action
-Type%5D.push(cb)%0A  return () =%3E %7B%0A    subscribers = unsubscribe(subscribers, actionType, cb)%0A  %7D%0A%7D%0A%0Aconst dispatch = (actionType, data) =%3E %7B%0A  const timestamp = Date.now()%0A  state = handlers%5BactionType%5D(state, data)%0A%0A  if (!(actionType in subscribers)) return%0A  subscribers%5BactionType%5D.forEach(cb =%3E %7B%0A    cb(%7B type: actionType, timestamp, state, data %7D)%0A  %7D)%0A%7D%0A%0Aconst getState = () =%3E state%0A%0A// Local methods%0A%0Aconst unsubscribe = (subscribers, actionType, cb) =%3E %7B%0A  if (!(actionType in subscribers)) return%0A  return subscribers%5BactionType%5D.filter(sub =%3E sub !== cb)%0A%7D
+ type '$%7BactionType%7D' dispatched%60)%0A  %7D%0A%0A  let stateCopy = Object.assign(%7B%7D, state)%0A  state = handlers%5BactionType%5D(stateCopy, data)%0A%7D%0A%0Aconst getState = () =%3E state
 %0A%0A//
@@ -467,19 +467,8 @@
 nit,
- subscribe,
  dis

remove subscribe method, throw error when invoking unknown action type and always pass into action handler copy of the state