Proof of concept: provide empty optionals #569
Draft
+32
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proof of concept: provide empty optionals
The problem
When Candid types are updated in ic-js, if new optional fields are added, updating the ic-js version in nns-dapp (or other depending repos) is a breaking change, even though the fields are optional.
Here is an example of a PR that updated the ic-js dependency in nns-dapp. In addition to updating the dependency, it had to add new empty field values in many places. I'd like updating the ic-js dependency to be automatic without manual changes.
A solution?
The solution I propose is to provide default empty values for all Candid types. The client repo can then destructure these values in order to get all empty optional values. If a new optional field is added, it should be added to the default empty values such that the client repo will use it automatically.
This PR shows how this could be done for just a single type.
It also adds a test which makes sure that any new optional fields are added.
Here is an example of how this would be used in NNS dapp: dfinity/nns-dapp#4594