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()?
If
req.flash()
is called like that without any arguments, it should return an array of all the messages regardless of their key. For exampleThis 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 doingYou would have to do
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()
?