happypoulp/redux-tutorial

08_dispatch-async-action-2.js doesn't make sense?

Closed this issue · 1 comments

I see the point you're trying to reach with using the middleware for async actions but I don't understand what you did here in this example:

var asyncSayActionCreator_1 = function (message) {
    return function (dispatch) {
        setTimeout(function () {
            dispatch({
                type: 'SAY',
                message
            })
        }, 2000)
    }
}

console.log("\n", 'Running our async action creator:', "\n")
store_0.dispatch(asyncSayActionCreator_1('Hi'))

so asyncSayActionCreator_1is a function that takes a message as a parameter but it also returns a function that is expecting a dispatch method as a parameter to later invoke on the actual async action object passed to setTimeout.

in this example you are calling store_0.dispatch on the ActionCreator itself which doesn't make sense to me

store_0.dispatch(asyncSayActionCreator_1('Hi'))

Wouldn't this example make more sense and actually dispatch the asyncAction?

console.log("\n", 'Running our async action creator:', "\n")
asyncSayActionCreator_1('Hi')(store_0.dispatch)

Nevermind! I guess I didn't understand how the middleware works on the store. I should have kept reading, my mistake!