Commit b361a3b4 authored by Adam Barth's avatar Adam Barth

fn3 shouldn't rebuild components that don't change identity

parent 5fdd996e
...@@ -204,6 +204,9 @@ abstract class Element<T extends Widget> { ...@@ -204,6 +204,9 @@ abstract class Element<T extends Widget> {
} }
if (child != null) { if (child != null) {
assert(child._slot == slot);
if (child._widget == updated)
return child;
if (_canUpdate(child._widget, updated)) { if (_canUpdate(child._widget, updated)) {
child.update(updated); child.update(updated);
return child; return child;
......
...@@ -32,6 +32,21 @@ class TestComponentState extends ComponentState { ...@@ -32,6 +32,21 @@ class TestComponentState extends ComponentState {
final BoxDecoration kBoxDecorationA = new BoxDecoration(); final BoxDecoration kBoxDecorationA = new BoxDecoration();
final BoxDecoration kBoxDecorationB = new BoxDecoration(); final BoxDecoration kBoxDecorationB = new BoxDecoration();
class TestBuildCounter extends Component {
static int buildCount = 0;
Widget build() {
++buildCount;
return new DecoratedBox(decoration: kBoxDecorationA);
}
}
void flipStatefulComponent(WidgetTester tester) {
ComponentStateElement stateElement =
tester.findElement((element) => element is ComponentStateElement);
(stateElement.state as TestComponentState).flip();
}
void main() { void main() {
test('Stateful component smoke test', () { test('Stateful component smoke test', () {
WidgetTester tester = new WidgetTester(); WidgetTester tester = new WidgetTester();
...@@ -63,10 +78,7 @@ void main() { ...@@ -63,10 +78,7 @@ void main() {
checkTree(kBoxDecorationB); checkTree(kBoxDecorationB);
ComponentStateElement stateElement = flipStatefulComponent(tester);
tester.findElement((element) => element is ComponentStateElement);
(stateElement.state as TestComponentState).flip();
Element.flushBuild(); Element.flushBuild();
checkTree(kBoxDecorationA); checkTree(kBoxDecorationA);
...@@ -82,4 +94,20 @@ void main() { ...@@ -82,4 +94,20 @@ void main() {
}); });
test('Don\'t rebuild subcomponents', () {
WidgetTester tester = new WidgetTester();
tester.pumpFrame(
new TestComponentConfig(
left: new TestBuildCounter(),
right: new DecoratedBox(decoration: kBoxDecorationB)
)
);
expect(TestBuildCounter.buildCount, equals(1));
flipStatefulComponent(tester);
Element.flushBuild();
expect(TestBuildCounter.buildCount, equals(1));
});
} }
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