Commit b61fe238 authored by Adam Barth's avatar Adam Barth

Rename syncFields to syncConstructorArguments

parent dc7137b0
......@@ -32,10 +32,10 @@ class DialogMenuItem extends ButtonBase {
List<Widget> children;
Function onPressed;
void syncFields(DialogMenuItem source) {
void syncConstructorArguments(DialogMenuItem source) {
children = source.children;
onPressed = source.onPressed;
super.syncFields(source);
super.syncConstructorArguments(source);
}
Widget buildContent() {
......@@ -73,7 +73,7 @@ class FeedFragment extends StatefulComponent {
super.initState();
}
void syncFields(FeedFragment source) {
void syncConstructorArguments(FeedFragment source) {
navigator = source.navigator;
userData = source.userData;
onItemCreated = source.onItemCreated;
......@@ -298,7 +298,7 @@ class AddItemDialog extends StatefulComponent {
Navigator navigator;
void syncFields(AddItemDialog source) {
void syncConstructorArguments(AddItemDialog source) {
this.navigator = source.navigator;
}
......
......@@ -49,7 +49,7 @@ class MealFragment extends StatefulComponent {
Navigator navigator;
FitnessItemHandler onCreated;
void syncFields(MealFragment source) {
void syncConstructorArguments(MealFragment source) {
navigator = source.navigator;
onCreated = source.onCreated;
}
......
......@@ -60,7 +60,7 @@ class MeasurementFragment extends StatefulComponent {
Navigator navigator;
FitnessItemHandler onCreated;
void syncFields(MeasurementFragment source) {
void syncConstructorArguments(MeasurementFragment source) {
navigator = source.navigator;
onCreated = source.onCreated;
}
......
......@@ -17,7 +17,7 @@ class SettingsFragment extends StatefulComponent {
UserData userData;
SettingsUpdater updater;
void syncFields(SettingsFragment source) {
void syncConstructorArguments(SettingsFragment source) {
navigator = source.navigator;
userData = source.userData;
updater = source.updater;
......
......@@ -17,7 +17,7 @@ class StockHome extends StatefulComponent {
StockMode stockMode;
ModeUpdater modeUpdater;
void syncFields(StockHome source) {
void syncConstructorArguments(StockHome source) {
navigator = source.navigator;
stocks = source.stocks;
stockMode = source.stockMode;
......
......@@ -18,7 +18,7 @@ class StockSettings extends StatefulComponent {
BackupMode backup;
SettingsUpdater updater;
void syncFields(StockSettings source) {
void syncConstructorArguments(StockSettings source) {
navigator = source.navigator;
optimism = source.optimism;
backup = source.backup;
......
......@@ -19,7 +19,7 @@ class DragData {
class ExampleDragTarget extends StatefulComponent {
String _text = 'ready';
void syncFields(ExampleDragTarget source) {
void syncConstructorArguments(ExampleDragTarget source) {
}
void _handleAccept(DragData data) {
......
......@@ -29,7 +29,7 @@ class EditableText extends StatefulComponent {
TextStyle style;
Color cursorColor;
void syncFields(EditableText source) {
void syncConstructorArguments(EditableText source) {
value = source.value;
focused = source.focused;
style = source.style;
......
......@@ -44,7 +44,7 @@ class Input extends StatefulComponent {
super.initState();
}
void syncFields(Input source) {
void syncConstructorArguments(Input source) {
placeholder = source.placeholder;
onChanged = source.onChanged;
keyboardType = source.keyboardType;
......
......@@ -267,7 +267,7 @@ class MyDialog extends StatefulComponent {
});
}
void syncFields(MyDialog source) {
void syncConstructorArguments(MyDialog source) {
onDismissed = source.onDismissed;
}
......@@ -319,9 +319,9 @@ Let's walk through the differences in `MyDialog` caused by its being stateful:
`build` function, which means the user interface might not update to reflect
the changed state.
* `MyDialog` implements the `syncFields` member function. To understand
`syncFields`, we'll need to dive a bit deeper into how the `build` function
is used by the framework.
* `MyDialog` implements the `syncConstructorArguments` member function. To
understand `syncConstructorArguments`, we'll need to dive a bit deeper into
how the `build` function is used by the framework.
A component's `build` function returns a tree of widgets that represent a
"virtual" description of its appearance. The first time the framework calls
......@@ -337,28 +337,29 @@ Let's walk through the differences in `MyDialog` caused by its being stateful:
hierchy. Old _stateful_ components, however, cannot simply be discarded
because they contain state that needs to be preserved. Instead, the old
stateful components are retained in the widget hierarchy and asked to
`syncFields` with the new instance of the component created by the parent in
its `build` function.
`syncConstructorArguments` with the new instance of the component created by
the parent in its `build` function.
Without `syncFields`, the new values the parent component passed to the
`MyDialog` constructor in the parent's `build` function would be lost because
they would be stored only as member variables on the new instance of the
component, which is not retained in the component hiearchy. Therefore, the
`syncFields` function in a component should update `this` to account for the
new values the parent passed to `source` because `source` is the authorative
source of those values.
Without `syncConstructorArguments`, the new values the parent component
passed to the `MyDialog` constructor in the parent's `build` function would
be lost because they would be stored only as member variables on the new
instance of the component, which is not retained in the component hiearchy.
Therefore, the `syncConstructorArguments` function in a component should
update `this` to account for the new values the parent passed to `source`
because `source` is the authorative source of those values.
By convention, components typically store the values they receive from their
parents in public member variables and their own internal state in private
member variables. Therefore, a typical `syncFields` implementation will copy
the public, but not the private, member variables from `source`. When
following this convention, there is no need to copy over the private member
variables because those represent the internal state of the object and `this`
is the authoritative source of that state.
member variables. Therefore, a typical `syncConstructorArguments`
implementation will copy the public, but not the private, member variables
from `source`. When following this convention, there is no need to copy over
the private member variables because those represent the internal state of
the object and `this` is the authoritative source of that state.
When implementing a `StatefulComponent`, make sure to call
`super.syncFields(source)` from within your `syncFields()` method,
unless you are extending `StatefulComponent` directly.
`super.syncConstructorArguments(source)` from within your
`syncConstructorArguments()` method, unless you are extending
`StatefulComponent` directly.
Finally, when the user taps on the "Save" button, `MyDialog` follows the same
pattern as `MyCheckbox` and calls a function passed in by its parent component
......@@ -382,9 +383,9 @@ efficient (and less error-prone) than initializing that state during the
component's constructor because parent executes the component's constructor each
time the parent rebuilds even though the framework mounts only the first
instance into the widget hierarchy. (Instead of mounting later instances, the
framework passes them to the original instance in `syncFields` so that the first
instance of the component can incorporate the values passed by the parent to the
component's constructor.)
framework passes them to the original instance in `syncConstructorArguments` so
that the first instance of the component can incorporate the values passed by
the parent to the component's constructor.)
Components often override `didUnmount` to release resources or to cancel
subscriptions to event streams from outside the widget hierachy. When overriding
......
......@@ -9,7 +9,7 @@ abstract class AnimatedComponent extends StatefulComponent {
AnimatedComponent({ Key key }) : super(key: key);
void syncFields(AnimatedComponent source) { }
void syncConstructorArguments(AnimatedComponent source) { }
final List<AnimationPerformance> _watchedPerformances = new List<AnimationPerformance>();
......
......@@ -57,7 +57,7 @@ class AnimatedMatrix4Value extends AnimatedValue<Matrix4> {
abstract class AnimationBehavior {
void initFields(AnimatedContainer original);
void syncFields(AnimatedContainer original, AnimatedContainer updated);
void syncConstructorArguments(AnimatedContainer original, AnimatedContainer updated);
}
class ImplicitlyAnimatedValue<T> {
......@@ -97,7 +97,7 @@ abstract class ImplicitlyAnimatedFieldBehavior<T> extends AnimationBehavior {
_updateField(original, getter(original));
}
void syncFields(AnimatedContainer original, AnimatedContainer updated) {
void syncConstructorArguments(AnimatedContainer original, AnimatedContainer updated) {
_updateField(original, getter(updated));
}
......@@ -213,10 +213,10 @@ class AnimatedContainer extends AnimatedComponent {
i.initFields(this);
}
void syncFields(AnimatedContainer updated) {
void syncConstructorArguments(AnimatedContainer updated) {
child = updated.child;
for (AnimationBehavior i in behavior)
i.syncFields(this, updated);
i.syncConstructorArguments(this, updated);
}
Widget build() {
......
......@@ -622,7 +622,7 @@ class ImageListener extends StatefulComponent {
image.removeListener(_handleImageChanged);
}
void syncFields(ImageListener source) {
void syncConstructorArguments(ImageListener source) {
final bool needToUpdateListeners = (image != source.image) && mounted;
if (needToUpdateListeners)
image.removeListener(_handleImageChanged);
......
......@@ -10,7 +10,7 @@ abstract class ButtonBase extends StatefulComponent {
bool highlight;
void syncFields(ButtonBase source) {
void syncConstructorArguments(ButtonBase source) {
highlight = source.highlight;
}
......
......@@ -52,7 +52,7 @@ class Dismissable extends StatefulComponent {
_startResizePerformance();
}
void syncFields(Dismissable source) {
void syncConstructorArguments(Dismissable source) {
child = source.child;
onResized = source.onResized;
onDismissed = source.onDismissed;
......
......@@ -28,7 +28,7 @@ class DragTarget<T> extends StatefulComponent {
final List<T> _candidateData = new List<T>();
final List<dynamic> _rejectedData = new List<dynamic>();
void syncFields(DragTarget source) {
void syncConstructorArguments(DragTarget source) {
builder = source.builder;
onWillAccept = source.onWillAccept;
onAccept = source.onAccept;
......
......@@ -75,7 +75,7 @@ class Drawer extends StatefulComponent {
}
}
void syncFields(Drawer source) {
void syncConstructorArguments(Drawer source) {
children = source.children;
level = source.level;
navigator = source.navigator;
......
......@@ -25,12 +25,12 @@ class DrawerItem extends ButtonBase {
OnPressedFunction onPressed;
bool selected;
void syncFields(DrawerItem source) {
void syncConstructorArguments(DrawerItem source) {
icon = source.icon;
children = source.children;
onPressed = source.onPressed;
selected = source.selected;
super.syncFields(source);
super.syncConstructorArguments(source);
}
TextStyle _getTextStyle(ThemeData themeData) {
......
......@@ -26,8 +26,8 @@ class FloatingActionButton extends ButtonBase {
Color backgroundColor;
Function onPressed;
void syncFields(FloatingActionButton source) {
super.syncFields(source);
void syncConstructorArguments(FloatingActionButton source) {
super.syncConstructorArguments(source);
child = source.child;
backgroundColor = source.backgroundColor;
onPressed = source.onPressed;
......
......@@ -78,7 +78,7 @@ class Focus extends StatefulComponent {
bool autofocus;
Widget child;
void syncFields(Focus source) {
void syncConstructorArguments(Focus source) {
autofocus = source.autofocus;
child = source.child;
}
......
......@@ -257,7 +257,7 @@ abstract class Widget {
// Subclasses which implements Nodes that become stateful may return true
// if the node has become stateful and should be retained.
// This is called immediately before _sync().
// Component.retainStatefulNodeIfPossible() calls syncFields().
// Component.retainStatefulNodeIfPossible() calls syncConstructorArguments().
bool retainStatefulNodeIfPossible(Widget newNode) => false;
void _sync(Widget old, dynamic slot);
......@@ -737,7 +737,7 @@ abstract class StatefulComponent extends Component {
_isStateInitialized = true;
}
if (old != null)
syncFields(old);
syncConstructorArguments(old);
super._sync(old, slot);
}
......@@ -748,9 +748,9 @@ abstract class StatefulComponent extends Component {
// This is called by _sync(). Derived classes should override this
// method to update `this` to account for the new values the parent
// passed to `source`. Make sure to call super.syncFields(source)
// passed to `source`. Make sure to call super.syncConstructorArguments(source)
// unless you are extending StatefulComponent directly.
void syncFields(Component source);
void syncConstructorArguments(Component source);
Widget syncChild(Widget node, Widget oldNode, dynamic slot) {
assert(!_disqualifiedFromEverAppearingAgain);
......@@ -1262,7 +1262,7 @@ abstract class App extends StatefulComponent {
SkyBinding.instance.removeEventListener(_handleEvent);
}
void syncFields(Component source) { }
void syncConstructorArguments(Component source) { }
// Override this to handle back button behavior in your app
// Call super.onBack() to finish the activity
......@@ -1278,7 +1278,7 @@ abstract class AbstractWidgetRoot extends StatefulComponent {
_scheduleComponentForRender(this);
}
void syncFields(AbstractWidgetRoot source) {
void syncConstructorArguments(AbstractWidgetRoot source) {
assert(false);
// if we get here, it implies that we have a parent
}
......
......@@ -21,11 +21,11 @@ abstract class MaterialButton extends ButtonBase {
bool enabled;
Function onPressed;
void syncFields(MaterialButton source) {
void syncConstructorArguments(MaterialButton source) {
child = source.child;
enabled = source.enabled;
onPressed = source.onPressed;
super.syncFields(source);
super.syncConstructorArguments(source);
}
Color get color;
......
......@@ -20,7 +20,7 @@ class Mimic extends StatefulComponent {
_requestToStartMimic();
}
void syncFields(Mimic source) {
void syncConstructorArguments(Mimic source) {
callback = source.callback;
if (original != source.original) {
_stopMimic();
......@@ -87,7 +87,7 @@ class Mimicable extends StatefulComponent {
Mimic _mimic;
bool _didStartMimic = false;
void syncFields(Mimicable source) {
void syncConstructorArguments(Mimicable source) {
child = source.child;
}
......
......@@ -25,7 +25,7 @@ class MimicOverlay extends AnimatedComponent {
Curve curve;
Rect targetRect;
void syncFields(MimicOverlay source) {
void syncConstructorArguments(MimicOverlay source) {
children = source.children;
duration = source.duration;
......
......@@ -138,7 +138,7 @@ class Navigator extends StatefulComponent {
NavigationState state;
void syncFields(Navigator source) {
void syncConstructorArguments(Navigator source) {
state = source.state;
}
......
......@@ -58,7 +58,7 @@ class PopupMenu extends StatefulComponent {
_open();
}
void syncFields(PopupMenu source) {
void syncConstructorArguments(PopupMenu source) {
if (!showing && source.showing)
_open();
showing = source.showing;
......
......@@ -38,7 +38,7 @@ abstract class ProgressIndicator extends StatefulComponent {
..variable = new AnimatedValue<double>(0.0, end: 1.0, curve: ease);
}
void syncFields(ProgressIndicator source) {
void syncConstructorArguments(ProgressIndicator source) {
value = source.value;
bufferValue = source.bufferValue;
}
......
......@@ -27,11 +27,11 @@ class Radio extends ButtonBase {
Object groupValue;
RadioValueChanged onChanged;
void syncFields(Radio source) {
void syncConstructorArguments(Radio source) {
value = source.value;
groupValue = source.groupValue;
onChanged = source.onChanged;
super.syncFields(source);
super.syncConstructorArguments(source);
}
Color get color {
......
......@@ -55,7 +55,7 @@ abstract class Scrollable extends StatefulComponent {
});
}
void syncFields(Scrollable source) {
void syncConstructorArguments(Scrollable source) {
scrollDirection = source.scrollDirection;
}
......@@ -266,9 +266,9 @@ class ScrollableViewport extends Scrollable {
Widget child;
void syncFields(ScrollableViewport source) {
void syncConstructorArguments(ScrollableViewport source) {
child = source.child;
super.syncFields(source);
super.syncConstructorArguments(source);
}
ScrollBehavior createScrollBehavior() => new OverscrollWhenScrollableBehavior();
......@@ -357,7 +357,7 @@ abstract class ScrollableWidgetList extends Scrollable {
int get itemCount;
int _previousItemCount;
void syncFields(ScrollableWidgetList source) {
void syncConstructorArguments(ScrollableWidgetList source) {
bool scrollBehaviorUpdateNeeded =
padding != source.padding ||
itemExtent != source.itemExtent ||
......@@ -365,7 +365,7 @@ abstract class ScrollableWidgetList extends Scrollable {
padding = source.padding;
itemExtent = source.itemExtent;
super.syncFields(source); // update scrollDirection
super.syncConstructorArguments(source); // update scrollDirection
if (itemCount != _previousItemCount) {
scrollBehaviorUpdateNeeded = true;
......@@ -508,10 +508,10 @@ class ScrollableList<T> extends ScrollableWidgetList {
List<T> items;
ItemBuilder<T> itemBuilder;
void syncFields(ScrollableList<T> source) {
void syncConstructorArguments(ScrollableList<T> source) {
items = source.items;
itemBuilder = source.itemBuilder;
super.syncFields(source);
super.syncConstructorArguments(source);
}
int get itemCount => items.length;
......@@ -547,10 +547,10 @@ class PageableList<T> extends ScrollableList<T> {
Duration duration;
Curve curve;
void syncFields(PageableList<T> source) {
void syncConstructorArguments(PageableList<T> source) {
duration = source.duration;
curve = source.curve;
super.syncFields(source);
super.syncConstructorArguments(source);
}
double _snapScrollOffset(double newScrollOffset) {
......@@ -617,7 +617,7 @@ class ScrollableMixedWidgetList extends Scrollable {
super.didUnmount();
}
void syncFields(ScrollableMixedWidgetList source) {
void syncConstructorArguments(ScrollableMixedWidgetList source) {
builder = source.builder;
if (token != source.token)
_contentsChanged = true;
......@@ -629,7 +629,7 @@ class ScrollableMixedWidgetList extends Scrollable {
layoutState = source.layoutState;
layoutState.addListener(_handleLayoutChanged);
}
super.syncFields(source);
super.syncConstructorArguments(source);
}
ScrollBehavior createScrollBehavior() => new OverscrollBehavior();
......
......@@ -416,8 +416,8 @@ class TabBar extends Scrollable {
..variable = new AnimatedRect(null, curve: ease);
}
void syncFields(TabBar source) {
super.syncFields(source);
void syncConstructorArguments(TabBar source) {
super.syncConstructorArguments(source);
labels = source.labels;
selectedIndex = source.selectedIndex;
onChanged = source.onChanged;
......
......@@ -42,14 +42,14 @@ class _AnchorTransition extends AnimatedComponent {
watch(transition.performance);
}
void syncFields(_AnchorTransition source) {
void syncConstructorArguments(_AnchorTransition source) {
if (transition != null && isWatching(transition.performance))
unwatch(transition.performance);
anchoredTo = source.anchoredTo;
if (transition != null)
watch(transition.performance);
child = source.child;
super.syncFields(source);
super.syncConstructorArguments(source);
}
Widget build() {
......@@ -95,7 +95,7 @@ abstract class TransitionBase extends AnimatedComponent {
_start();
}
void syncFields(TransitionBase source) {
void syncConstructorArguments(TransitionBase source) {
child = source.child;
onCompleted = source.onCompleted;
onDismissed = source.onDismissed;
......@@ -104,7 +104,7 @@ abstract class TransitionBase extends AnimatedComponent {
direction = source.direction;
_start();
}
super.syncFields(source);
super.syncConstructorArguments(source);
}
void _start() {
......@@ -152,9 +152,9 @@ class SlideTransition extends TransitionBase {
AnimatedValue<Point> position;
void syncFields(SlideTransition source) {
void syncConstructorArguments(SlideTransition source) {
position = source.position;
super.syncFields(source);
super.syncConstructorArguments(source);
}
Widget buildWithChild(Widget child) {
......@@ -187,9 +187,9 @@ class FadeTransition extends TransitionBase {
AnimatedValue<double> opacity;
void syncFields(FadeTransition source) {
void syncConstructorArguments(FadeTransition source) {
opacity = source.opacity;
super.syncFields(source);
super.syncConstructorArguments(source);
}
Widget buildWithChild(Widget child) {
......@@ -220,9 +220,9 @@ class ColorTransition extends TransitionBase {
AnimatedColorValue color;
void syncFields(ColorTransition source) {
void syncConstructorArguments(ColorTransition source) {
color = source.color;
super.syncFields(source);
super.syncConstructorArguments(source);
}
Widget buildWithChild(Widget child) {
......@@ -258,10 +258,10 @@ class SquashTransition extends TransitionBase {
AnimatedValue<double> width;
AnimatedValue<double> height;
void syncFields(SquashTransition source) {
void syncConstructorArguments(SquashTransition source) {
width = source.width;
height = source.height;
super.syncFields(source);
super.syncConstructorArguments(source);
}
Widget buildWithChild(Widget child) {
......@@ -299,10 +299,10 @@ class BuilderTransition extends TransitionBase {
List<AnimatedValue> variables;
BuilderFunction builder;
void syncFields(BuilderTransition source) {
void syncConstructorArguments(BuilderTransition source) {
variables = source.variables;
builder = source.builder;
super.syncFields(source);
super.syncConstructorArguments(source);
}
Widget buildWithChild(Widget child) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment