Skip to content

Commit 580cde3

Browse files
regouyyx990803
authored andcommitted
add 'fromEvent' options (#36)
* add import 'fromEvent' warning add support fromEvent Options * spaces around else if * warning space
1 parent 80dd3a5 commit 580cde3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

example/counter.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<!-- simple usage -->
1111
<button v-stream:click="plus$">Add on Click</button>
1212

13+
14+
<button v-stream:click="{ subject: plus$, data: minusDelta1, options:{once:true} }">Add on Click (Option once:true)</button>
15+
1316
<!-- you can also stream to the same subject with different events/data -->
1417
<button
1518
v-stream:click="{ subject: minus$, data: minusDelta1 }"

src/directives/stream.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@ export default {
2121
vnode.context
2222
)
2323
return
24+
} else if (!Rx.Observable.fromEvent) {
25+
warn(
26+
`No 'fromEvent' method on Observable class. ` +
27+
`v-stream directive requires Rx.Observable.fromEvent method. ` +
28+
`Try import 'rxjs/add/observable/fromEvent' for ${streamName}`,
29+
vnode.context
30+
)
31+
return
2432
}
2533

2634
const subject = handle.subject
2735
const next = (subject.next || subject.onNext).bind(subject)
28-
handle.subscription = Rx.Observable.fromEvent(el, event).subscribe(e => {
36+
let fromEventArgs = handle.options ? [el, event, handle.options] : [el, event]
37+
handle.subscription = Rx.Observable.fromEvent(...fromEventArgs).subscribe(e => {
2938
next({
3039
event: e,
3140
data: handle.data

0 commit comments

Comments
 (0)