'use strict'

var assign = require('object-assign')
var EventEmitter = require('eventemitter3')
var objEql = require('obj-eql')

function createStore(obj) {
  var store = assign(Object.create(EventEmitter.prototype), {
    state: {},
    setState: function(change) {
      var newState = Object.freeze(assign({}, this.state, change))
      updateState(this, newState)
    },
    replaceState: function(newState) {
      newState = Object.freeze(assign({}, newState))
      updateState(this, newState)
    }
  }, obj)
  Object.freeze(store.state)
  return store
}

function updateState(store, newState) {
  if (!objEql(newState, store.state)) {
    store.state = newState
    store.emit('change')
  }
}

module.exports = createStore

@@ -270,35 +270,24 @@
     
-var newState = Object.freez
+this.replaceStat
 e(as
@@ -320,36 +320,46 @@
 e))%0A    
-  updateState(this, 
+%7D,%0A    replaceState: function(
 newState
@@ -363,52 +363,51 @@
 ate)
+ %7B
 %0A    
-%7D,%0A    replaceState: function(newS
+  if (!objEql(newState, this.s
 tate)
+)
  %7B%0A 
@@ -411,20 +411,24 @@
 %7B%0A      
+ 
-newS
+ this.s
 tate = O
@@ -440,27 +440,16 @@
 .freeze(
-assign(%7B%7D, 
 newState
@@ -453,43 +453,44 @@
 ate)
-)
 %0A
+ 
       
-updateState(this, newState)
+ this.emit('change')%0A      %7D
 %0A   
@@ -553,147 +553,8 @@
 %0A%7D%0A%0A
-function updateState(store, newState) %7B%0A  if (!objEql(newState, store.state)) %7B%0A    store.state = newState%0A    store.emit('change')%0A  %7D%0A%7D%0A%0A
 modu

Refactor replaceState to handle all state updates