OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library async.stream_sink_transformer; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import 'stream_sink_transformer/handler_transformer.dart'; | |
10 import 'stream_sink_transformer/stream_transformer_wrapper.dart'; | |
11 | |
12 /// A [StreamSinkTransformer] transforms the events being passed to a sink. | |
13 /// | |
14 /// This works on the same principle as a [StreamTransformer]. Each transformer | |
15 /// defines a [bind] method that takes in the original [StreamSink] and returns | |
16 /// the transformed version. However, where a [StreamTransformer] transforms | |
17 /// events after they leave the stream, this transforms them before they enter | |
18 /// the sink. | |
19 /// | |
20 /// It's good practice to write transformers that can be used multiple times. | |
Lasse Reichstein Nielsen
2016/01/07 07:37:01
Not sure what this line says?
I *think* it means t
nweiz
2016/01/07 21:32:26
Done.
I copied this line almost verbatim from the
Lasse Reichstein Nielsen
2016/01/08 07:23:06
Good point, I'll look at that.
| |
21 abstract class StreamSinkTransformer<S, T> { | |
Lasse Reichstein Nielsen
2016/01/07 07:37:01
Do we really need a class?
It has exactly one inst
nweiz
2016/01/07 21:32:26
My biggest worry with that is how inconsistent it
Lasse Reichstein Nielsen
2016/01/08 07:23:06
True. StreamTransformer is used on other classes t
| |
22 /// Creates a [StreamSinkTransformer] that transforms events and errors | |
23 /// using [transformer]. | |
24 /// | |
25 /// This is equivalent to piping all events from the outer sink through a | |
26 /// stream transformed by [transformer] and from there into the inner sink. | |
27 const factory StreamSinkTransformer.fromStreamTransformer( | |
28 StreamTransformer<S, T> transformer) = | |
29 StreamTransformerWrapper<S, T>; | |
30 | |
31 /// Creates a [StreamSinkTransformer] that delegates events to the given | |
32 /// handlers. | |
33 /// | |
34 /// The handlers work exactly as they do for [StreamTransformer.fromHandlers]. | |
35 /// They're called for each incoming event, and any actions on the sink | |
36 /// they're passed are forwarded to the inner sink. | |
Lasse Reichstein Nielsen
2016/01/07 07:37:01
Specify what happens if a handler is omitted (it s
nweiz
2016/01/07 21:32:26
Done.
| |
37 factory StreamSinkTransformer.fromHandlers({ | |
38 void handleData(S data, EventSink<T> sink), | |
39 void handleError(Object error, StackTrace stackTrace, EventSink<T> sink), | |
40 void handleDone(EventSink<T> sink)}) { | |
41 return new HandlerTransformer<S, T>(handleData, handleError, handleDone); | |
42 } | |
43 | |
44 /// Transforms the events passed to [sink]. | |
45 /// | |
46 /// Creates a new sink. When events are passed to the returned sink, it will | |
47 /// transform them and pass the transformed versions to [sink]. | |
48 StreamSink<S> bind(StreamSink<T> sink); | |
49 } | |
OLD | NEW |