yoshuawuyts / barracks

:mountain_railway: action dispatcher for unidirectional data flows
MIT License
177 stars 22 forks source link

Is it ok that `prev` and `state` in onStateChange handler return same values? #77

Open voronianski opened 7 years ago

voronianski commented 7 years ago

Please take a look at my example (pls open console to see logs).

On every 'counter:increment' action onStateChange handler logs the same values for state.counter.count in state and prev objects:

image

Is it intended?

voronianski commented 7 years ago

Also I'm a bit confused that inside choo.js onStateChange function has different signature - https://github.com/yoshuawuyts/choo/blob/master/index.js#L89

voronianski commented 7 years ago

@yoshuawuyts I really like the concepts and minimal API of the library and would like to use it inside of my project but this issue stops me for now.

yoshuawuyts commented 7 years ago

currently thinking of actually ditching the prev argument because it causes a fair amount of complexity in the API - wouldn't rely on it tbh

yoshuawuyts commented 7 years ago

Instead you can hold your own reference to the prev instance of state, for example inside a closure (: