blob: ef911fdad70fa7e4f591a2b5f6b9b7027b8ba87d [file] [log] [blame]
// Copyright (c) 2013, 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:async';
import 'package:observatory/models.dart' as M show Sentinel, SentinelKind;
import 'package:observatory/src/elements/helpers/rendering_scheduler.dart';
import 'package:observatory/src/elements/helpers/custom_element.dart';
class SentinelValueElement extends CustomElement implements Renderable {
late RenderingScheduler<SentinelValueElement> _r;
Stream<RenderedEvent<SentinelValueElement>> get onRendered => _r.onRendered;
late M.Sentinel _sentinel;
M.Sentinel get sentinel => _sentinel;
factory SentinelValueElement(M.Sentinel sentinel, {RenderingQueue? queue}) {
assert(sentinel != null);
SentinelValueElement e = new SentinelValueElement.created();
e._r = new RenderingScheduler<SentinelValueElement>(e, queue: queue);
e._sentinel = sentinel;
return e;
SentinelValueElement.created() : super.created('sentinel-value');
void attached() {
void detached() {
_r.disable(notify: true);
text = '';
title = '';
void render() {
text = _sentinel.valueAsString;
title = _sentinelKindToDescription(_sentinel.kind);
static String _sentinelKindToDescription(M.SentinelKind kind) {
switch (kind) {
case M.SentinelKind.collected:
return 'This object has been reclaimed by the garbage collector.';
case M.SentinelKind.expired:
return 'The handle to this object has expired. '
'Consider refreshing the page.';
case M.SentinelKind.notInitialized:
return 'This object will be initialized once it is accessed by '
'the program.';
case M.SentinelKind.initializing:
return 'This object is currently being initialized.';
case M.SentinelKind.optimizedOut:
return 'This object is no longer needed and has been removed by the '
'optimizing compiler.';
return '';
throw new Exception('Unknown SentinelKind: $kind');