Chromium Code Reviews| Index: lib/src/delegate/event_sink.dart |
| diff --git a/lib/src/delegate/event_sink.dart b/lib/src/delegate/event_sink.dart |
| index 5a525dfc8c55d079a21ef7f4e0c0366134a9889a..14501b28d3ea65906c4cf3ebd51cf5a5c61e74ac 100644 |
| --- a/lib/src/delegate/event_sink.dart |
| +++ b/lib/src/delegate/event_sink.dart |
| @@ -12,7 +12,18 @@ class DelegatingEventSink<T> implements EventSink<T> { |
| final EventSink _sink; |
| /// Create a delegating sink forwarding calls to [sink]. |
| - DelegatingEventSink(EventSink sink) : _sink = sink; |
| + DelegatingEventSink(EventSink<T> sink) : _sink = sink; |
| + |
| + DelegatingEventSink._(this._sink); |
| + |
| + /// Creates a wrapper that coerces the type of [sink]. |
| + /// |
| + /// Unlike [new DelegatingEventSink], this only requires its argument to be an |
| + /// instance of `EventSink`, not `EventSink<T>`. This means that calls to |
| + /// [add] may throw a [CastError] if the argument type doesn't match the |
| + /// reified type of [sink]. |
| + static EventSink/*<T>*/ typed/*<T>*/(EventSink sink) => |
| + sink is EventSink/*<T>*/ ? sink : new DelegatingEventSink._(sink); |
|
floitsch
2016/04/12 20:03:07
new DelegatingEventSink<T>
nweiz
2016/04/12 20:41:19
This is inferred from the return type.
floitsch
2016/04/14 13:59:45
Maybe, but that's non-intuitive, and it shouldn't
nweiz
2016/04/14 19:27:16
I think it's pretty intuitive. It's right there in
|
| void add(T data) { |
| _sink.add(data); |