jaredhanson / connect-flash

Flash message middleware for Connect and Express.
MIT License
1.24k stars 158 forks source link

Return all flash messages as array if key isn't passed #26

Closed rightaway closed 9 years ago

rightaway commented 9 years ago

If req.flash() is called like that without any arguments, it should return an array of all the messages regardless of their key. For example

[
  { type: 'info', message: 'message 1' },
  { type: 'error', message: 'message 2' },
  { type: 'success', message: 'message 3' },
]

This is so that you are sure you are getting all error messages regardless of key. If you only do req.flash('info/success/error, etc you will miss messages that have been added under a new key. It also makes the templates more complicated. Instead of simply doing

for msg in flash
  <div class='{{ msg.type }}'>{{ msg.message }}</div>

You would have to do

for msg in flash('info')
  <div class='info'>{{ msg }}</div>
for msg in flash('error')
  <div class='error'>{{ msg }}</div>
for msg in flash('success')
  <div class='success'>{{ msg }}</div>

and would have to remember to add to this list when new flash message types are added throughout the application.

If such a change is considered breaking and unacceptable, could it be added as a new method under the flash object, like flash.all()?