-
Notifications
You must be signed in to change notification settings - Fork 190
/
counter-function.html
51 lines (40 loc) · 1.01 KB
/
counter-function.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!-- this demo requires a browser that natively supports ES2015 -->
<script src="https://unpkg.com/rxjs/bundles/rxjs.umd.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="../dist/vue-rx.js"></script>
<div id="app">
<div>{{ count }}</div>
<!-- callback declared on observableMethods -->
<button v-on:click="muchMore(500)">Add 500</button>
<button v-on:click="minus(minusDelta1)"> Minus on Click </button>
<pre>{{ $data }}</pre>
</div>
<script>
const { merge } = rxjs
const { startWith, scan } = rxjs.operators
new Vue({
el: '#app',
data () {
return {
minusDelta1: -1,
minusDelta2: -1
}
},
// declare callback Subjects
observableMethods: {
muchMore: 'muchMore$',
minus:'minus$'
}, // equivalent of above: ['muchMore','minus']
subscriptions () {
return {
count: merge(
this.muchMore$,
this.minus$
).pipe(
startWith(0),
scan((total, change) => total + change)
)
}
}
})
</script>