OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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/service.dart'; | 8 import 'package:observatory/service.dart'; |
10 import 'package:observatory/mocks.dart'; | |
11 import 'package:observatory/models.dart' as M; | |
12 import 'package:observatory/src/elements/helpers/tag.dart'; | 9 import 'package:observatory/src/elements/helpers/tag.dart'; |
13 import 'package:observatory/src/elements/shims/binding.dart'; | 10 import 'package:observatory/src/elements/shims/binding.dart'; |
14 import 'package:observatory/src/elements/nav/isolate_menu.dart'; | 11 import 'package:observatory/src/elements/nav/isolate_menu.dart'; |
15 | 12 |
16 @bindable | 13 @bindable |
17 class NavIsolateMenuElementWrapper extends HtmlElement { | 14 class NavIsolateMenuElementWrapper extends HtmlElement { |
18 static const binder = const Binder<NavIsolateMenuElementWrapper>(const { | 15 static const binder = const Binder<NavIsolateMenuElementWrapper>(const { |
19 'last': #last, 'isolate': #isolate | 16 'last': #last, 'isolate': #isolate |
20 }); | 17 }); |
21 | 18 |
22 static const tag = | 19 static const tag = |
23 const Tag<NavIsolateMenuElementWrapper>('isolate-nav-menu'); | 20 const Tag<NavIsolateMenuElementWrapper>('isolate-nav-menu'); |
24 | 21 |
25 final StreamController<M.IsolateUpdateEvent> _updatesController = | |
26 new StreamController<M.IsolateUpdateEvent>(); | |
27 Stream<M.IsolateUpdateEvent> _updates; | |
28 StreamSubscription _subscription; | |
29 | |
30 bool _last = false; | 22 bool _last = false; |
31 Isolate _isolate; | 23 Isolate _isolate; |
| 24 |
32 bool get last => _last; | 25 bool get last => _last; |
33 Isolate get isolate => _isolate; | 26 Isolate get isolate => _isolate; |
| 27 |
34 set last(bool value) { | 28 set last(bool value) { |
35 _last = value; render(); | 29 _last = value; |
| 30 render(); |
36 } | 31 } |
37 set isolate(Isolate value) { | 32 set isolate(Isolate value) { |
38 _isolate = value; _detached(); _attached(); | 33 _isolate = value; |
| 34 render(); |
39 } | 35 } |
40 | 36 |
41 NavIsolateMenuElementWrapper.created() : super.created() { | 37 NavIsolateMenuElementWrapper.created() : super.created() { |
42 _updates = _updatesController.stream.asBroadcastStream(); | |
43 binder.registerCallback(this); | 38 binder.registerCallback(this); |
44 _last = _getBoolAttribute('last'); | 39 _last = _getBoolAttribute('last'); |
45 createShadowRoot(); | 40 createShadowRoot(); |
46 render(); | 41 render(); |
47 } | 42 } |
48 | 43 |
49 @override | 44 @override |
50 void attached() { | 45 void attached() { |
51 super.attached(); | 46 super.attached(); |
52 _attached(); | |
53 } | |
54 | |
55 @override | |
56 void detached() { | |
57 super.detached(); | |
58 _detached(); | |
59 } | |
60 | |
61 void _attached() { | |
62 if (_isolate != null) { | |
63 _subscription = _isolate.changes.listen((_) { | |
64 _updatesController.add(new IsolateUpdateEventMock(isolate: isolate)); | |
65 }); | |
66 } | |
67 render(); | 47 render(); |
68 } | 48 } |
69 | 49 |
70 void _detached() { | |
71 if (_subscription != null) { | |
72 _subscription.cancel(); | |
73 _subscription = null; | |
74 } | |
75 } | |
76 | |
77 void render() { | 50 void render() { |
78 shadowRoot.children = []; | 51 shadowRoot.children = []; |
79 if (_isolate == null || _last == null) return; | 52 if (_isolate == null || _last == null) { |
| 53 return; |
| 54 } |
80 | 55 |
81 shadowRoot.children = [ | 56 shadowRoot.children = [ |
82 new NavIsolateMenuElement(isolate, _updates, last: last, | 57 new NavIsolateMenuElement(_isolate, app.events, last: _last, |
83 queue: ObservatoryApplication.app.queue) | 58 queue: app.queue) |
84 ..children = [new ContentElement()] | 59 ..children = [new ContentElement()] |
85 ]; | 60 ]; |
86 } | 61 } |
87 | 62 |
| 63 ObservatoryApplication get app => ObservatoryApplication.app; |
| 64 |
88 bool _getBoolAttribute(String name) { | 65 bool _getBoolAttribute(String name) { |
89 final String value = getAttribute(name); | 66 final String value = getAttribute(name); |
90 return !(value == null || value == 'false'); | 67 return !(value == null || value == 'false'); |
91 } | 68 } |
92 } | 69 } |
OLD | NEW |