It’s a function that returns a function; when you call it it dispatches an action then it waits for a response and dispatched a second action. It’s effectively an action creator that can create more actions, but those actions maybe dont execute straightaway (subroutines). It’s not in the code anywhere else because it’s the actual function that gets called. If you were using React, this would just send a message saying a request had been made and nothing else, it’s pretty useless:
<button onClick={() => requestingData() } >Make a Request</button>
Whereas this will do the async thing: it’ll send a message to the reducer saying a request has been made, then sometime later it’ll send another message to the reducer saying the request completed, and update the store with the data.
<button onClick={() => handleAsync() } >Make a Request</button>
Your syntax is wrong though
store.dispatch(requestingData)
It’s not store.dispatch, it’s just dispatch. dispatch is a parameter that gets passed into the function. It happens to be the store’s dispatch function, but it’s the middleware that joins it to the store. handleAsync is just a function that returns a function, and dispatch is just a parameter, it could be called anything, store does not exist in that scope.
And you pass values to dispatch. It’s like dispatch({type: 'REQUESTING_DATA'}). And you have a function that produces that value (requestingData), so you need to execute the function