OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, 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 import 'dart:html'; |
| 6 import 'dart:async'; |
| 7 |
| 8 import 'package:observatory/app.dart'; |
| 9 import 'package:observatory/models.dart' show IsolateUpdateEvent; |
| 10 import 'package:observatory/mocks.dart' show IsolateUpdateEventMock; |
| 11 import 'package:observatory/service_html.dart' show Isolate; |
| 12 import 'package:observatory/src/elements/isolate_ref.dart'; |
| 13 import 'package:observatory/src/elements/helpers/tag.dart'; |
| 14 import 'package:observatory/src/elements/shims/binding.dart'; |
| 15 |
| 16 class IsolateRefElementWrapper extends HtmlElement { |
| 17 |
| 18 static final binder = new Binder<IsolateRefElementWrapper>( |
| 19 const [const Binding('ref')]); |
| 20 |
| 21 static const tag = const Tag<IsolateRefElementWrapper>('isolate-ref'); |
| 22 |
| 23 final StreamController<IsolateUpdateEvent> _updatesController = |
| 24 new StreamController<IsolateUpdateEvent>(); |
| 25 Stream<IsolateUpdateEvent> _updates; |
| 26 StreamSubscription _subscription; |
| 27 |
| 28 Isolate _isolate; |
| 29 Isolate get ref => _isolate; |
| 30 void set ref(Isolate ref) { _isolate = ref; _detached(); _attached(); } |
| 31 |
| 32 IsolateRefElementWrapper.created() : super.created() { |
| 33 _updates = _updatesController.stream.asBroadcastStream(); |
| 34 binder.registerCallback(this); |
| 35 createShadowRoot(); |
| 36 render(); |
| 37 } |
| 38 |
| 39 @override |
| 40 void attached() { |
| 41 super.attached(); |
| 42 _attached(); |
| 43 } |
| 44 |
| 45 void _attached() { |
| 46 if (ref != null) { |
| 47 _subscription = ref.changes.listen((_) { |
| 48 _updatesController.add(new IsolateUpdateEventMock(isolate: ref)); |
| 49 }); |
| 50 } |
| 51 render(); |
| 52 } |
| 53 |
| 54 @override |
| 55 void detached() { |
| 56 super.detached(); |
| 57 _detached(); |
| 58 } |
| 59 |
| 60 void _detached() { |
| 61 if (_subscription != null) { |
| 62 _subscription.cancel(); |
| 63 _subscription = null; |
| 64 } |
| 65 } |
| 66 |
| 67 void render() { |
| 68 shadowRoot.children = []; |
| 69 if (ref == null) return; |
| 70 |
| 71 shadowRoot.children = [ |
| 72 new StyleElement() |
| 73 ..text = '@import "packages/observatory/src/elements/css/shared.css";', |
| 74 new IsolateRefElement(_isolate, _updates, |
| 75 queue: ObservatoryApplication.app.queue) |
| 76 ]; |
| 77 } |
| 78 } |
OLD | NEW |