Skip to content

Commit a4e49d1

Browse files
committed
chore: update examples for rxjs 6
1 parent bd193d5 commit a4e49d1

File tree

4 files changed

+47
-50
lines changed

4 files changed

+47
-50
lines changed

example/counter-function.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- this demo requires a browser that natively supports ES2015 -->
22

3-
<script src="https://unpkg.com/@reactivex/rxjs/dist/global/Rx.js"></script>
3+
<script src="https://unpkg.com/rxjs/bundles/rxjs.umd.js"></script>
44
<script src="https://unpkg.com/vue/dist/vue.js"></script>
55
<script src="../dist/vue-rx.js"></script>
66

@@ -17,6 +17,9 @@
1717
</div>
1818

1919
<script>
20+
const { merge } = rxjs
21+
const { startWith, scan } = rxjs.operators
22+
2023
new Vue({
2124
el: '#app',
2225

@@ -34,16 +37,14 @@
3437
}, // equivalent of above: ['muchMore','minus']
3538

3639
subscriptions () {
37-
var count$ = Rx.Observable
38-
.merge(
39-
this.muchMore$,
40+
return {
41+
count: merge(
42+
this.muchMore$,
4043
this.minus$
44+
).pipe(
45+
startWith(0),
46+
scan((total, change) => total + change)
4147
)
42-
.startWith(0)
43-
.scan((total, change) => total + change)
44-
45-
return {
46-
count: count$
4748
}
4849
}
4950
})

example/counter-simple.html

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
1-
<script src="https://unpkg.com/@reactivex/rxjs/dist/global/Rx.js"></script>
1+
<script src="https://unpkg.com/rxjs/bundles/rxjs.umd.js"></script>
22
<script src="https://unpkg.com/vue/dist/vue.js"></script>
33
<script src="../dist/vue-rx.js"></script>
44

55
<div id="app">
66
<div>{{ count }}</div>
77
<button v-stream:click="plus$">+</button>
88
<button v-stream:click="minus$">-</button>
9-
<my-component v-stream:more="more$"></my-component>
109
</div>
1110

1211
<script>
13-
Vue.component('my-component', {
14-
template: '<button v-on:click="more">Iwant more!</button>',
15-
methods:{
16-
more:function(){
17-
this.$emit('more',100)
18-
}
19-
}
20-
})
12+
const { merge } = rxjs
13+
const { map, startWith, scan } = rxjs.operators
2114

2215
new Vue({
2316
el: '#app',
2417

2518
// declare dom stream Subjects
26-
domStreams: ['plus$', 'minus$','more$'],
19+
domStreams: ['plus$', 'minus$'],
2720

2821
subscriptions () {
29-
var plus$ = this.plus$.map(() => 1)
30-
var minus$ = this.minus$.map(() => -1)
31-
var more$ = this.more$.map(() => 100)
32-
var count$ = Rx.Observable
33-
.merge(plus$, minus$, more$)
34-
.startWith(0)
35-
.scan((total, change) => total + change)
36-
3722
return {
38-
count: count$
23+
count: merge(
24+
this.plus$.pipe(map(() => 1)),
25+
this.minus$.pipe(map(() => -1))
26+
).pipe(
27+
startWith(0),
28+
scan((total, change) => total + change)
29+
)
3930
}
4031
}
4132
})
42-
</script>
33+
</script>

example/counter.html

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- this demo requires a browser that natively supports ES2015 -->
22

3-
<script src="https://unpkg.com/@reactivex/rxjs/dist/global/Rx.js"></script>
3+
<script src="https://unpkg.com/rxjs/bundles/rxjs.umd.js"></script>
44
<script src="https://unpkg.com/vue/dist/vue.js"></script>
55
<script src="../dist/vue-rx.js"></script>
66

@@ -25,6 +25,9 @@
2525
</div>
2626

2727
<script>
28+
const { merge } = rxjs
29+
const { map, pluck, startWith, scan } = rxjs.operators
30+
2831
new Vue({
2932
el: '#app',
3033

@@ -37,7 +40,7 @@
3740

3841
components: {
3942
myButton: {
40-
template: '<button>MyButton</button>'
43+
template: `<button @click="$emit('click')">MyButton</button>`
4144
}
4245
},
4346

@@ -52,16 +55,14 @@
5255
domStreams: ['plus$', 'minus$'],
5356

5457
subscriptions () {
55-
var count$ = Rx.Observable
56-
.merge(
57-
this.plus$.map(() => 1),
58-
this.minus$.pluck('data')
59-
)
60-
.startWith(0)
61-
.scan((total, change) => total + change)
62-
6358
return {
64-
count: count$
59+
count: merge(
60+
this.plus$.pipe(map(() => 1)),
61+
this.minus$.pipe(pluck('data'))
62+
).pipe(
63+
startWith(0),
64+
scan((total, change) => total + change)
65+
)
6566
}
6667
}
6768
})

example/wiki-search.html

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script src="https://unpkg.com/jquery"></script>
2-
<script src="https://unpkg.com/@reactivex/rxjs/dist/global/Rx.js"></script>
2+
<script src="https://unpkg.com/rxjs/bundles/rxjs.umd.js"></script>
33
<script src="https://unpkg.com/vue/dist/vue.js"></script>
44
<script src="../dist/vue-rx.js"></script>
55

@@ -22,8 +22,11 @@ <h1>{{ results.term }}</h1>
2222
</div>
2323

2424
<script>
25+
const { from } = rxjs
26+
const { pluck, filter, debounceTime, distinctUntilChanged, switchMap, map } = rxjs.operators
27+
2528
function fetchTerm (term) {
26-
return Rx.Observable.fromPromise($.ajax({
29+
return from($.ajax({
2730
url: 'http://en.wikipedia.org/w/api.php',
2831
dataType: 'jsonp',
2932
data: {
@@ -53,13 +56,14 @@ <h1>{{ results.term }}</h1>
5356
subscriptions () {
5457
return {
5558
// this is the example in RxJS's readme.
56-
results: this.$watchAsObservable('search')
57-
.pluck('newValue')
58-
.filter(text => text.length > 2)
59-
.debounceTime(500)
60-
.distinctUntilChanged()
61-
.switchMap(fetchTerm)
62-
.map(formatResult)
59+
results: this.$watchAsObservable('search').pipe(
60+
pluck('newValue'),
61+
filter(text => text.length > 2),
62+
debounceTime(500),
63+
distinctUntilChanged(),
64+
switchMap(fetchTerm),
65+
map(formatResult)
66+
)
6367
}
6468
}
6569
})</script>

0 commit comments

Comments
 (0)