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

Side by Side Diff: runtime/observatory/lib/src/elements/inbound_references.dart

Issue 2265513003: Converted Observatory object-common element (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Addressed comments 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:html';
6 import 'dart:async';
7 import 'package:observatory/models.dart' as M;
8 import 'package:observatory/src/elements/curly_block.dart';
9 import 'package:observatory/src/elements/instance_ref.dart';
10 import 'package:observatory/src/elements/helpers/any_ref.dart';
11 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart';
12 import 'package:observatory/src/elements/helpers/tag.dart';
13
14 class InboundReferencesElement extends HtmlElement implements Renderable {
15 static const tag = const Tag<InboundReferencesElement>('inbound-references',
16 dependencies: const [
17 CurlyBlockElement.tag,
18 InstanceRefElement.tag
19 ]);
20
21 RenderingScheduler<InboundReferencesElement> _r;
22
23 Stream<RenderedEvent<InboundReferencesElement>> get onRendered =>
24 _r.onRendered;
25
26 M.IsolateRef _isolate;
27 M.ObjectRef _object;
28 M.InboundReferencesRepository _references;
29 M.InstanceRepository _instances;
30 M.InboundReferences _inbounds;
31 bool _expanded = false;
32
33 M.IsolateRef get isolate => _isolate;
34 M.ObjectRef get object => _object;
35
36 factory InboundReferencesElement(M.IsolateRef isolate, M.ObjectRef object,
37 M.InboundReferencesRepository references, M.InstanceRepository instances,
38 {RenderingQueue queue}) {
39 assert(isolate != null);
40 assert(object != null);
41 assert(references != null);
42 assert(instances != null);
43 InboundReferencesElement e = document.createElement(tag.name);
44 e._r = new RenderingScheduler(e, queue: queue);
45 e._isolate = isolate;
46 e._object = object;
47 e._references = references;
48 e._instances = instances;
49 return e;
50 }
51
52 InboundReferencesElement.created() : super.created();
53
54 @override
55 void attached() {
56 super.attached();
57 _r.enable();
58 }
59
60 @override
61 void detached() {
62 super.detached();
63 children = [];
64 _r.disable(notify: true);
65 }
66
67 void render() {
68 children = [
69 new CurlyBlockElement(expanded: _expanded, queue: _r.queue)
70 ..children = _createContent()
71 ..onToggle.listen((e) async {
72 _expanded = e.control.expanded;
73 if (_expanded) {
74 e.control.disabled = true;
75 await _refresh();
76 e.control.disabled = false;
77 }
78 })
79 ];
80 }
81
82 Future _refresh() async {
83 _inbounds = await _references.get(_isolate, _object.id);
84 _r.dirty();
85 }
86
87 List<Element> _createContent() {
88 if (_inbounds == null) {
89 return const [];
90 }
91 return _inbounds.elements.map(_createItem).toList();
92 }
93
94 Element _createItem(M.InboundReference reference) {
95 final content = <Element>[];
96
97 if (reference.parentField != null) {
98 content.addAll([
99 new SpanElement()..text = 'from ',
100 anyRef(_isolate, reference.parentField, _instances,
101 queue: _r.queue),
102 new SpanElement()..text = ' of '
103 ]);
104 } else if (reference.parentListIndex != null) {
105 content.add(
106 new SpanElement()
107 ..text = 'from [ ${reference.parentListIndex} ] of '
108 );
109 } else if (reference.parentWordOffset != null) {
110 content.add(
111 new SpanElement()
112 ..text = 'from word [ ${reference.parentWordOffset} ] of '
113 );
114 }
115
116 content.addAll([
117 anyRef(_isolate, reference.source, _instances, queue: _r.queue),
118 new SpanElement()..text = ' referenced by ',
119 new InboundReferencesElement(_isolate, reference.source, _references,
120 _instances, queue: _r.queue )
121 ]);
122
123 return new DivElement()..classes = ['indent']..children = content;
124 }
125 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/elements/inbound_reference.html ('k') | runtime/observatory/lib/src/elements/instance_view.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698