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

Side by Side Diff: runtime/observatory/lib/src/elements/isolate_ref.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) 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 library isolate_ref_element; 5 library isolate_ref_element;
6 6
7 import 'dart:html'; 7 import 'dart:html';
8 import 'dart:async'; 8 import 'dart:async';
9 import 'package:observatory/models.dart' as M 9 import 'package:observatory/models.dart' as M
10 show IsolateRef, IsolateUpdateEvent; 10 show IsolateRef, EventRepository;
11 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; 11 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart';
12 import 'package:observatory/src/elements/helpers/tag.dart'; 12 import 'package:observatory/src/elements/helpers/tag.dart';
13 import 'package:observatory/src/elements/helpers/uris.dart'; 13 import 'package:observatory/src/elements/helpers/uris.dart';
14 14
15 class IsolateRefElement extends HtmlElement implements Renderable { 15 class IsolateRefElement extends HtmlElement implements Renderable {
16 static const tag = const Tag<IsolateRefElement>('isolate-ref-wrapped'); 16 static const tag = const Tag<IsolateRefElement>('isolate-ref-wrapped');
17 17
18 RenderingScheduler<IsolateRefElement> _r; 18 RenderingScheduler<IsolateRefElement> _r;
19 19
20 Stream<RenderedEvent<IsolateRefElement>> get onRendered => _r.onRendered; 20 Stream<RenderedEvent<IsolateRefElement>> get onRendered => _r.onRendered;
21 21
22 Stream<M.IsolateUpdateEvent> _updates; 22
23 M.IsolateRef _isolate;
24 M.EventRepository _events;
23 StreamSubscription _updatesSubscription; 25 StreamSubscription _updatesSubscription;
24 M.IsolateRef _isolate;
25 26
26 M.IsolateRef get isolate => _isolate; 27 M.IsolateRef get isolate => _isolate;
27 28
28 factory IsolateRefElement(M.IsolateRef isolate, 29 factory IsolateRefElement(M.IsolateRef isolate, M.EventRepository events,
29 Stream<M.IsolateUpdateEvent> updates, {RenderingQueue queue}) { 30 {RenderingQueue queue}) {
30 assert(isolate != null); 31 assert(isolate != null);
31 assert(updates != null); 32 assert(events != null);
32 IsolateRefElement e = document.createElement(tag.name); 33 IsolateRefElement e = document.createElement(tag.name);
33 e._r = new RenderingScheduler(e, queue: queue); 34 e._r = new RenderingScheduler(e, queue: queue);
34 e._isolate = isolate; 35 e._isolate = isolate;
35 e._updates = updates; 36 e._events = events;
36 return e; 37 return e;
37 } 38 }
38 39
39 IsolateRefElement.created() : super.created(); 40 IsolateRefElement.created() : super.created();
40 41
41 @override 42 @override
42 void attached() { 43 void attached() {
43 super.attached(); 44 super.attached();
44 assert(_isolate != null); 45 _updatesSubscription = _events.onIsolateUpdate
45 assert(_updates != null); 46 .where((e) => e.isolate.id == isolate.id)
47 .listen((e) { _isolate = e.isolate; _r.dirty(); });
46 _r.enable(); 48 _r.enable();
47 _updatesSubscription = _updates
48 .where((M.IsolateUpdateEvent e) => e.isolate.id == isolate.id)
49 .listen((M.IsolateUpdateEvent e) { _isolate = e.isolate; _r.dirty(); });
50 } 49 }
51 50
52 @override 51 @override
53 void detached() { 52 void detached() {
54 super.detached(); _r.disable(notify: true); 53 super.detached();
55 children = []; 54 children = [];
56 assert(_updatesSubscription != null); 55 _r.disable(notify: true);
57 _updatesSubscription.cancel(); 56 _updatesSubscription.cancel();
58 _updatesSubscription = null;
59 } 57 }
60 58
61 void render() { 59 void render() {
62 children = [ 60 children = [
63 new AnchorElement(href: Uris.inspect(isolate)) 61 new AnchorElement(href: Uris.inspect(isolate))
64 ..text = 'Isolate ${isolate.number} (${isolate.name})' 62 ..text = 'Isolate ${isolate.number} (${isolate.name})'
65 ..classes = ['isolate-ref'] 63 ..classes = ['isolate-ref']
66 ]; 64 ];
67 } 65 }
68 } 66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698