Skip to content

Commit

Permalink
Merge pull request #127 from brigade/fix-undefined-handlers
Browse files Browse the repository at this point in the history
Check for handler presence before invoking it
  • Loading branch information
trotzig authored Oct 20, 2016
2 parents 6ce28c6 + a317a79 commit 3e7033c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/waypoint.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ class TargetEventHandlers {
handleEvent(eventName, event) {
const { handlers } = this.getEventHandlers(eventName);
Object.keys(handlers).forEach(function(index) {
handlers[index](event);
const handler = handlers[index];
if (handler) {
// We need to check for presence here because a handler function may
// cause later handlers to get removed. This can happen if you for
// instance have a waypoint that unmounts another waypoint as part of an
// onEnter/onLeave handler.
handler(event);
}
});
}

Expand Down

0 comments on commit 3e7033c

Please sign in to comment.