yoshuawuyts / barracks

:mountain_railway: action dispatcher for unidirectional data flows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

voronianski opened this issue · comments

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?

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

@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.

commented

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

commented

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