Fork me on GitHub

So, middleware. I grok that when you have multiple middleware, re-frame runs them in the opposite order as comp, i.e., first one in the list first. But how do after middleware fit into that pattern? E.g., in the todo-mvc example ( two of those middleware are after and the other two, trim-v and path are (I suspect) not-`after`. The after middlewares must operate on the output of the base handler (which gets its input from the not-`after` middlewares) right?


@fasiha: after middleware run the rest of the middleware chain, then runs the thing you passed.


Therefore the execution sequence of after middleware is right-to-left.


@cky: thanks, your prose explanation is much more understandable to me than the highly-nested code implementing after 😛 I guess then my question is: in the link I pasted above to the todomvc re-frame example, a vector of middlewares is (in pseudocode): [after f, path, after g, trim-v]. From what I understand so far, both after middlewares could be moved to the end of the vector (preserving their order, so in that case, check-schema-mw would still be left of ->ls) and functionality would be exactly the same?


I'm trying to understand why those four middlewares there were ordered the way they are, and just how much flexibility there is in reordering that vector. I.e., the two afters could have come first, last, interspersed as they are now…


@fasiha: To my understanding, the execution order is: path, trim-v, todos->ls!, then check-and-throw.


@cky: Excellent—that makes sense. Though it would probably be more sensible to write to localStorage (`todos->ls!`) only after the schema validation passed (`check-and-throw`).


Perhaps a todo (for me): add the twist about after middlewares being ordered the opposite as non-after ones to the wiki


I posted a question about re-frame-template ( when using +handler option (to use compojure), about autoloading the compojure handler as the file is changed. Cross-posting here in case that's something everyone can do—trying out this Clojure-in-both-front/back-end thing simple_smile