@@ -59,38 +59,110 @@ export const bufferTime: OperatorDoc = {
5959 name :
6060 'After every two and a half seconds, emit an array of the click events during that timeframe' ,
6161 code : `
62- import { fromEvent } from 'rxjs/observable/fromEvent';
63- import { map, bufferTime } from 'rxjs/operators';
64-
65- const clicks = fromEvent(document, 'click');
66- const buffered = clicks.pipe(
67- map(e => { return {x: e.clientX, y: e.clientY}; }),
68- bufferTime(2500)
69- );
70- buffered.subscribe(x => console.log(x));
62+ import { fromEvent } from 'rxjs/observable/fromEvent';
63+ import { bufferTime } from 'rxjs/operators';
64+
65+ const clicks = fromEvent(document, 'click', e => ({x: e.clientX, y: e.clientY}));
66+ const buffered = clicks.pipe(
67+ bufferTime(2500)
68+ );
69+ /*
70+ Example console output
71+
72+ []
73+
74+ [[object Object] {
75+ x: 150,
76+ y: 139
77+ }, [object Object] {
78+ x: 150,
79+ y: 139
80+ }, [object Object] {
81+ x: 150,
82+ y: 139
83+ }, [object Object] {
84+ x: 150,
85+ y: 139
86+ }]
87+
88+ [[object Object] {
89+ x: 150,
90+ y: 139
91+ }]
92+
93+ [[object Object] {
94+ x: 150,
95+ y: 137
96+ }, [object Object] {
97+ x: 150,
98+ y: 137
99+ }]
100+
101+ []
102+ */
103+
104+
105+ buffered.subscribe(x => console.log(x));
71106 ` ,
72107 externalLink : {
73108 platform : 'JSBin' ,
74- url : 'http://jsbin.com/fuqewiy/3 /embed?js,console,output'
109+ url : 'http://jsbin.com/fuqewiy/6 /embed?js,console,output'
75110 }
76111 } ,
77112 {
78113 name :
79- 'Every five seconds, emit the click events from a window of the next two seconds' ,
114+ 'Every five seconds, emit the click events from a window of the last two seconds' ,
80115 code : `
81116 import { fromEvent } from 'rxjs/observable/fromEvent';
82- import { map, bufferTime } from 'rxjs/operators';
117+ import { bufferTime } from 'rxjs/operators';
83118
84- const clicks = fromEvent(document, 'click');
119+ const clicks = fromEvent(document, 'click', e => ({x: e.clientX, y: e.clientY}) );
85120 const buffered = clicks.pipe(
86- map(e => { return {x: e.clientX, y: e.clientY}; }),
87121 bufferTime(2000, 5000)
88122 );
123+
124+ /*
125+ Example console output:
126+
127+ []
128+
129+ []
130+
131+ [[object Object] {
132+ x: 159,
133+ y: 140
134+ }, [object Object] {
135+ x: 159,
136+ y: 140
137+ }]
138+
139+ [[object Object] {
140+ x: 161,
141+ y: 140
142+ }, [object Object] {
143+ x: 161,
144+ y: 140
145+ }, [object Object] {
146+ x: 161,
147+ y: 140
148+ }, [object Object] {
149+ x: 161,
150+ y: 140
151+ }, [object Object] {
152+ x: 161,
153+ y: 140
154+ }, [object Object] {
155+ x: 161,
156+ y: 140
157+ }]
158+
159+ []
160+ */
89161 buffered.subscribe(x => console.log(x));
90162` ,
91163 externalLink : {
92164 platform : 'JSBin' ,
93- url : 'http://jsbin.com/xohupot/2 /embed?js,console,output'
165+ url : 'http://jsbin.com/xohupot/4 /embed?js,console,output'
94166 }
95167 }
96168 ] ,
0 commit comments