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