Skip to content

Commit 3096ffc

Browse files
committed
fix: listeners for manually forwarded events bound with modifiers were called twice
1 parent f6f3b51 commit 3096ffc

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

packages/common/forwardEventsBuilder.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
stop_propagation,
66
} from 'svelte/internal';
77

8-
// Match modifiers on DOM events.
8+
// Match old modifiers. (only works on DOM events)
99
const oldModifierRegex = /^[a-z]+(?::(?:preventDefault|stopPropagation|passive|nonpassive|capture|once|self))+$/;
10-
// Match modifiers on other events.
10+
// Match new modifiers.
1111
const newModifierRegex = /^[^$]+(?:\$(?:preventDefault|stopPropagation|passive|nonpassive|capture|once|self))+$/;
1212

1313
export function forwardEventsBuilder(component) {
@@ -30,23 +30,20 @@ export function forwardEventsBuilder(component) {
3030
events.push([eventType, callback]);
3131
}
3232
const oldModifierMatch = eventType.match(oldModifierRegex);
33-
const newModifierMatch = eventType.match(newModifierRegex);
34-
const modifierMatch = oldModifierMatch || newModifierMatch;
3533

3634
if (oldModifierMatch && console) {
3735
console.warn(
38-
'Event modifiers in SMUI now use "$" instead of ":", so that all events can be bound with modifiers. Please update your event binding: ',
36+
'Event modifiers in SMUI now use "$" instead of ":", so that ' +
37+
'all events can be bound with modifiers. Please update your ' +
38+
'event binding: ',
3939
eventType
4040
);
4141
}
4242

43-
if (modifierMatch) {
44-
// Remove modifiers from the real event.
45-
const parts = eventType.split(oldModifierMatch ? ':' : '$');
46-
eventType = parts[0];
47-
}
48-
4943
// Call the original $on function.
44+
// The modifiers are passed in so that if a lower component
45+
// forwards an event that doesn't bubble automatically, the
46+
// bound listeners will only be fired once.
5047
const componentDestructor = componentOn.call(
5148
component,
5249
eventType,
@@ -68,7 +65,8 @@ export function forwardEventsBuilder(component) {
6865
const destructors = [];
6966
const forwardDestructors = {};
7067

71-
// This function is responsible for forwarding all bound events.
68+
// This function is responsible for listening and forwarding
69+
// all bound events.
7270
$on = (fullEventType, callback) => {
7371
let eventType = fullEventType;
7472
let handler = callback;

0 commit comments

Comments
 (0)