Skip to content

Commit 3e7033c

Browse files
authored
Merge pull request #127 from brigade/fix-undefined-handlers
Check for handler presence before invoking it
2 parents 6ce28c6 + a317a79 commit 3e7033c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/waypoint.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ class TargetEventHandlers {
7171
handleEvent(eventName, event) {
7272
const { handlers } = this.getEventHandlers(eventName);
7373
Object.keys(handlers).forEach(function(index) {
74-
handlers[index](event);
74+
const handler = handlers[index];
75+
if (handler) {
76+
// We need to check for presence here because a handler function may
77+
// cause later handlers to get removed. This can happen if you for
78+
// instance have a waypoint that unmounts another waypoint as part of an
79+
// onEnter/onLeave handler.
80+
handler(event);
81+
}
7582
});
7683
}
7784

0 commit comments

Comments
 (0)