jsem / mtg-life-counter

A personalised life counter for mtg
0 stars 0 forks source link

Implement game history #6

Open jsem opened 6 years ago

jsem commented 6 years ago

in the player reducer can we actually create notes from the reducer, given that they need to be created on the game reducer??

not sure if this actually works or is even recommended. please research

might just need to call addHistory from the game reducer in the component code before/after dispatching a playerReducer action, in which case we will handle the code for creating the history notes when we get around to creating the screens/components

jsem commented 6 years ago

this link seems to provide some relevant examples for this, including dispatching multiple actions with the same action creator etc (note i havent read the whole thing so i dont know how relevant it is) http://jamesknelson.com/can-i-dispatch-multiple-actions-from-redux-action-creators/

jsem commented 6 years ago

basic idea here is that you can just return an array of actions from each action creator, then when you dispatch, it will handle each action in the array.

i.e. dispatch(updateLife(playerId, amount)) will have the player reducer handle an UPDATE_LIFE action, and the gmae reducer handle an ADD_HISTORY action, because the updateLife action creator returns an array containing both actions.

this means that we can just update each action creator that creates an action that should add a history note to return an array containing both the intended action and an ADD_HISTORY action to add the history note