@@ -46,41 +46,94 @@ export const bufferToggle: OperatorDoc = {
4646 import { fromEvent } from 'rxjs/observable/fromEvent';
4747 import { interval } from 'rxjs/observable/interval';
4848 import { empty } from 'rxjs/observable/empty';
49- import { map, bufferToggle } from 'rxjs/operators';
49+ import { bufferToggle } from 'rxjs/operators';
5050
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())
5655 );
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));
5877 ` ,
5978 externalLink : {
6079 platform : 'JSBin' ,
61- url : 'http://jsbin.com/nuriyod/1 /embed?js,console,output'
80+ url : 'http://jsbin.com/nuriyod/3 /embed?js,console,output'
6281 }
6382 } ,
6483 {
6584 name :
6685 'Start buffering all the click events when you press the "S" key and close the buffer when you press the "E" key' ,
6786 code : `
6887 import { fromEvent } from 'rxjs/observable/fromEvent';
69- import { filter, map, bufferToggle } from 'rxjs/operators';
88+ import { filter, bufferToggle } from 'rxjs/operators';
7089
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)
7896 );
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));
80133` ,
81134 externalLink : {
82135 platform : 'JSBin' ,
83- url : 'http://jsbin.com/vurobel/8 /embed?js,console,output'
136+ url : 'http://jsbin.com/vurobel/11 /embed?js,console,output'
84137 }
85138 }
86139 ] ,
0 commit comments