| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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'; | 6 import 'dart:async'; |
| 7 import 'package:observatory/models.dart' as M; | 7 import 'package:observatory/models.dart' as M; |
| 8 import 'package:observatory/src/elements/curly_block.dart'; | 8 import 'package:observatory/src/elements/curly_block.dart'; |
| 9 import 'package:observatory/src/elements/instance_ref.dart'; | 9 import 'package:observatory/src/elements/instance_ref.dart'; |
| 10 import 'package:observatory/src/elements/helpers/any_ref.dart'; | 10 import 'package:observatory/src/elements/helpers/any_ref.dart'; |
| 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 | 13 |
| 14 class StronglyReachableInstancesElement extends HtmlElement | 14 class StronglyReachableInstancesElement extends HtmlElement |
| 15 implements Renderable { | 15 implements Renderable { |
| 16 static const tag = const Tag<StronglyReachableInstancesElement>( | 16 static const tag = const Tag<StronglyReachableInstancesElement>( |
| 17 'strongly-reachable-instances', | 17 'strongly-reachable-instances', |
| 18 dependencies: const [CurlyBlockElement.tag, InstanceRefElement.tag]); | 18 dependencies: const [CurlyBlockElement.tag, InstanceRefElement.tag]); |
| 19 | 19 |
| 20 RenderingScheduler<StronglyReachableInstancesElement> _r; | 20 RenderingScheduler<StronglyReachableInstancesElement> _r; |
| 21 | 21 |
| 22 Stream<RenderedEvent<StronglyReachableInstancesElement>> get onRendered => | 22 Stream<RenderedEvent<StronglyReachableInstancesElement>> get onRendered => |
| 23 _r.onRendered; | 23 _r.onRendered; |
| 24 | 24 |
| 25 M.IsolateRef _isolate; | 25 M.IsolateRef _isolate; |
| 26 M.ClassRef _cls; | 26 M.ClassRef _cls; |
| 27 M.StronglyReachableInstancesRepository _stronglyReachableInstances; | 27 M.StronglyReachableInstancesRepository _stronglyReachableInstances; |
| 28 M.InstanceRepository _instances; | 28 M.ObjectRepository _objects; |
| 29 M.InstanceSet _result; | 29 M.InstanceSet _result; |
| 30 bool _expanded = false; | 30 bool _expanded = false; |
| 31 | 31 |
| 32 M.IsolateRef get isolate => _isolate; | 32 M.IsolateRef get isolate => _isolate; |
| 33 M.ClassRef get cls => _cls; | 33 M.ClassRef get cls => _cls; |
| 34 | 34 |
| 35 factory StronglyReachableInstancesElement( | 35 factory StronglyReachableInstancesElement( |
| 36 M.IsolateRef isolate, | 36 M.IsolateRef isolate, |
| 37 M.ClassRef cls, | 37 M.ClassRef cls, |
| 38 M.StronglyReachableInstancesRepository stronglyReachable, | 38 M.StronglyReachableInstancesRepository stronglyReachable, |
| 39 M.InstanceRepository instances, | 39 M.ObjectRepository objects, |
| 40 {RenderingQueue queue}) { | 40 {RenderingQueue queue}) { |
| 41 assert(isolate != null); | 41 assert(isolate != null); |
| 42 assert(cls != null); | 42 assert(cls != null); |
| 43 assert(stronglyReachable != null); | 43 assert(stronglyReachable != null); |
| 44 assert(instances != null); | 44 assert(objects != null); |
| 45 StronglyReachableInstancesElement e = document.createElement(tag.name); | 45 StronglyReachableInstancesElement e = document.createElement(tag.name); |
| 46 e._r = new RenderingScheduler(e, queue: queue); | 46 e._r = new RenderingScheduler(e, queue: queue); |
| 47 e._isolate = isolate; | 47 e._isolate = isolate; |
| 48 e._cls = cls; | 48 e._cls = cls; |
| 49 e._stronglyReachableInstances = stronglyReachable; | 49 e._stronglyReachableInstances = stronglyReachable; |
| 50 e._instances = instances; | 50 e._objects = objects; |
| 51 return e; | 51 return e; |
| 52 } | 52 } |
| 53 | 53 |
| 54 StronglyReachableInstancesElement.created() : super.created(); | 54 StronglyReachableInstancesElement.created() : super.created(); |
| 55 | 55 |
| 56 @override | 56 @override |
| 57 void attached() { | 57 void attached() { |
| 58 super.attached(); | 58 super.attached(); |
| 59 _r.enable(); | 59 _r.enable(); |
| 60 } | 60 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 84 _result = await _stronglyReachableInstances.get(_isolate, _cls); | 84 _result = await _stronglyReachableInstances.get(_isolate, _cls); |
| 85 _r.dirty(); | 85 _r.dirty(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 List<Element> _createContent() { | 88 List<Element> _createContent() { |
| 89 if (_result == null) { | 89 if (_result == null) { |
| 90 return [new SpanElement()..text = 'Loading...']; | 90 return [new SpanElement()..text = 'Loading...']; |
| 91 } | 91 } |
| 92 final content = _result.samples | 92 final content = _result.samples |
| 93 .map((sample) => new DivElement() | 93 .map((sample) => new DivElement() |
| 94 ..children = [anyRef(_isolate, sample, _instances, queue: _r.queue)]) | 94 ..children = [anyRef(_isolate, sample, _objects, queue: _r.queue)]) |
| 95 .toList(); | 95 .toList(); |
| 96 content.add(new DivElement() | 96 content.add(new DivElement() |
| 97 ..children = ([] | 97 ..children = ([] |
| 98 ..addAll(_createShowMoreButton()) | 98 ..addAll(_createShowMoreButton()) |
| 99 ..add(new SpanElement()..text = ' of total ${_result.count}'))); | 99 ..add(new SpanElement()..text = ' of total ${_result.count}'))); |
| 100 return content; | 100 return content; |
| 101 } | 101 } |
| 102 | 102 |
| 103 List<Element> _createShowMoreButton() { | 103 List<Element> _createShowMoreButton() { |
| 104 final samples = _result.samples.toList(); | 104 final samples = _result.samples.toList(); |
| 105 if (samples.length == _result.count) { | 105 if (samples.length == _result.count) { |
| 106 return []; | 106 return []; |
| 107 } | 107 } |
| 108 final count = samples.length; | 108 final count = samples.length; |
| 109 final button = new ButtonElement()..text = 'show next ${count}'; | 109 final button = new ButtonElement()..text = 'show next ${count}'; |
| 110 button.onClick.listen((_) async { | 110 button.onClick.listen((_) async { |
| 111 button.disabled = true; | 111 button.disabled = true; |
| 112 _result = await _stronglyReachableInstances.get(_isolate, _cls, | 112 _result = await _stronglyReachableInstances.get(_isolate, _cls, |
| 113 limit: count * 2); | 113 limit: count * 2); |
| 114 _r.dirty(); | 114 _r.dirty(); |
| 115 }); | 115 }); |
| 116 return [button]; | 116 return [button]; |
| 117 } | 117 } |
| 118 } | 118 } |
| OLD | NEW |