Skip to content

Commit

Permalink
Fix mutation calling onCompleted for loading state
Browse files Browse the repository at this point in the history
After the introduction of the initial loading state to false on PR zino-hofmann#112, the first emission of the observableQuery observable is a query result with the `loading: true`. The unexpected side effect of this change is that the `onCompleted`callback, which listens only to the first emission, would be called only for the loading state change and not for the query response itself.
This PR changes the `onCompleted` subscription to only call the method and cancel the subscription after the loading changes back to false.
  • Loading branch information
rafaelring committed Oct 11, 2018
1 parent c0e7c56 commit 8db34e7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/src/widgets/mutation.dart
Expand Up @@ -45,8 +45,10 @@ class MutationState extends State<Mutation> {
if (widget.onCompleted != null) {
onCompleteSubscription = observableQuery.stream.listen(
(QueryResult result) {
widget.onCompleted(result);
onCompleteSubscription.cancel();
if (!result.loading) {
widget.onCompleted(result);
onCompleteSubscription.cancel();
}
},
);
}
Expand Down

0 comments on commit 8db34e7

Please sign in to comment.