This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-12
Channels
- # beginners (4)
- # boot (58)
- # braid-chat (9)
- # cider (19)
- # clojure (26)
- # clojure-austin (8)
- # clojure-berlin (1)
- # clojure-poland (2)
- # clojure-russia (238)
- # clojurescript (22)
- # core-async (2)
- # cursive (6)
- # datomic (32)
- # emacs (5)
- # hoplon (1)
- # jobs (10)
- # keechma (1)
- # ldnclj (2)
- # off-topic (5)
- # om (7)
- # onyx (4)
- # proton (1)
- # re-frame (10)
- # reagent (5)
- # ring-swagger (10)
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 (https://github.com/Day8/re-frame/blob/4b3e59950f90c46d873aaab0777c1217a1aeead0/examples/todomvc/src/todomvc/handlers.cljs#L27) 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: Have a look at https://github.com/Day8/re-frame/blob/master/src/re_frame/middleware.cljs#L190
@fasiha: after
middleware run the rest of the middleware chain, then runs the thing you passed.
@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 after
s 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 (https://github.com/Day8/re-frame-template/issues/24) 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