ring.middleware.flash questions

191 views
Skip to first unread message

Greg

unread,
Jul 21, 2013, 9:15:17 PM7/21/13
to ring-c...@googlegroups.com
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?

2) I'm looking at the code for 'flash-response', shown here:

 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)))

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)

?

Thanks!
Greg

--
Please do not email me anything that you are not comfortable also sharing with the NSA.

James Reeves

unread,
Jul 21, 2013, 9:51:45 PM7/21/13
to ring-c...@googlegroups.com
On 22 July 2013 02:15, Greg <gr...@kinostudios.com> wrote:
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?

Have you read the docstring?


  "If a :flash key is set on the response by the handler, a :flash key with
the same value will be set on the next request that shares the same session.
This is useful for small messages that persist across redirects."

The :flash key persists for exactly one request - it's like an auto-expiring session key. The terminology was cribbed from Ruby on Rails.
 
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)

?

Yes, you might be right. The redundancy might have come about from the async refactor.

- James

Greg

unread,
Jul 22, 2013, 11:51:59 AM7/22/13
to ring-c...@googlegroups.com
Have you read the docstring?

Yes, it was the first thing I read. It was not clear to me from the docstring that it didn't have anything to do with Flash. Where I come from, "flash" means either Flash memory or Adobe Flash (in the context of computers), and I've never heard another other use of it.

The :flash key persists for exactly one request - it's like an auto-expiring session key. The terminology was cribbed from Ruby on Rails.

I hate Ruby. :-p

Yes, you might be right. The redundancy might have come about from the async refactor.

OK thanks, just wanted to make sure I wasn't missing something! :-)

- Greg

--
Please do not email me anything that you are not comfortable also sharing with the NSA.

--
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.
 
 

Reply all
Reply to author
Forward
0 new messages