Proof of concept: provide empty optionals
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: https://github.com/dfinity/nns-dapp/pull/4594
size-limit report 📦
| Path | Size |
|---|---|
| @dfinity/ckbtc | 7.29 KB (0%) |
| @dfinity/cketh | 2.15 KB (0%) |
| @dfinity/cmc | 1.29 KB (0%) |
| @dfinity/ledger-icrc | 3.38 KB (0%) |
| @dfinity/ledger-icp | 15.83 KB (0%) |
| @dfinity/nns | 35.74 KB (0%) |
| @dfinity/nns-proto | 76.44 KB (0%) |
| @dfinity/sns | 15.46 KB (+0.24% 🔺) |
| @dfinity/utils | 4.44 KB (0%) |
| @dfinity/ic-management | 2.44 KB (0%) |
@dskloetd, thanks a lot for the explanation. I like this solution; it will definitely save some repetitive work in the future 👍