forked from dfinity/nns-dapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify 'last call' logic for queryAndUpdate (dfinity#5563)
# Motivation With `queryAndUpdate` we make 2 calls but sometimes we only want to do something for 1 of the calls. For example, if there is an error in the query call, we just ignore it and wait for the update call. The problem is that `queryAndUpdate` doesn't always do 2 calls and there is some logic to determine whether to do 2 calls or not. If the user is not logged in, we only do a query call and it's also possible to pass in a strategy, which might also depend on the value of `FORCE_CALL_STRATEGY`. Altogether this makes knowing which strategy is currently being used, and thus whether we are doing 1 or 2 calls, and thus whether the current call is the last call or if another call is still following, quite fragile. In this PR, we make `queryAndUpdate` pass the actually used strategy to the `onLoad` and `onError` callback and also add a `isLastCall` function to determine if the current call is either the update call of query+update or the only call of a single query or update call. # Changes 1. Make `queryAndUpdate` pass `strategy` to its callbacks. 2. Add `isLastCall` utility function. 3. Use the utility function in all the places where it makes sense. # Tests 1. Add unit tests for `isLastCall`. 2. Update unit tests for `queryAndUpdate`. 3. Add a lot of missing test coverage because it seems that all these "is this the last call" code paths were untested. # Todos - [ ] Add entry to changelog (if necessary). not necessary
- Loading branch information
Showing
21 changed files
with
562 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.