Dispatching Actions
Before actually dispatch and apply withdraw or deposit actions, let's take a look at how we can see the current state of our application and it's values.
This can be done by using the getState() function that is provided from our store. This has access to the state that is returned lately by the reducer function of this store.
If you console.log(store.getState()) at the bottom of your script you will probably be able to see an object with a property of currentBalance set to 0 like that:
{currentBalance: 0}
Then after that line, we will actually call the action functions we created. Now normally this is not something that in a real case scenario you would like to do it manually, but you will want to associate it with an event (like a mouse click, a hover, a scroll event etc). But for now we will just do it manually by calling the action.
How? Just by wrapping the action's function name inside the store's dispatch method as shown above. The dispatch method connects the action function that is passed as an argument with the store and it's reducer. Then the type of the action is passed (alongside with the amount of money in this case) and the reducer finds the corresponding code inside it's own switch-case to execute the corresponding code.
Now after every dispatch, if you console.log and get the current state you can see the values of the state and of the currentBalance change accordingly!
You made it!