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

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

Issue 2161633005: Converted Observatory nav-refresh element (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Final Merge 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
10 class RefreshEvent {
11 final NavRefreshElement element;
12 RefreshEvent(this.element);
13 }
14
15 class NavRefreshElement extends HtmlElement implements Renderable {
16 static const tag = const Tag<NavRefreshElement>('nav-refresh-wrapped');
17
18 RenderingScheduler _r;
19
20 Stream<RenderedEvent<NavRefreshElement>> get onRendered => _r.onRendered;
21
22 final StreamController<RefreshEvent> _onRefresh =
23 new StreamController<RefreshEvent>.broadcast();
24 Stream<RefreshEvent> get onRefresh => _onRefresh.stream;
25
26 bool _disabled;
27 String _label;
28 bool get disabled => _disabled;
29 String get label => _label;
30 set disabled(bool value) {
31 if (_disabled != value) {
32 _disabled = value;
33 _r.dirty();
34 } else {
35 _r.scheduleNotification();
36 }
37 }
38 set label(String value) {
39 if (_label != value) {
40 _label = value;
41 _r.dirty();
42 } else {
43 _r.scheduleNotification();
44 }
45 }
46
47
48 factory NavRefreshElement({String label: 'Refresh', bool disabled: false,
49 RenderingQueue queue}) {
50 assert(label != null);
51 assert(disabled != null);
52 NavRefreshElement e = document.createElement(tag.name);
53 e._r = new RenderingScheduler(e, queue: queue);
54 e._label = label;
55 e._disabled = disabled;
56 return e;
57 }
58
59 NavRefreshElement.created() : super.created();
60
61 @override
62 void attached() { super.attached(); _r.enable(); }
63
64 @override
65 void detached() { super.detached(); children = []; _r.disable(notify: true); }
66
67 void render() {
68 children = [
69 new LIElement()
70 ..children = [
71 new ButtonElement()
72 ..text = label
73 ..disabled = disabled
74 ..onClick.map(_toEvent).listen(_refresh)
75 ]
76 ];
77 }
78
79 RefreshEvent _toEvent(_) {
80 return new RefreshEvent(this);
81 }
82
83 void _refresh(RefreshEvent e) {
84 if (_disabled) return;
85 _onRefresh.add(e);
86 }
87
88 void refresh() {
89 if (_disabled) return;
90 _refresh(new RefreshEvent(this));
91 }
92 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/elements/css/shared.css ('k') | runtime/observatory/lib/src/elements/nav/refresh_wrapper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698