File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -24,11 +24,21 @@ export default {
24
24
return
25
25
}
26
26
27
+ const modifiersFuncs = {
28
+ stop : e => e . stopPropagation ( ) ,
29
+ prevent : e => e . preventDefault ( )
30
+ }
31
+
32
+ var modifiersExists = Object . keys ( modifiersFuncs ) . filter (
33
+ key => modifiers [ key ]
34
+ )
35
+
27
36
const subject = handle . subject
28
37
const next = ( subject . next || subject . onNext ) . bind ( subject )
29
38
30
39
if ( ! modifiers . native && vnode . componentInstance ) {
31
40
handle . subscription = vnode . componentInstance . $eventToObservable ( event ) . subscribe ( e => {
41
+ modifiersExists . forEach ( mod => modifiersFuncs [ mod ] ( e ) )
32
42
next ( {
33
43
event : e ,
34
44
data : handle . data
@@ -46,6 +56,7 @@ export default {
46
56
}
47
57
const fromEventArgs = handle . options ? [ el , event , handle . options ] : [ el , event ]
48
58
handle . subscription = Rx . Observable . fromEvent ( ...fromEventArgs ) . subscribe ( e => {
59
+ modifiersExists . forEach ( mod => modifiersFuncs [ mod ] ( e ) )
49
60
next ( {
50
61
event : e ,
51
62
data : handle . data
Original file line number Diff line number Diff line change @@ -203,6 +203,32 @@ test('v-stream directive (with .native modify)', done => {
203
203
} )
204
204
} )
205
205
206
+ test ( 'v-stream directive (with .stop, .prevent modify)' , done => {
207
+ const vm = new Vue ( {
208
+ template : `
209
+ <form>
210
+ <span>{{stoped}} {{prevented}}</span>
211
+ <button id="btn-stop" v-stream:click.stop="clickStop$">Stop</button>
212
+ <button id="btn-prevent" type="submit" v-stream:click.prevent="clickPrevent$">Submit</button>
213
+ </form>
214
+ ` ,
215
+ domStreams : [ 'clickStop$' , 'clickPrevent$' ] ,
216
+ subscriptions ( ) {
217
+ return {
218
+ stoped : this . clickStop$ . map ( x => x . event . cancelBubble ) ,
219
+ prevented : this . clickPrevent$ . map ( x => x . event . defaultPrevented )
220
+ }
221
+ }
222
+ } ) . $mount ( )
223
+
224
+ click ( vm . $el . querySelector ( '#btn-stop' ) )
225
+ click ( vm . $el . querySelector ( '#btn-prevent' ) )
226
+ nextTick ( ( ) => {
227
+ expect ( vm . $el . querySelector ( 'span' ) . textContent ) . toBe ( 'true true' )
228
+ done ( )
229
+ } )
230
+ } )
231
+
206
232
test ( 'v-stream directive (with data)' , done => {
207
233
const vm = new Vue ( {
208
234
data : {
You can’t perform that action at this time.
0 commit comments