Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: runtime/observatory/lib/src/elements/nav/isolate_menu_wrapper.dart

Issue 2168463004: Converted Observatory isolate-nav-menu element (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merged with master Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:html';
6 import 'dart:async';
7
8 import 'package:observatory/app.dart';
9 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';
13 import 'package:observatory/src/elements/shims/binding.dart';
14 import 'package:observatory/src/elements/nav/isolate_menu.dart';
15
16 class NavIsolateMenuElementWrapper extends HtmlElement {
17 static final binder = new Binder<NavIsolateMenuElementWrapper>(
18 const [const Binding('last'), const Binding('isolate')]);
19
20 static const tag =
21 const Tag<NavIsolateMenuElementWrapper>('isolate-nav-menu');
22
23 final StreamController<M.IsolateUpdateEvent> _updatesController =
24 new StreamController<M.IsolateUpdateEvent>();
25 Stream<M.IsolateUpdateEvent> _updates;
26 StreamSubscription _subscription;
27
28 bool _last = false;
29 Isolate _isolate;
30 bool get last => _last;
31 Isolate get isolate => _isolate;
32 set last(bool value) {
33 _last = value; render();
34 }
35 set isolate(Isolate value) {
36 _isolate = value; _detached(); _attached();
37 }
38
39 NavIsolateMenuElementWrapper.created() : super.created() {
40 _updates = _updatesController.stream.asBroadcastStream();
41 binder.registerCallback(this);
42 _last = _getBoolAttribute('last');
43 createShadowRoot();
44 render();
45 }
46
47 @override
48 void attached() {
49 super.attached();
50 _attached();
51 }
52
53 @override
54 void detached() {
55 super.detached();
56 _detached();
57 }
58
59 void _attached() {
60 if (_isolate != null) {
61 _subscription = _isolate.changes.listen((_) {
62 _updatesController.add(new IsolateUpdateEventMock(isolate: isolate));
63 });
64 }
65 render();
66 }
67
68 void _detached() {
69 if (_subscription != null) {
70 _subscription.cancel();
71 _subscription = null;
72 }
73 }
74
75 void render() {
76 shadowRoot.children = [];
77 if (_isolate == null || _last == null) return;
78
79 shadowRoot.children = [
80 new NavIsolateMenuElement(isolate, _updates, last: last,
81 queue: ObservatoryApplication.app.queue)
82 ..children = [new ContentElement()]
83 ];
84 }
85
86 bool _getBoolAttribute(String name) {
87 final String value = getAttribute(name);
88 return !(value == null || value == 'false');
89 }
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698