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