Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
39 changes: 39 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ 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')
require('rxjs/add/operator/filter')

const miniRx = {
Observable,
Expand Down Expand Up @@ -141,6 +143,43 @@ 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 id="btn-native" v-stream:click.native="clickNative$">+</my-button>
<my-button id="btn" v-stream:click="click$">-</my-button>
</div>
`,
components: {
myButton: {
template: '<button>MyButton</button>'
}
},
domStreams: ['clickNative$', 'click$'],
subscriptions () {
return {
count: this.clickNative$
.filter(e => e.event.target && e.event.target.id === 'btn-native')
.map(() => 1)
.merge(this.click$.map(() => -1))
.merge()
.startWith(0)
.scan((total, change) => total + change)
}
}
}).$mount()

expect(vm.$el.querySelector('span').textContent).toBe('0')
click(vm.$el.querySelector('#btn-native'))
click(vm.$el.querySelector('#btn'))
nextTick(() => {
expect(vm.$el.querySelector('span').textContent).toBe('1')
done()
})
})

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