OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:html'; | 5 import 'dart:html'; |
6 import 'dart:async'; | |
7 | 6 |
8 import 'package:observatory/app.dart'; | 7 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; | 8 import 'package:observatory/service_html.dart' show Isolate; |
12 import 'package:observatory/src/elements/isolate_ref.dart'; | 9 import 'package:observatory/src/elements/isolate_ref.dart'; |
13 import 'package:observatory/src/elements/helpers/tag.dart'; | 10 import 'package:observatory/src/elements/helpers/tag.dart'; |
14 import 'package:observatory/src/elements/shims/binding.dart'; | 11 import 'package:observatory/src/elements/shims/binding.dart'; |
15 | 12 |
16 @bindable | 13 @bindable |
17 class IsolateRefElementWrapper extends HtmlElement { | 14 class IsolateRefElementWrapper extends HtmlElement { |
18 | 15 |
19 static const binder = const Binder<IsolateRefElementWrapper>(const { | 16 static const binder = const Binder<IsolateRefElementWrapper>(const { |
20 'ref': #ref | 17 'ref': #ref |
21 }); | 18 }); |
22 | 19 |
23 static const tag = const Tag<IsolateRefElementWrapper>('isolate-ref'); | 20 static const tag = const Tag<IsolateRefElementWrapper>('isolate-ref'); |
24 | 21 |
25 final StreamController<IsolateUpdateEvent> _updatesController = | 22 Isolate _isolate; |
26 new StreamController<IsolateUpdateEvent>(); | |
27 Stream<IsolateUpdateEvent> _updates; | |
28 StreamSubscription _subscription; | |
29 | 23 |
30 Isolate _isolate; | |
31 Isolate get ref => _isolate; | 24 Isolate get ref => _isolate; |
32 void set ref(Isolate ref) { _isolate = ref; _detached(); _attached(); } | 25 |
| 26 void set ref(Isolate value) { |
| 27 _isolate = value; |
| 28 render(); |
| 29 } |
33 | 30 |
34 IsolateRefElementWrapper.created() : super.created() { | 31 IsolateRefElementWrapper.created() : super.created() { |
35 _updates = _updatesController.stream.asBroadcastStream(); | |
36 binder.registerCallback(this); | 32 binder.registerCallback(this); |
37 createShadowRoot(); | 33 createShadowRoot(); |
38 render(); | 34 render(); |
39 } | 35 } |
40 | 36 |
41 @override | 37 @override |
42 void attached() { | 38 void attached() { |
43 super.attached(); | 39 super.attached(); |
44 _attached(); | |
45 } | |
46 | |
47 void _attached() { | |
48 if (ref != null) { | |
49 _subscription = ref.changes.listen((_) { | |
50 _updatesController.add(new IsolateUpdateEventMock(isolate: ref)); | |
51 }); | |
52 } | |
53 render(); | 40 render(); |
54 } | 41 } |
55 | 42 |
56 @override | |
57 void detached() { | |
58 super.detached(); | |
59 _detached(); | |
60 } | |
61 | |
62 void _detached() { | |
63 if (_subscription != null) { | |
64 _subscription.cancel(); | |
65 _subscription = null; | |
66 } | |
67 } | |
68 | |
69 void render() { | 43 void render() { |
70 shadowRoot.children = []; | 44 shadowRoot.children = []; |
71 if (ref == null) return; | 45 if (ref == null) { |
| 46 return; |
| 47 } |
72 | 48 |
73 shadowRoot.children = [ | 49 shadowRoot.children = [ |
74 new StyleElement() | 50 new StyleElement() |
75 ..text = ''' | 51 ..text = ''' |
76 isolate-ref-wrapped > a[href]:hover { | 52 isolate-ref-wrapped > a[href]:hover { |
77 text-decoration: underline; | 53 text-decoration: underline; |
78 } | 54 } |
79 isolate-ref-wrapped > a[href] { | 55 isolate-ref-wrapped > a[href] { |
80 color: #0489c3; | 56 color: #0489c3; |
81 text-decoration: none; | 57 text-decoration: none; |
82 }''', | 58 }''', |
83 new IsolateRefElement(_isolate, _updates, | 59 new IsolateRefElement(_isolate, app.events, queue: app.queue) |
84 queue: ObservatoryApplication.app.queue) | |
85 ]; | 60 ]; |
86 } | 61 } |
| 62 |
| 63 ObservatoryApplication get app => ObservatoryApplication.app; |
87 } | 64 } |
OLD | NEW |