@@ -46,41 +46,94 @@ export const bufferToggle: OperatorDoc = {
46
46
import { fromEvent } from 'rxjs/observable/fromEvent';
47
47
import { interval } from 'rxjs/observable/interval';
48
48
import { empty } from 'rxjs/observable/empty';
49
- import { map, bufferToggle } from 'rxjs/operators';
49
+ import { bufferToggle } from 'rxjs/operators';
50
50
51
- const clicks$ = fromEvent(document, 'click');
52
- const openings$ = interval(1000);
53
- const buffered$ = clicks$.pipe(
54
- map(e => {return {X: e.clientX, Y: e.clientY};}),
55
- bufferToggle(openings$, i => i % 2 ? interval(500) : empty())
51
+ const clicks = fromEvent(document, 'click', e => ({x: e.clientX, y: e.clientY}));
52
+ const openings = interval(1000);
53
+ const buffered = clicks.pipe(
54
+ bufferToggle(openings, i => i % 2 ? interval(500) : empty())
56
55
);
57
- buffered$.subscribe(x => console.log(x));
56
+ /*
57
+ Expected console output:
58
+
59
+ []
60
+
61
+ [[object Object] {
62
+ x: 156,
63
+ y: 165
64
+ }, [object Object] {
65
+ x: 156,
66
+ y: 165
67
+ }, [object Object] {
68
+ x: 156,
69
+ y: 165
70
+ }]
71
+
72
+ []
73
+
74
+ []
75
+ */
76
+ buffered.subscribe(x => console.log(x));
58
77
` ,
59
78
externalLink : {
60
79
platform : 'JSBin' ,
61
- url : 'http://jsbin.com/nuriyod/1 /embed?js,console,output'
80
+ url : 'http://jsbin.com/nuriyod/3 /embed?js,console,output'
62
81
}
63
82
} ,
64
83
{
65
84
name :
66
85
'Start buffering all the click events when you press the "S" key and close the buffer when you press the "E" key' ,
67
86
code : `
68
87
import { fromEvent } from 'rxjs/observable/fromEvent';
69
- import { filter, map, bufferToggle } from 'rxjs/operators';
88
+ import { filter, bufferToggle } from 'rxjs/operators';
70
89
71
- const clicks$ = fromEvent(document, 'click');
72
- const keyUp$ = fromEvent(document,'keyup');
73
- const openings$ = keyUp$.pipe(filter(e => e.key === 's'));
74
- const closing$ = keyUp$.pipe(filter(e => e.key === 'e'));
75
- const buffered$ = clicks$.pipe(
76
- map(e => {return {X: e.clientX, Y: e.clientY};}),
77
- bufferToggle(openings$, _ => closing$)
90
+ const clicks = fromEvent(document, 'click', e => ({x: e.clientX, y: e.clientY}));
91
+ const keyUp = fromEvent(document,'keyup');
92
+ const openings = keyUp.pipe(filter(e => e.key === 's'));
93
+ const closing = keyUp.pipe(filter(e => e.key === 'e'));
94
+ const buffered = clicks.pipe(
95
+ bufferToggle(openings, _ => closing)
78
96
);
79
- buffered$.subscribe(x => console.log(x));
97
+ /*
98
+ Expected console output:
99
+
100
+ [[object Object] {
101
+ x: 147,
102
+ y: 135
103
+ }, [object Object] {
104
+ x: 147,
105
+ y: 135
106
+ }, [object Object] {
107
+ x: 144,
108
+ y: 135
109
+ }, [object Object] {
110
+ x: 144,
111
+ y: 135
112
+ }, [object Object] {
113
+ x: 144,
114
+ y: 135
115
+ }]
116
+
117
+ [[object Object] {
118
+ x: 144,
119
+ y: 135
120
+ }, [object Object] {
121
+ x: 144,
122
+ y: 135
123
+ }]
124
+
125
+ [[object Object] {
126
+ x: 143,
127
+ y: 136
128
+ }]
129
+
130
+ */
131
+
132
+ buffered.subscribe(x => console.log(x));
80
133
` ,
81
134
externalLink : {
82
135
platform : 'JSBin' ,
83
- url : 'http://jsbin.com/vurobel/8 /embed?js,console,output'
136
+ url : 'http://jsbin.com/vurobel/11 /embed?js,console,output'
84
137
}
85
138
}
86
139
] ,
0 commit comments