Chromium Code Reviews| Index: runtime/observatory/lib/src/elements/isolate_ref_wrapper.dart |
| diff --git a/runtime/observatory/lib/src/elements/isolate_ref_wrapper.dart b/runtime/observatory/lib/src/elements/isolate_ref_wrapper.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e07ce56fd9985d0ba0c9f5e0f35ec9bb994a307b |
| --- /dev/null |
| +++ b/runtime/observatory/lib/src/elements/isolate_ref_wrapper.dart |
| @@ -0,0 +1,72 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import 'dart:html'; |
| +import 'dart:async'; |
| +import 'package:observatory/service_html.dart' show Isolate; |
| +import 'package:observatory/repositories.dart' show IsolateUpdateEvent; |
| +import 'shims/binding.dart'; |
| +import 'helpers/tag.dart'; |
| +import 'isolate_ref.dart'; |
| + |
| +class IsolateRefElementWrapper extends HtmlElement { |
| + |
| + static final binder = new Binder<IsolateRefElementWrapper>( |
| + const [const Binding('ref')]); |
| + |
| + static const tag = const Tag<IsolateRefElementWrapper>('isolate-ref'); |
| + |
| + final StreamController<IsolateUpdateEvent> _updatesController = |
| + new StreamController<IsolateUpdateEvent>(); |
| + Stream<IsolateUpdateEvent> _updates; |
| + StreamSubscription _subscription; |
| + |
| + Isolate _isolate; |
| + Isolate get ref => _isolate; |
| + void set ref(Isolate ref) { _isolate = ref; _detached(); _attached(); } |
| + |
| + IsolateRefElementWrapper.created() : super.created() { |
| + _updates = _updatesController.stream.asBroadcastStream(); |
| + binder.registerCallback(this); |
| + createShadowRoot(); |
| + render(); |
| + } |
| + |
| + @override |
| + void attached() { |
| + super.attached(); |
| + _attached(); |
| + } |
| + |
| + void _attached() { |
| + if (ref != null) { |
| + _subscription = ref.changes.listen((_) { |
| + _updatesController.add(new IsolateUpdateEvent(ref)); |
|
Cutch
2016/07/07 19:50:57
This pattern is going to appear often. Maybe subsc
cbernaschina
2016/07/07 22:08:13
Working on it.
|
| + }); |
| + } |
| + render(); |
| + } |
| + |
| + @override |
| + void detached() { |
| + super.detached(); |
| + _detached(); |
| + } |
| + |
| + void _detached() { |
| + if (_subscription != null) { |
| + _subscription.cancel(); |
| + _subscription = null; |
| + } |
| + } |
| + |
| + void render() { |
| + shadowRoot.children = []; |
| + if (ref == null) return; |
| + |
| + shadowRoot.children = [ |
| + new IsolateRefElement(_isolate, _updates) |
| + ]; |
| + } |
| +} |