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