Chromium Code Reviews| 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 5cc8d916c199f4255cd5f59491e47dd5c16cc283..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'; |
| @@ -13,9 +14,12 @@ import 'package:polymer/polymer.dart'; |
| class ObservatoryElement extends PolymerElement { |
| ObservatoryElement.created() : super.created(); |
| + ObservatoryApplication get app => ObservatoryApplication.app; |
| + |
| @override |
| void attached() { |
| super.attached(); |
| + _startPoll(); |
| } |
| @override |
| @@ -26,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; |
|
turnidge
2014/07/01 00:27:47
I wonder if there is a way to make this simpler.
Cutch
2014/07/01 17:14:51
Perhaps it makes more sense on a pane-level. That
|
| + |
| + /// 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); |