OLD | NEW |
1 --- | 1 --- |
2 layout: tutorial | 2 layout: tutorial |
3 title: "Use Streams for Data" | 3 title: "Use Streams for Data" |
4 description: | 4 description: |
5 Learn how to consume single-subscriber and broadcast streams, | 5 Learn how to consume single-subscriber and broadcast streams, |
6 with real-world uses. | 6 with real-world uses. |
7 tutorial: | 7 tutorial: |
8 id: streams | 8 id: streams |
9 next: fetchdata/ | 9 next: fetchdata/ |
10 next-title: "Fetch Data Dynamically" | 10 next-title: "Fetch Data Dynamically" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 .listen((value) => print("skip: $value")); // skip: 4 | 218 .listen((value) => print("skip: $value")); // skip: 4 |
219 // skip: 5 | 219 // skip: 5 |
220 | 220 |
221 broadcastStream | 221 broadcastStream |
222 .takeWhile((value) => value < 3) // take while true | 222 .takeWhile((value) => value < 3) // take while true |
223 .listen((value) => print("takeWhile: $value")); // takeWhile: 1 | 223 .listen((value) => print("takeWhile: $value")); // takeWhile: 1 |
224 // takeWhile: 2 | 224 // takeWhile: 2 |
225 | 225 |
226 broadcastStream | 226 broadcastStream |
227 .skipWhile((value) => value < 3) // skip while true | 227 .skipWhile((value) => value < 3) // skip while true |
228 .listen((value) => print("skipWhile: $value")); // skipWhile: 4 | 228 .listen((value) => print("skipWhile: $value")); // skipWhile: 3 |
| 229 // skipWhile: 4 |
229 // skipWhile: 5 | 230 // skipWhile: 5 |
230 {% endprettify %}<!--- END(stream_subsets) --> | 231 {% endprettify %}<!--- END(stream_subsets) --> |
231 | 232 |
232 ### Transforming stream data | 233 ### Transforming stream data |
233 | 234 |
234 Another useful method is the `transform()` method, which takes a | 235 Another useful method is the `transform()` method, which takes a |
235 `StreamTransformer` instance. This allows you to modify the contents of the | 236 `StreamTransformer` instance. This allows you to modify the contents of the |
236 stream. The `StreamTransformer.fromHandlers` constructor takes a `handleData` f
unction, | 237 stream. The `StreamTransformer.fromHandlers` constructor takes a `handleData` f
unction, |
237 which is called for each value passed from the stream. You can modify the value
| 238 which is called for each value passed from the stream. You can modify the value
|
238 as you wish, and add it back to the `StreamSink`, which results in the modified | 239 as you wish, and add it back to the `StreamSink`, which results in the modified |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 Chris Buckett is a Technical Manager for | 502 Chris Buckett is a Technical Manager for |
502 [Entity Group Ltd](http://www.entity.co.uk/), responsible for building and | 503 [Entity Group Ltd](http://www.entity.co.uk/), responsible for building and |
503 delivering enterprise client-server webapps, mostly with GWT, Java and .Net. | 504 delivering enterprise client-server webapps, mostly with GWT, Java and .Net. |
504 He runs the [dartwatch.com blog](http://blog.dartwatch.com/), and has written | 505 He runs the [dartwatch.com blog](http://blog.dartwatch.com/), and has written |
505 the book _Dart in Action_, which is available | 506 the book _Dart in Action_, which is available |
506 at [manning.com](http://www.manning.com/buckett). | 507 at [manning.com](http://www.manning.com/buckett). |
507 | 508 |
508 {% endcapture %} | 509 {% endcapture %} |
509 | 510 |
510 {% include tutorial.html %} | 511 {% include tutorial.html %} |
OLD | NEW |