happypoulp / redux-tutorial

Learn how to use redux step by step
3.76k stars 546 forks source link

Step 11: promise-middleware.js too confusing? #81

Closed ablakey closed 8 years ago

ablakey commented 8 years ago

It might just be me, but the contents of promise-middleware.js seems very complex. I can't make anything of it, despite fully understanding everything else in this tutorial. Is it possible to break something like that down into separate functions and then compose them together? I come mainly from the land of Python where isolating "doing one thing" as its own method/function is a form of documentation.

And please feel free to say, "it's perfectly readable to a typical js developer" if that's the truth.

happypoulp commented 8 years ago

Hi,

You're right that promise-middleware is not that much easy to understand. Is it the promise middleware logic that bothers you or the general structure of a middleware:

    var anyMiddleware = function ({ dispatch, getState }) {
        return function(next) {
            return function (action) {
                // your middleware-specific code goes here
            }
        }
    }

?

If you struggle with the generic middleware structure, I strongly advise you to have a look at http://redux.js.org/docs/advanced/Middleware.html with explain in more details the purpose this structure.

If it's really the logic of the promise-middleware that you find hard to grasp, I'll detail it to you, there is no magic in it.