| Index: runtime/bin/vmservice/client/lib/src/elements/observatory_element.dart
|
| diff --git a/runtime/bin/vmservice/client/lib/src/elements/observatory_element.dart b/runtime/bin/vmservice/client/lib/src/elements/observatory_element.dart
|
| index 510290158456b3774bb91ed0e8bb8d190d6f02d2..b53e7cf2b7221f51f120a1a92b724a8986820d46 100644
|
| --- a/runtime/bin/vmservice/client/lib/src/elements/observatory_element.dart
|
| +++ b/runtime/bin/vmservice/client/lib/src/elements/observatory_element.dart
|
| @@ -4,6 +4,7 @@
|
|
|
| library observatory_element;
|
|
|
| +import 'dart:async';
|
| import 'dart:html';
|
| import 'package:observatory/app.dart';
|
| import 'package:polymer/polymer.dart';
|
| @@ -18,6 +19,7 @@ class ObservatoryElement extends PolymerElement {
|
| @override
|
| void attached() {
|
| super.attached();
|
| + _startPoll();
|
| }
|
|
|
| @override
|
| @@ -28,21 +30,68 @@ class ObservatoryElement extends PolymerElement {
|
| @override
|
| void detached() {
|
| super.detached();
|
| + _stopPoll();
|
| }
|
|
|
| + @override
|
| void ready() {
|
| super.ready();
|
| }
|
|
|
| - void goto(MouseEvent event, var detail, Element target) {
|
| - location.onGoto(event, detail, target);
|
| + /// Set to a non-null value to enable polling on this element. When the poll
|
| + /// timer fires, onPoll will be called.
|
| + @observable Duration pollPeriod;
|
| + Timer _pollTimer;
|
| +
|
| + /// Called every [pollPeriod] while the element is attached to the DOM.
|
| + void onPoll() { }
|
| +
|
| + void pollPeriodChanged(oldValue) {
|
| + if (pollPeriod != null) {
|
| + _startPoll();
|
| + } else {
|
| + _stopPoll();
|
| + }
|
| }
|
|
|
| - String gotoLink(String url) {
|
| - return location.makeLink(url);
|
| + void _startPoll() {
|
| + if (pollPeriod == null) {
|
| + return;
|
| + }
|
| + if (_pollTimer != null) {
|
| + _pollTimer.cancel();
|
| + }
|
| + _pollTimer = new Timer(pollPeriod, _onPoll);
|
| }
|
|
|
| + void _stopPoll() {
|
| + if (_pollTimer != null) {
|
| + _pollTimer.cancel();
|
| + }
|
| + _pollTimer = null;
|
| + }
|
|
|
| + void _onPoll() {
|
| + onPoll();
|
| + if (pollPeriod == null) {
|
| + // Stop polling.
|
| + _stopPoll();
|
| + return;
|
| + }
|
| + // Restart timer.
|
| + _pollTimer = new Timer(pollPeriod, _onPoll);
|
| + }
|
| +
|
| + /// Utility method for handling on-click of <a> tags. Navigates
|
| + /// within the application using the [LocationManager].
|
| + void goto(MouseEvent event, var detail, Element target) {
|
| + app.locationManager.onGoto(event, detail, target);
|
| + }
|
| +
|
| + /// Create a link that can be consumed by [goto].
|
| + String gotoLink(String url) {
|
| + return app.locationManager.makeLink(url);
|
| + }
|
|
|
| String formatTimePrecise(double time) => Utils.formatTimePrecise(time);
|
|
|
|
|