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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: runtime/observatory/lib/src/elements/nav/notify_exception.dart
diff --git a/runtime/observatory/lib/src/elements/nav/notify_exception.dart b/runtime/observatory/lib/src/elements/nav/notify_exception.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8e3e3758e56547f2b93618fa4c67988b0b809c44
--- /dev/null
+++ b/runtime/observatory/lib/src/elements/nav/notify_exception.dart
@@ -0,0 +1,125 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:html';
+import 'dart:async';
+import 'package:observatory/src/elements/helpers/tag.dart';
+import 'package:observatory/src/elements/helpers/rendering_scheduler.dart';
+import 'package:observatory/models.dart'
+ show ConnectionException;
+
+
+class ExceptionRemoveEvent{
+ final Exception exception;
+ final StackTrace stacktrace;
+
+ ExceptionRemoveEvent(this.exception, {this.stacktrace});
+}
+
+class NavNotifyExceptionElement extends HtmlElement implements Renderable {
+ static const tag = const Tag<NavNotifyExceptionElement>('nav-exception');
+
+ RenderingScheduler _r;
+
+ Stream<RenderedEvent<NavNotifyExceptionElement>> get onRendered =>
+ _r.onRendered;
+
+ final StreamController<ExceptionRemoveEvent> _onRemove;
+ final Stream<ExceptionRemoveEvent> onRemove;
+
+ Exception _exception;
+ StackTrace _stacktrace;
+ Exception get exception => _exception;
+ StackTrace get stacktrace => _stacktrace;
+
+ factory NavNotifyExceptionElement(Exception exception,
+ {StackTrace stacktrace: null,
+ RenderingQueue queue}) {
+ assert(exception != null);
+ NavNotifyExceptionElement e = document.createElement(tag.name);
+ e._r = new RenderingScheduler(e, queue: queue);
+ e._exception = exception;
+ e._stacktrace = stacktrace;
+ return e;
+ }
+
+ NavNotifyExceptionElement.created()
+ : this._(new StreamController<ExceptionRemoveEvent>());
+
+ NavNotifyExceptionElement._(StreamController<ExceptionRemoveEvent> onRemove)
+ : super.created(),
+ this._onRemove = onRemove,
+ this.onRemove = onRemove.stream.asBroadcastStream();
+
+ @override
+ void attached() { super.attached(); _r.enable(); }
+
+ @override
+ void detached() { super.detached(); children = []; _r.disable(notify: true); }
+
+ void render() {
+ if (exception is ConnectionException) {
+ renderConnectionException();
+ } else {
+ renderGenericException();
+ }
+ }
+
+ void renderConnectionException() {
+ children = [
+ new DivElement()
+ ..children = [
+ new SpanElement()..text = 'The request cannot be completed because the '
+ 'VM is currently disconnected',
+ new BRElement(), new BRElement(),
+ new SpanElement()..text = '[',
+ new AnchorElement(href: '#/vm-connect')
+ ..text = 'Connect to a different VM',
+ new SpanElement()..text = ']',
+ new ButtonElement()..innerHtml = '&times;'
+ ..onClick.map(_toEvent).listen(_remove)
+ ]
+ ];
+ }
+
+ void renderGenericException() {
+ List<Node> content;
+ content = [
+ new SpanElement()..text = 'Unexpected exception:',
+ new BRElement(), new BRElement(),
+ new DivElement()..text = exception.toString(),
+ new BRElement()
+ ];
+ if (stacktrace != null) {
+ content.addAll([
+ new SpanElement()..text = 'Stacktrace:',
+ new BRElement(), new BRElement(),
+ new DivElement()..text = stacktrace.toString(),
+ new BRElement()
+ ]);
+ }
+ content.addAll([
+ new SpanElement()..text = '[',
+ new AnchorElement(href: '#/vm-connect')
+ ..text = 'Connect to a different VM',
+ new SpanElement()..text = ']',
+ new ButtonElement()..innerHtml = '&times;'
+ ..onClick.map(_toEvent).listen(_remove)
+ ]);
+ children = [
+ new DivElement()
+ ..children = content
+ ];
+ }
+
+ ExceptionRemoveEvent _toEvent(_) {
+ return new ExceptionRemoveEvent(exception, stacktrace: stacktrace);
+ }
+
+ void _remove(ExceptionRemoveEvent e) {
+ if (_onRemove.hasListener) {
+ _onRemove.add(e);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698