mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Merge pull request #1259 from abarth/fn3_rebuild
fn3 shouldn't rebuild components that don't change identity
This commit is contained in:
commit
d27f3d5251
@ -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 {
|
|||||||
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() {
|
|||||||
|
|
||||||
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() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user