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 show IsolateRef, ClassRef; | 7 import 'package:observatory/models.dart' as M show IsolateRef, ClassRef; |
| 8 import 'package:observatory/src/elements/helpers/nav_menu.dart'; |
8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | 9 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
9 import 'package:observatory/src/elements/helpers/tag.dart'; | 10 import 'package:observatory/src/elements/helpers/tag.dart'; |
10 import 'package:observatory/src/elements/helpers/uris.dart'; | 11 import 'package:observatory/src/elements/helpers/uris.dart'; |
11 import 'package:observatory/src/elements/nav/menu.dart'; | |
12 | 12 |
13 class NavClassMenuElement extends HtmlElement implements Renderable { | 13 class NavClassMenuElement extends HtmlElement implements Renderable { |
14 static const tag = const Tag<NavClassMenuElement>('nav-class-menu', | 14 static const tag = const Tag<NavClassMenuElement>('nav-class-menu'); |
15 dependencies: const [NavMenuElement.tag]); | |
16 | 15 |
17 RenderingScheduler _r; | 16 RenderingScheduler _r; |
18 | 17 |
19 Stream<RenderedEvent<NavClassMenuElement>> get onRendered => _r.onRendered; | 18 Stream<RenderedEvent<NavClassMenuElement>> get onRendered => _r.onRendered; |
20 | 19 |
21 bool _last; | |
22 M.IsolateRef _isolate; | 20 M.IsolateRef _isolate; |
23 M.ClassRef _cls; | 21 M.ClassRef _cls; |
24 bool get last => _last; | 22 Iterable<Element> _content = const []; |
| 23 |
25 M.IsolateRef get isolate => _isolate; | 24 M.IsolateRef get isolate => _isolate; |
26 M.ClassRef get cls => _cls; | 25 M.ClassRef get cls => _cls; |
27 set last(bool value) => _last = _r.checkAndReact(_last, value); | 26 Iterable<Element> get content => _content; |
| 27 |
| 28 set content(Iterable<Element> value) { |
| 29 _content = value.toList(); |
| 30 _r.dirty(); |
| 31 } |
28 | 32 |
29 factory NavClassMenuElement(M.IsolateRef isolate, M.ClassRef cls, | 33 factory NavClassMenuElement(M.IsolateRef isolate, M.ClassRef cls, |
30 {bool last: false, RenderingQueue queue}) { | 34 {RenderingQueue queue}) { |
31 assert(isolate != null); | 35 assert(isolate != null); |
32 assert(cls != null); | 36 assert(cls != null); |
33 assert(last != null); | |
34 NavClassMenuElement e = document.createElement(tag.name); | 37 NavClassMenuElement e = document.createElement(tag.name); |
35 e._r = new RenderingScheduler(e, queue: queue); | 38 e._r = new RenderingScheduler(e, queue: queue); |
36 e._isolate = isolate; | 39 e._isolate = isolate; |
37 e._cls = cls; | 40 e._cls = cls; |
38 e._last = last; | |
39 return e; | 41 return e; |
40 } | 42 } |
41 | 43 |
42 NavClassMenuElement.created() : super.created() { createShadowRoot(); } | 44 NavClassMenuElement.created() : super.created(); |
43 | 45 |
44 @override | 46 @override |
45 void attached() { | 47 void attached() { |
46 super.attached(); | 48 super.attached(); |
47 _r.enable(); | 49 _r.enable(); |
48 } | 50 } |
49 | 51 |
50 @override | 52 @override |
51 void detached() { | 53 void detached() { |
52 super.detached(); | 54 super.detached(); |
| 55 children = []; |
53 _r.disable(notify: true); | 56 _r.disable(notify: true); |
54 shadowRoot.children = []; | |
55 } | 57 } |
56 | 58 |
57 void render() { | 59 void render() { |
58 shadowRoot.children = [ | 60 children = [ |
59 new NavMenuElement(cls.name, last: last, queue: _r.queue, | 61 navMenu(cls.name, content: _content, |
60 link: Uris.inspect(isolate, object: cls)) | 62 link: Uris.inspect(isolate, object: cls)) |
61 ..children = [new ContentElement()] | |
62 ]; | 63 ]; |
63 } | 64 } |
64 } | 65 } |
OLD | NEW |