| OLD | NEW |
| 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:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:observatory/src/elements/helpers/rendering_queue.dart'; | 7 import 'package:observatory/src/elements/helpers/rendering_queue.dart'; |
| 8 export 'package:observatory/src/elements/helpers/rendering_queue.dart'; | 8 export 'package:observatory/src/elements/helpers/rendering_queue.dart'; |
| 9 | 9 |
| 10 /// A generic renderable object. | 10 /// A generic renderable object. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 /// Set the object as dirty. A rendering will be scheduled. | 84 /// Set the object as dirty. A rendering will be scheduled. |
| 85 void dirty() { | 85 void dirty() { |
| 86 if (_dirty) return; | 86 if (_dirty) return; |
| 87 _dirty = true; | 87 _dirty = true; |
| 88 scheduleRendering(); | 88 scheduleRendering(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 /// Checks for modification during attribute set. | 91 /// Checks for modification during attribute set. |
| 92 /// If value changes a new rendering is scheduled. | 92 /// If value changes a new rendering is scheduled. |
| 93 /// set attr(T v) => _attr = _r.checkAndReact(_attr, v); | 93 /// set attr(T v) => _attr = _r.checkAndReact(_attr, v); |
| 94 dynamic checkAndReact(dynamic oldValue, dynamic newValue) { | 94 T checkAndReact<T>(T oldValue, T newValue) { |
| 95 if (oldValue != newValue) | 95 if (oldValue != newValue) |
| 96 dirty(); | 96 dirty(); |
| 97 else | 97 else |
| 98 scheduleNotification(); | 98 scheduleNotification(); |
| 99 return newValue; | 99 return newValue; |
| 100 } | 100 } |
| 101 | 101 |
| 102 /// Schedules a new rendering phase. | 102 /// Schedules a new rendering phase. |
| 103 void scheduleRendering() { | 103 void scheduleRendering() { |
| 104 if (_renderingScheduled) return; | 104 if (_renderingScheduled) return; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 130 _wait.addAll(it); | 130 _wait.addAll(it); |
| 131 } | 131 } |
| 132 | 132 |
| 133 Future _notify() async { | 133 Future _notify() async { |
| 134 await Future.wait(_wait); | 134 await Future.wait(_wait); |
| 135 _wait.clear(); | 135 _wait.clear(); |
| 136 _onRendered.add(new RenderedEvent<T>(element, _dirty)); | 136 _onRendered.add(new RenderedEvent<T>(element, _dirty)); |
| 137 _notificationScheduled = false; | 137 _notificationScheduled = false; |
| 138 } | 138 } |
| 139 } | 139 } |
| OLD | NEW |