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

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

Issue 2119733003: Wrapping leaf nodes in non polymer elements (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Converted vm-connect Created 4 years, 5 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/src/elements/helpers/tag.dart';
8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart';
9 import 'package:observatory/models.dart'
10 show ConnectionException;
11
12
13 class ExceptionRemoveEvent{
14 final Exception exception;
15 final StackTrace stacktrace;
16
17 ExceptionRemoveEvent(this.exception, {this.stacktrace});
18 }
19
20 class NavNotifyExceptionElement extends HtmlElement implements Renderable {
21 static const tag = const Tag<NavNotifyExceptionElement>('nav-exception');
22
23 RenderingScheduler _r;
24
25 Stream<RenderedEvent<NavNotifyExceptionElement>> get onRendered =>
26 _r.onRendered;
27
28 final StreamController<ExceptionRemoveEvent> _onRemove;
29 final Stream<ExceptionRemoveEvent> onRemove;
30
31 Exception _exception;
32 StackTrace _stacktrace;
33 Exception get exception => _exception;
34 StackTrace get stacktrace => _stacktrace;
35
36 factory NavNotifyExceptionElement(Exception exception,
37 {StackTrace stacktrace: null,
38 RenderingQueue queue}) {
39 assert(exception != null);
40 NavNotifyExceptionElement e = document.createElement(tag.name);
41 e._r = new RenderingScheduler(e, queue: queue);
42 e._exception = exception;
43 e._stacktrace = stacktrace;
44 return e;
45 }
46
47 NavNotifyExceptionElement.created()
48 : this._(new StreamController<ExceptionRemoveEvent>());
49
50 NavNotifyExceptionElement._(StreamController<ExceptionRemoveEvent> onRemove)
51 : super.created(),
52 this._onRemove = onRemove,
53 this.onRemove = onRemove.stream.asBroadcastStream();
54
55 @override
56 void attached() { super.attached(); _r.enable(); }
57
58 @override
59 void detached() { super.detached(); children = []; _r.disable(notify: true); }
60
61 void render() {
62 if (exception is ConnectionException) {
63 renderConnectionException();
64 } else {
65 renderGenericException();
66 }
67 }
68
69 void renderConnectionException() {
70 children = [
71 new DivElement()
72 ..children = [
73 new SpanElement()..text = 'The request cannot be completed because the '
74 'VM is currently disconnected',
75 new BRElement(), new BRElement(),
76 new SpanElement()..text = '[',
77 new AnchorElement(href: '#/vm-connect')
78 ..text = 'Connect to a different VM',
79 new SpanElement()..text = ']',
80 new ButtonElement()..innerHtml = '&times;'
81 ..onClick.map(_toEvent).listen(_remove)
82 ]
83 ];
84 }
85
86 void renderGenericException() {
87 List<Node> content;
88 content = [
89 new SpanElement()..text = 'Unexpected exception:',
90 new BRElement(), new BRElement(),
91 new DivElement()..text = exception.toString(),
92 new BRElement()
93 ];
94 if (stacktrace != null) {
95 content.addAll([
96 new SpanElement()..text = 'Stacktrace:',
97 new BRElement(), new BRElement(),
98 new DivElement()..text = stacktrace.toString(),
99 new BRElement()
100 ]);
101 }
102 content.addAll([
103 new SpanElement()..text = '[',
104 new AnchorElement(href: '#/vm-connect')
105 ..text = 'Connect to a different VM',
106 new SpanElement()..text = ']',
107 new ButtonElement()..innerHtml = '&times;'
108 ..onClick.map(_toEvent).listen(_remove)
109 ]);
110 children = [
111 new DivElement()
112 ..children = content
113 ];
114 }
115
116 ExceptionRemoveEvent _toEvent(_) {
117 return new ExceptionRemoveEvent(exception, stacktrace: stacktrace);
118 }
119
120 void _remove(ExceptionRemoveEvent e) {
121 if (_onRemove.hasListener) {
122 _onRemove.add(e);
123 }
124 }
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698