@@ -11,15 +11,6 @@ export default {
1111 const event = binding . arg
1212 const streamName = binding . expression
1313
14- if ( ! Rx . Observable . fromEvent ) {
15- warn (
16- `No 'fromEvent' method on Observable class. ` +
17- `v-stream directive requires Rx.Observable.fromEvent method. ` +
18- `Try import 'rxjs/add/observable/fromEvent' for ${ streamName } ` ,
19- vnode . context
20- )
21- return
22- }
2314 if ( isSubject ( handle ) ) {
2415 handle = { subject : handle }
2516 } else if ( ! handle || ! isSubject ( handle . subject ) ) {
@@ -34,17 +25,36 @@ export default {
3425
3526 const subject = handle . subject
3627 const next = ( subject . next || subject . onNext ) . bind ( subject )
37- let fromEventArgs = handle . options ? [ el , event , handle . options ] : [ el , event ]
38- handle . subscription = Rx . Observable . fromEvent ( ...fromEventArgs ) . subscribe ( e => {
39- next ( {
40- event : e ,
41- data : handle . data
28+
29+ if ( vnode . componentInstance ) {
30+ handle . subscription = vnode . componentInstance . $eventToObservable ( event ) . subscribe ( e => {
31+ next ( {
32+ event : e ,
33+ data : handle . data
34+ } )
35+ } )
36+ } else {
37+ if ( ! Rx . Observable . fromEvent ) {
38+ warn (
39+ `No 'fromEvent' method on Observable class. ` +
40+ `v-stream directive requires Rx.Observable.fromEvent method. ` +
41+ `Try import 'rxjs/add/observable/fromEvent' for ${ streamName } ` ,
42+ vnode . context
43+ )
44+ return
45+ }
46+ let fromEventArgs = handle . options ? [ el , event , handle . options ] : [ el , event ]
47+ handle . subscription = Rx . Observable . fromEvent ( ...fromEventArgs ) . subscribe ( e => {
48+ next ( {
49+ event : e ,
50+ data : handle . data
51+ } )
4252 } )
43- } )
4453
45- // store handle on element with a unique key for identifying
46- // multiple v-stream directives on the same node
47- ; ( el . _rxHandles || ( el . _rxHandles = { } ) ) [ getKey ( binding ) ] = handle
54+ // store handle on element with a unique key for identifying
55+ // multiple v-stream directives on the same node
56+ ; ( el . _rxHandles || ( el . _rxHandles = { } ) ) [ getKey ( binding ) ] = handle
57+ }
4858 } ,
4959
5060 update ( el , binding ) {
0 commit comments