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'; | 6 import 'dart:async'; |
7 import 'package:observatory/models.dart' as M | 7 import 'package:observatory/models.dart' as M |
8 show VM, IsolateRef, Target, VMUpdateEvent; | 8 show VM, EventRepository; |
9 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | 9 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
10 import 'package:observatory/src/elements/helpers/tag.dart'; | 10 import 'package:observatory/src/elements/helpers/tag.dart'; |
11 import 'package:observatory/src/elements/helpers/uris.dart'; | 11 import 'package:observatory/src/elements/helpers/uris.dart'; |
12 import 'package:observatory/src/elements/nav/menu.dart'; | 12 import 'package:observatory/src/elements/nav/menu.dart'; |
13 import 'package:observatory/src/elements/nav/menu_item.dart'; | 13 import 'package:observatory/src/elements/nav/menu_item.dart'; |
14 | 14 |
15 class NavVMMenuElement extends HtmlElement implements Renderable { | 15 class NavVMMenuElement extends HtmlElement implements Renderable { |
16 static const tag = const Tag<NavVMMenuElement>('nav-vm-menu', | 16 static const tag = const Tag<NavVMMenuElement>('nav-vm-menu', |
17 dependencies: const [NavMenuElement.tag, | 17 dependencies: const [NavMenuElement.tag, |
18 NavMenuItemElement.tag]); | 18 NavMenuItemElement.tag]); |
19 | 19 |
20 RenderingScheduler _r; | 20 RenderingScheduler _r; |
21 | 21 |
22 Stream<RenderedEvent<NavVMMenuElement>> get onRendered => _r.onRendered; | 22 Stream<RenderedEvent<NavVMMenuElement>> get onRendered => _r.onRendered; |
23 | 23 |
24 Stream<M.VMUpdateEvent> _updates; | 24 bool _last; |
| 25 M.VM _vm; |
| 26 M.EventRepository _events; |
25 StreamSubscription _updatesSubscription; | 27 StreamSubscription _updatesSubscription; |
26 | 28 |
27 bool _last; | 29 |
28 M.VM _vm; | |
29 M.Target _target; | |
30 bool get last => _last; | 30 bool get last => _last; |
31 M.VM get vm => _vm; | 31 M.VM get vm => _vm; |
32 M.Target get target => _target; | 32 |
33 set last(bool value) => _last = _r.checkAndReact(_last, value); | 33 set last(bool value) => _last = _r.checkAndReact(_last, value); |
34 | 34 |
35 factory NavVMMenuElement(M.VM vm, Stream<M.VMUpdateEvent> updates, | 35 factory NavVMMenuElement(M.VM vm, M.EventRepository events, {bool last: false, |
36 {bool last: false, M.Target target, RenderingQueue queue}) { | 36 RenderingQueue queue}) { |
37 assert(vm != null); | 37 assert(vm != null); |
38 assert(updates != null); | 38 assert(events != null); |
39 assert(last != null); | 39 assert(last != null); |
40 NavVMMenuElement e = document.createElement(tag.name); | 40 NavVMMenuElement e = document.createElement(tag.name); |
41 e._r = new RenderingScheduler(e, queue: queue); | 41 e._r = new RenderingScheduler(e, queue: queue); |
42 e._vm = vm; | 42 e._vm = vm; |
43 e._updates = updates; | 43 e._events = events; |
44 e._last = last; | 44 e._last = last; |
45 e._target = target; | |
46 return e; | 45 return e; |
47 } | 46 } |
48 | 47 |
49 NavVMMenuElement.created() : super.created() { createShadowRoot(); } | 48 NavVMMenuElement.created() : super.created() { createShadowRoot(); } |
50 | 49 |
51 @override | 50 @override |
52 void attached() { | 51 void attached() { |
53 super.attached(); | 52 super.attached(); |
| 53 _updatesSubscription = _events.onVMUpdate |
| 54 .listen((e) { _vm = e.vm; _r.dirty(); }); |
54 _r.enable(); | 55 _r.enable(); |
55 _updatesSubscription = _updates | |
56 .listen((M.VMUpdateEvent e) { _vm = e.vm; _r.dirty(); }); | |
57 } | 56 } |
58 | 57 |
59 @override | 58 @override |
60 void detached() { | 59 void detached() { |
61 super.detached(); | 60 super.detached(); |
| 61 shadowRoot.children = []; |
62 _r.disable(notify: true); | 62 _r.disable(notify: true); |
63 shadowRoot.children = []; | |
64 assert(_updatesSubscription != null); | |
65 _updatesSubscription.cancel(); | 63 _updatesSubscription.cancel(); |
66 _updatesSubscription = null; | |
67 } | 64 } |
68 | 65 |
69 void render() { | 66 void render() { |
70 final String name = (target == null) ? vm.name | |
71 : '${vm.name}@${target.name}'; | |
72 /// TODO(cbernaschina) use the isolate repository. | |
73 shadowRoot.children = [ | 67 shadowRoot.children = [ |
74 new NavMenuElement(name, link: Uris.vm(), last: last, queue: _r.queue) | 68 new NavMenuElement(vm.displayName, link: Uris.vm(), last: last, |
| 69 queue: _r.queue) |
75 ..children = ( | 70 ..children = ( |
76 _vm.isolates.map((M.IsolateRef isolate) { | 71 _vm.isolates.map((isolate) { |
77 return new NavMenuItemElement(isolate.name, queue: _r.queue, | 72 return new NavMenuItemElement(isolate.name, queue: _r.queue, |
78 link: Uris.inspect(isolate)); | 73 link: Uris.inspect(isolate)); |
79 }).toList() | 74 }).toList() |
80 ..add(new ContentElement()) | 75 ..add(new ContentElement()) |
81 ) | 76 ) |
82 ]; | 77 ]; |
83 } | 78 } |
84 } | 79 } |
OLD | NEW |