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

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

Issue 2211603002: Centralized event streams (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Updated observatory_sources 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/models.dart' show IsolateUpdateEvent;
10 import 'package:observatory/mocks.dart' show IsolateUpdateEventMock;
11 import 'package:observatory/service_html.dart' show Isolate; 8 import 'package:observatory/service_html.dart' show Isolate;
12 import 'package:observatory/src/elements/isolate_ref.dart'; 9 import 'package:observatory/src/elements/isolate_ref.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 12
16 @bindable 13 @bindable
17 class IsolateRefElementWrapper extends HtmlElement { 14 class IsolateRefElementWrapper extends HtmlElement {
18 15
19 static const binder = const Binder<IsolateRefElementWrapper>(const { 16 static const binder = const Binder<IsolateRefElementWrapper>(const {
20 'ref': #ref 17 'ref': #ref
21 }); 18 });
22 19
23 static const tag = const Tag<IsolateRefElementWrapper>('isolate-ref'); 20 static const tag = const Tag<IsolateRefElementWrapper>('isolate-ref');
24 21
25 final StreamController<IsolateUpdateEvent> _updatesController = 22 Isolate _isolate;
26 new StreamController<IsolateUpdateEvent>();
27 Stream<IsolateUpdateEvent> _updates;
28 StreamSubscription _subscription;
29 23
30 Isolate _isolate;
31 Isolate get ref => _isolate; 24 Isolate get ref => _isolate;
32 void set ref(Isolate ref) { _isolate = ref; _detached(); _attached(); } 25
26 void set ref(Isolate ref) { _isolate = ref; render(); }
33 27
34 IsolateRefElementWrapper.created() : super.created() { 28 IsolateRefElementWrapper.created() : super.created() {
35 _updates = _updatesController.stream.asBroadcastStream();
36 binder.registerCallback(this); 29 binder.registerCallback(this);
37 createShadowRoot(); 30 createShadowRoot();
38 render(); 31 render();
39 } 32 }
40 33
41 @override 34 @override
42 void attached() { 35 void attached() {
43 super.attached(); 36 super.attached();
44 _attached();
45 }
46
47 void _attached() {
48 if (ref != null) {
49 _subscription = ref.changes.listen((_) {
50 _updatesController.add(new IsolateUpdateEventMock(isolate: ref));
51 });
52 }
53 render(); 37 render();
54 } 38 }
55 39
56 @override
57 void detached() {
58 super.detached();
59 _detached();
60 }
61
62 void _detached() {
63 if (_subscription != null) {
64 _subscription.cancel();
65 _subscription = null;
66 }
67 }
68
69 void render() { 40 void render() {
70 shadowRoot.children = []; 41 shadowRoot.children = [];
71 if (ref == null) return; 42 if (ref == null) return;
72 43
73 shadowRoot.children = [ 44 shadowRoot.children = [
74 new StyleElement() 45 new StyleElement()
75 ..text = ''' 46 ..text = '''
76 isolate-ref-wrapped > a[href]:hover { 47 isolate-ref-wrapped > a[href]:hover {
77 text-decoration: underline; 48 text-decoration: underline;
78 } 49 }
79 isolate-ref-wrapped > a[href] { 50 isolate-ref-wrapped > a[href] {
80 color: #0489c3; 51 color: #0489c3;
81 text-decoration: none; 52 text-decoration: none;
82 }''', 53 }''',
83 new IsolateRefElement(_isolate, _updates, 54 new IsolateRefElement(_isolate, app.events, queue: app.queue)
84 queue: ObservatoryApplication.app.queue)
85 ]; 55 ];
86 } 56 }
57
58 ObservatoryApplication get app => ObservatoryApplication.app;
87 } 59 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698