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