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

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

Issue 2211603002: Centralized event streams (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merged with master Created 4 years, 4 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
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/mocks.dart';
10 import 'package:observatory/models.dart' as M;
11 import 'package:observatory/service.dart'; 8 import 'package:observatory/service.dart';
12 import 'package:observatory/service_common.dart'; 9 import 'package:observatory/service_common.dart';
13 import 'package:observatory/src/elements/helpers/tag.dart'; 10 import 'package:observatory/src/elements/helpers/tag.dart';
14 import 'package:observatory/src/elements/shims/binding.dart'; 11 import 'package:observatory/src/elements/shims/binding.dart';
15 import 'package:observatory/src/elements/nav/vm_menu.dart'; 12 import 'package:observatory/src/elements/nav/vm_menu.dart';
16 13
17 @bindable 14 @bindable
18 class NavVMMenuElementWrapper extends HtmlElement { 15 class NavVMMenuElementWrapper extends HtmlElement {
19 static const binder = const Binder<NavVMMenuElementWrapper>(const { 16 static const binder = const Binder<NavVMMenuElementWrapper>(const {
20 'last': #last, 'vm': #vm 17 'last': #last, 'vm': #vm
21 }); 18 });
22 19
23 static const tag = const Tag<NavVMMenuElementWrapper>('vm-nav-menu'); 20 static const tag = const Tag<NavVMMenuElementWrapper>('vm-nav-menu');
24 21
25 StreamSubscription _subscription;
26 StreamController<M.VMUpdateEvent> _updatesController =
27 new StreamController<M.VMUpdateEvent>.broadcast();
28
29 bool _last = false; 22 bool _last = false;
30 VM _vm; 23 VM _vm;
24
31 bool get last => _last; 25 bool get last => _last;
32 VM get vm => _vm; 26 VM get vm => _vm;
27
33 set last(bool value) { 28 set last(bool value) {
34 _last = value; render(); 29 _last = value;
35 } 30 render(); }
36 set vm(VM value) { 31 set vm(VM value) {
37 _vm = value; _detached(); _attached(); 32 _vm = value;
33 render();
38 } 34 }
39 35
40 NavVMMenuElementWrapper.created() : super.created() { 36 NavVMMenuElementWrapper.created() : super.created() {
41 binder.registerCallback(this); 37 binder.registerCallback(this);
42 _last = _getBoolAttribute('last'); 38 _last = _getBoolAttribute('last');
43 createShadowRoot(); 39 createShadowRoot();
44 render(); 40 render();
45 } 41 }
46 42
47 @override 43 @override
48 void attached() { 44 void attached() {
49 super.attached(); 45 super.attached();
50 _attached();
51 }
52
53 @override
54 void detached() {
55 super.detached();
56 _detached();
57 }
58
59 void _attached() {
60 if (_vm != null) {
61 _subscription = _vm.changes.listen((_) {
62 _updatesController.add(new VMUpdateEventMock(vm: _vm));
63 });
64 }
65 render(); 46 render();
66 } 47 }
67 48
68 void _detached() {
69 if (_subscription != null) {
70 _subscription.cancel();
71 _subscription = null;
72 }
73 }
74
75 void render() { 49 void render() {
76 shadowRoot.children = []; 50 shadowRoot.children = [];
77 if (_vm == null || _last == null) return; 51 if (_vm == null || _last == null) {
52 return;
53 }
78 54
79 shadowRoot.children = [ 55 shadowRoot.children = [
80 new NavVMMenuElement(vm, _updatesController.stream, last: last, 56 new NavVMMenuElement(vm, app.events, last: last,
81 target: (vm as CommonWebSocketVM)?.target, 57 queue: app.queue)
82 queue: ObservatoryApplication.app.queue)
83 ..children = [new ContentElement()] 58 ..children = [new ContentElement()]
84 ]; 59 ];
85 } 60 }
86 61
62 ObservatoryApplication get app => ObservatoryApplication.app;
63
87 bool _getBoolAttribute(String name) { 64 bool _getBoolAttribute(String name) {
88 final String value = getAttribute(name); 65 final String value = getAttribute(name);
89 return !(value == null || value == 'false'); 66 return !(value == null || value == 'false');
90 } 67 }
91 } 68 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/elements/nav/vm_menu.dart ('k') | runtime/observatory/lib/src/elements/script_ref.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698