@@ -59,38 +59,110 @@ export const bufferTime: OperatorDoc = {
59
59
name :
60
60
'After every two and a half seconds, emit an array of the click events during that timeframe' ,
61
61
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));
71
106
` ,
72
107
externalLink : {
73
108
platform : 'JSBin' ,
74
- url : 'http://jsbin.com/fuqewiy/3 /embed?js,console,output'
109
+ url : 'http://jsbin.com/fuqewiy/6 /embed?js,console,output'
75
110
}
76
111
} ,
77
112
{
78
113
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' ,
80
115
code : `
81
116
import { fromEvent } from 'rxjs/observable/fromEvent';
82
- import { map, bufferTime } from 'rxjs/operators';
117
+ import { bufferTime } from 'rxjs/operators';
83
118
84
- const clicks = fromEvent(document, 'click');
119
+ const clicks = fromEvent(document, 'click', e => ({x: e.clientX, y: e.clientY}) );
85
120
const buffered = clicks.pipe(
86
- map(e => { return {x: e.clientX, y: e.clientY}; }),
87
121
bufferTime(2000, 5000)
88
122
);
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
+ */
89
161
buffered.subscribe(x => console.log(x));
90
162
` ,
91
163
externalLink : {
92
164
platform : 'JSBin' ,
93
- url : 'http://jsbin.com/xohupot/2 /embed?js,console,output'
165
+ url : 'http://jsbin.com/xohupot/4 /embed?js,console,output'
94
166
}
95
167
}
96
168
] ,
0 commit comments