Closed agarzola closed 8 years ago
This should be implemented as a separate project. The goal of connect-flash
is to mimic the functionality in Express 2.x, and nothing else.
Got it. Thank you for the prompt reply!
Hey @agarzola, did you make any progress with this?
@loweoj I think I handled this need some other way last year. That said, if this is something you want to take on yourself, I'd be happy to contribute either with code or testing/reviewing/both.
How I handled mine, the object passed to req.flash can be accessed as the zeroth index
req.flash('old', {me: 'Josh'})
var old = req.flash('old')[0]
res.send(old.me)
I’m interested in expanding
connect-flash
to allow passing objects to it. Ideally, I’m looking to do this:This way, it would be trivial to check for
messages.fieldName
from my templates like so:Specifically, I’d like to expand on
req.flash()
to accept a non-Array object as the second argument or the only argument. Behavior could be as follows:req.flash('type', object)
— Only the object would be registered atreq.session.flash.type
(i.e. not an array with the passedobject
as its first item). If an object had already been registered for that type, it would be expanded with the current object’s properties (read: not entirely replaced). If a non-object had already been registered for that type (i.e.req.flash('type', 'A message')
followed byreq.flash('type', object)
), then we would respect the existing array and simply push to it, resulting inreq.session.flash.type
being equal to[ 'A message', object ]
.req.flash(object)
— Each key/value pair at the root of the provided object is handled as if it wasreq.flash(key, value)
, following existing conventions as well as the new conventions I described above.I don’t think this would break existing functionality (please correct me if I’m wrong) and it would make more granular error reporting to the user easier to implement.
Is this a contribution you would be interested in, or would you rather it live as a separate project?