| 12 | (defn flash-response
|
| 13 | "If response has a :flash key, saves it in :_flash of session for next request."
|
| 14 | [response {:keys [session flash] :as request}]
|
| 15 | (let [session (if (contains? response :session)
|
| 16 | (response :session)
|
| 17 | session)
|
| 18 | session (if-let [flash (response :flash)]
|
| 19 | (assoc (response :session session) :_flash flash)
|
| 20 | session)]
|
| 21 | (if (or flash (response :flash) (contains? response :session))
|
| 22 | (assoc response :session session)
|
| 23 | response))) |
| 19 | (assoc (response :session session) :_flash flash) |
Two questions actually:1) Can someone please explain what this middleware for? I assume that 'flash' here does not refer to any use of Adobe Flash, correct? Why would someone use it instead of the regular session stuff?
"If a :flash key is set on the response by the handler, a :flash key withthe same value will be set on the next request that shares the same session.This is useful for small messages that persist across redirects."
2) I'm looking at the code for 'flash-response'
Am I mistaken, or does line 19 have a weird redundancy?
19 (assoc (response :session session) :_flash flash)Since the 'session' var was already set to either the session from the request or the response, can't line 19 be rewritten like this:(assoc session :_flash flash)?
Have you read the docstring?
The :flash key persists for exactly one request - it's like an auto-expiring session key. The terminology was cribbed from Ruby on Rails.
Yes, you might be right. The redundancy might have come about from the async refactor.
--
You received this message because you are subscribed to the Google Groups "Ring" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ring-clojure...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.