Hi Vagif,

On Feb 3, 4:27 pm, Vagif Verdi <[email protected]> wrote:
> Whatever you guys chose, do not go the immutable road. Compojure took
> that approach and now many people (including me) are stuck with
> situations where they need to update session in a middle and pass it
> somewhere else, and they can't. Session is a data storage, just like a
> database.

One thing that would help us a lot with choosing the right interface
for sessions is examples of session use from real application code. We
have considered simple examples like incrementing a counter and
logging in / logging out (http://gist.github.com/289993), but a
concrete example of read-write-read session usage would be really
helpful. Would you be willing to show us a case were you think
stateful sessions would be particularly nice?

> One of the strong points of compojure is the layers of middleware.
> Unfortunately there's no way to communicate between the layers,
> because current session updating mechanism makes it impossible. You
> cannot use the session to signal to the middleware that this
> particular case requires different handling.
>
> So one has to resort to communicating through other shared data
> storages like database and then practically duplicate the session
> mechanism.

It is possible to communicate between purely functional middleware
layers. The way one does this is by assoc'ing keys into the request
and/or response maps, and then get'ing and acting on those values
later in the request/response ring [1]. For example, to alter the the
behavior of middleware "wrap-second" from "wrap-first"

(defn wrap-first [handler]
  (fn [req]
    (handler (assoc req ::indicator true))))

(defn wrap-second [handler]
  (fn [req]
    (if (::indicator req)
      (do-somthing handler req)
      (do-something-else handler req))))

(def app
  (-> core
    wrap-first
    wrap-second))

This type of middleware communication will work in some cases but may
not in others. In particular, it works best when the actions in
question either happen all on the way down the middleware stack from
the adapter to the handler, or all on the way up. Would this kind of
communication be helpful for the problems that you are having? Again,
specific examples would be great.

[1] illustration of a request/response ring: http://imgur.com/6zAYD.jpg

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to