5
5
stop_propagation ,
6
6
} from 'svelte/internal' ;
7
7
8
- // Match modifiers on DOM events.
8
+ // Match old modifiers. (only works on DOM events)
9
9
const oldModifierRegex = / ^ [ a - z ] + (?: : (?: p r e v e n t D e f a u l t | s t o p P r o p a g a t i o n | p a s s i v e | n o n p a s s i v e | c a p t u r e | o n c e | s e l f ) ) + $ / ;
10
- // Match modifiers on other events .
10
+ // Match new modifiers .
11
11
const newModifierRegex = / ^ [ ^ $ ] + (?: \$ (?: p r e v e n t D e f a u l t | s t o p P r o p a g a t i o n | p a s s i v e | n o n p a s s i v e | c a p t u r e | o n c e | s e l f ) ) + $ / ;
12
12
13
13
export function forwardEventsBuilder ( component ) {
@@ -30,23 +30,20 @@ export function forwardEventsBuilder(component) {
30
30
events . push ( [ eventType , callback ] ) ;
31
31
}
32
32
const oldModifierMatch = eventType . match ( oldModifierRegex ) ;
33
- const newModifierMatch = eventType . match ( newModifierRegex ) ;
34
- const modifierMatch = oldModifierMatch || newModifierMatch ;
35
33
36
34
if ( oldModifierMatch && console ) {
37
35
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: ' ,
39
39
eventType
40
40
) ;
41
41
}
42
42
43
- if ( modifierMatch ) {
44
- // Remove modifiers from the real event.
45
- const parts = eventType . split ( oldModifierMatch ? ':' : '$' ) ;
46
- eventType = parts [ 0 ] ;
47
- }
48
-
49
43
// 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.
50
47
const componentDestructor = componentOn . call (
51
48
component ,
52
49
eventType ,
@@ -68,7 +65,8 @@ export function forwardEventsBuilder(component) {
68
65
const destructors = [ ] ;
69
66
const forwardDestructors = { } ;
70
67
71
- // This function is responsible for forwarding all bound events.
68
+ // This function is responsible for listening and forwarding
69
+ // all bound events.
72
70
$on = ( fullEventType , callback ) => {
73
71
let eventType = fullEventType ;
74
72
let handler = callback ;
0 commit comments