Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/directives/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
let handle = binding.value
const event = binding.arg
const streamName = binding.expression
const modifiers = binding.modifiers

if (isSubject(handle)) {
handle = { subject: handle }
Expand All @@ -26,7 +27,7 @@ export default {
const subject = handle.subject
const next = (subject.next || subject.onNext).bind(subject)

if (vnode.componentInstance) {
if (!modifiers.native && vnode.componentInstance) {
handle.subscription = vnode.componentInstance.$eventToObservable(event).subscribe(e => {
next({
event: e,
Expand Down
34 changes: 34 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require('rxjs/add/operator/map')
require('rxjs/add/operator/startWith')
require('rxjs/add/operator/scan')
require('rxjs/add/operator/pluck')
require('rxjs/add/operator/merge')

const miniRx = {
Observable,
Expand Down Expand Up @@ -141,6 +142,39 @@ test('v-stream directive (basic)', done => {
})
})

test('v-stream directive (with .native modify)', done => {
const vm = new Vue({
template: `
<div>
<span class="count">{{ count }}</span>
<my-button v-stream:click.native="clickNative$">+</my-button>
<my-button v-stream:click="click$">-</my-button>
</div>
`,
components: {
myButton: {
template: '<button>MyButton</button>'
}
},
domStreams: ['clickNative$', 'click$'],
subscriptions () {
return {
count: this.click$.map(() => -1)
.merge(this.clickNative$.map(() => 1))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This map operator function should asserting the passing argument is indeed a native event

.startWith(0)
.scan((total, change) => total + change)
}
}
}).$mount()

expect(vm.$el.querySelector('span').textContent).toBe('0')
click(vm.$el.querySelector('button'))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two buttons, use ID selector

nextTick(() => {
expect(vm.$el.querySelector('span').textContent).toBe('1')
done()
})
})

test('v-stream directive (with data)', done => {
const vm = new Vue({
data: {
Expand Down