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

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

Issue 2159273004: Added helper function to automatically dirty a RenderingScheduler on attribute change (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Added comments to new helper method 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
« no previous file with comments | « runtime/observatory/lib/src/elements/nav/menu_item.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:html'; 5 import 'dart:html';
6 import 'dart:async'; 6 import 'dart:async';
7 import 'package:observatory/src/elements/helpers/tag.dart'; 7 import 'package:observatory/src/elements/helpers/tag.dart';
8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; 8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart';
9 9
10 class RefreshEvent { 10 class RefreshEvent {
11 final NavRefreshElement element; 11 final NavRefreshElement element;
12 RefreshEvent(this.element); 12 RefreshEvent(this.element);
13 } 13 }
14 14
15 class NavRefreshElement extends HtmlElement implements Renderable { 15 class NavRefreshElement extends HtmlElement implements Renderable {
16 static const tag = const Tag<NavRefreshElement>('nav-refresh-wrapped'); 16 static const tag = const Tag<NavRefreshElement>('nav-refresh-wrapped');
17 17
18 RenderingScheduler _r; 18 RenderingScheduler _r;
19 19
20 Stream<RenderedEvent<NavRefreshElement>> get onRendered => _r.onRendered; 20 Stream<RenderedEvent<NavRefreshElement>> get onRendered => _r.onRendered;
21 21
22 final StreamController<RefreshEvent> _onRefresh = 22 final StreamController<RefreshEvent> _onRefresh =
23 new StreamController<RefreshEvent>.broadcast(); 23 new StreamController<RefreshEvent>.broadcast();
24 Stream<RefreshEvent> get onRefresh => _onRefresh.stream; 24 Stream<RefreshEvent> get onRefresh => _onRefresh.stream;
25 25
26 bool _disabled; 26 bool _disabled;
27 String _label; 27 String _label;
28 bool get disabled => _disabled; 28 bool get disabled => _disabled;
29 String get label => _label; 29 String get label => _label;
30 set disabled(bool value) { 30 set disabled(bool value) => _disabled = _r.checkAndReact(_disabled, value);
31 if (_disabled != value) { 31 set label(String value) => _label = _r.checkAndReact(_label, 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 32
48 factory NavRefreshElement({String label: 'Refresh', bool disabled: false, 33 factory NavRefreshElement({String label: 'Refresh', bool disabled: false,
49 RenderingQueue queue}) { 34 RenderingQueue queue}) {
50 assert(label != null); 35 assert(label != null);
51 assert(disabled != null); 36 assert(disabled != null);
52 NavRefreshElement e = document.createElement(tag.name); 37 NavRefreshElement e = document.createElement(tag.name);
53 e._r = new RenderingScheduler(e, queue: queue); 38 e._r = new RenderingScheduler(e, queue: queue);
54 e._label = label; 39 e._label = label;
55 e._disabled = disabled; 40 e._disabled = disabled;
56 return e; 41 return e;
(...skipping 26 matching lines...) Expand all
83 void _refresh(RefreshEvent e) { 68 void _refresh(RefreshEvent e) {
84 if (_disabled) return; 69 if (_disabled) return;
85 _onRefresh.add(e); 70 _onRefresh.add(e);
86 } 71 }
87 72
88 void refresh() { 73 void refresh() {
89 if (_disabled) return; 74 if (_disabled) return;
90 _refresh(new RefreshEvent(this)); 75 _refresh(new RefreshEvent(this));
91 } 76 }
92 } 77 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/elements/nav/menu_item.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698