Skip to content

Commit

Permalink
Fix case where setState and store trigger only result in one render
Browse files Browse the repository at this point in the history
  • Loading branch information
greglittlefield-wf committed Aug 14, 2017
1 parent 6946cbd commit 3740fd8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/component_declaration/flux_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ abstract class _FluxComponentMixin<TProps extends FluxUiProps> implements Batche
});
}

void componentDidUpdate(Map prevProps, Map prevState) {
void componentWillReceiveProps(Map prevProps) {
// Let BatchedRedraws know that this component has redrawn in the current batch
didBatchRedraw = true;
}
Expand Down
25 changes: 25 additions & 0 deletions test/over_react/component_declaration/flux_component_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,31 @@ void main() {
expect(nested1.renderCount, 3, reason: 'should have rerendered once in response to the store triggering');
expect(nested2.renderCount, 3, reason: 'should have rerendered once in response to the store triggering');
});

test('redraws twice in response to a the component calling setState and a store trigger happening at the same time', () async {
var store = new Store();

TestNestedComponent nested0;

render(
(TestNested()
..store = store
..ref = (ref) { nested0 = ref; }
)()
);
expect(nested0.renderCount, 1, reason: 'setup check: initial render');

nested0.setState({});
store.trigger();
// Two async gaps just to be safe, since we're
// asserting that additional redraws don't happen.
await nextTick();
await nextTick();

expect(nested0.renderCount, 3,
reason: 'should have rerendered once in response to the store triggering'
' and once in response to setState');
});
});
}

Expand Down

0 comments on commit 3740fd8

Please sign in to comment.