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

Stop event propagation inside handler. #69

Closed
wants to merge 1 commit into from

Conversation

doowb
Copy link

@doowb doowb commented Sep 16, 2015

I'd like to be able to break out of the handler loop if a handler specifies that it has handled the event.
This PR lets a handler fn set this.handled = true that will break out of the emit loop.

emitter.on('login', function (user) {
  if (user.username === 'doowb' && user.password === 'password') {
    this.handled = true;
    this.user = user;
  }
});

emitter.on('login', function (user) {
  this.error = 'Invalid username and/or password';
});

emitter.emit('login', {username: 'doowb', password: 'invalid'});
console.log(emitter.error);
//=> Invalid username and/or password

emitter.emit('login', {username: 'doowb', password: 'password'});
console.log(emitter.user);
//=> {username: 'doowb', password: 'password'}

@vendethiel
Copy link
Contributor

Seems like not too many people have needed this; so I'm going to close it.

Sorry for the delay.

@vendethiel vendethiel closed this Apr 15, 2019
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

Successfully merging this pull request may close these issues.

None yet

2 participants