Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The value of a little advice #8

Open
tudousi opened this issue Sep 28, 2015 · 0 comments
Open

The value of a little advice #8

tudousi opened this issue Sep 28, 2015 · 0 comments

Comments

@tudousi
Copy link

tudousi commented Sep 28, 2015

use while message = flash.shift() get value too cumbersome。
Some values are not my concern
I just want error_message value
Whether this can be req.flash('message') ?

I modified code
after flash('message') the 'message' be delete, no need to manually shift.

function push(type, msg) {
  var res = this.res || this;
  var locals = res.locals.flash;
  if(!msg){
      if(typeof type === 'string' && locals.length){
          for(var i = 0, l = locals.length; i < l; i++){
              if(locals[i]['type'] === type){
                  msg = locals[i]['message'];
                  locals.splice(i, 1);
                  return msg;
              }
          }
      }
      return;
  }
  msg = {
    message: msg,
    type: type
  }

  var messages = res.locals.flash
  // do not allow duplicate flash messages
  for (var i = 0; i < messages.length; i++) {
    var message = messages[i]
    if (msg.type === message.type && msg.message === message.message) return this
  }
  messages.push(msg)
  return this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant