lib/rydux/store.rb in rydux-0.9.0 vs lib/rydux/store.rb in rydux-0.9.1

- old
+ new

@@ -30,36 +30,38 @@ def dispatch(action) @reducers.each do |k, reducer| new_state = {} new_state[k] = reducer.map_state(action, state[k]) - set_state(new_state) + set_state(new_state, action[:type]) end end def state State.new(@state) end private - def set_state(new_state) + def set_state(new_state, last_dispatch = nil) new_state.each do |k, v| @state[k] = v if !self.methods.include? k self.define_singleton_method(k.to_sym) do return State.new(state[k]) end end - notify_listeners + notify_listeners(last_dispatch) end end - def notify_listeners + def notify_listeners(last_dispatch) @listeners.each do |listener| - listener.public_send(:state_changed, state) + if listener.respond_to? :state_changed + listener.public_send(:state_changed, state, last_dispatch) + end end end end end