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

Unified Diff: sky/sdk/lib/framework/fn2.dart

Issue 1174023003: Remove one more use of mirrors: Components now have to explicitly sync their fields. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/lib/framework/components2/tool_bar.dart ('k') | sky/sdk/lib/framework/rendering/box.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/framework/fn2.dart
diff --git a/sky/sdk/lib/framework/fn2.dart b/sky/sdk/lib/framework/fn2.dart
index 4d8413682ba90120411d754f59b7ad3e1cc1baf4..60acbf0a7c8ce720baa249c23493bb1f521c6428 100644
--- a/sky/sdk/lib/framework/fn2.dart
+++ b/sky/sdk/lib/framework/fn2.dart
@@ -10,7 +10,6 @@ import 'dart:collection';
import 'dart:mirrors';
import 'dart:sky' as sky;
import 'package:vector_math/vector_math.dart';
-import 'reflect.dart' as reflect;
import 'rendering/block.dart';
import 'rendering/box.dart';
import 'rendering/flex.dart';
@@ -89,7 +88,9 @@ abstract class UINode {
// Subclasses which implements Nodes that become stateful may return true
// if the |old| node has become stateful and should be retained.
- bool _willSync(UINode old) => false;
+ // This is called immediately before _sync().
+ // Component._retainStatefulNodeIfPossible() calls syncFields().
+ bool _retainStatefulNodeIfPossible(UINode old) => false;
bool get interchangeable => false; // if true, then keys can be duplicated
@@ -131,7 +132,7 @@ abstract class UINode {
return null;
}
- if (oldNode != null && node._key == oldNode._key && node._willSync(oldNode)) {
+ if (oldNode != null && node._key == oldNode._key && node._retainStatefulNodeIfPossible(oldNode)) {
assert(oldNode.mounted);
assert(!node.mounted);
oldNode._sync(node, slot);
@@ -929,26 +930,38 @@ abstract class Component extends UINode {
super.remove();
}
- bool _willSync(UINode old) {
+ bool _retainStatefulNodeIfPossible(UINode old) {
assert(!_disqualifiedFromEverAppearingAgain);
Component oldComponent = old as Component;
if (oldComponent == null || !oldComponent._stateful)
return false;
- // Make |this| the "old" Component
+ assert(key == oldComponent.key);
+
+ // Make |this|, the newly-created object, into the "old" Component, and kill it
_stateful = false;
_built = oldComponent._built;
assert(_built != null);
_disqualifiedFromEverAppearingAgain = true;
// Make |oldComponent| the "new" component
- reflect.copyPublicFields(this, oldComponent);
oldComponent._built = null;
oldComponent._dirty = true;
+ oldComponent.syncFields(this);
return true;
}
+ // This is called by _retainStatefulNodeIfPossible(), during
+ // syncChild(), just before _sync() is called.
+ // This must be implemented on any subclass that can become stateful
+ // (but don't call super.syncFields() if you inherit directly from
+ // Component, since that'll fire an assert).
+ // If you don't ever become stateful, then don't override this.
+ void syncFields(Component source) {
+ assert(false);
+ }
+
final int _order;
static int _currentOrder = 0;
« no previous file with comments | « sky/sdk/lib/framework/components2/tool_bar.dart ('k') | sky/sdk/lib/framework/rendering/box.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698