Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept: provide empty optionals #569

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dskloetd
Copy link
Collaborator

@dskloetd dskloetd commented Mar 6, 2024

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

@dskloetd dskloetd marked this pull request as draft March 6, 2024 10:39
Copy link
Contributor

github-actions bot commented Mar 6, 2024

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%)

import { emptyOptionalsForSnsNeuronsFundParticipationConstraints } from "./optionals";

// If this file has a compilation error because new optional fields were added
// to a Candid type, add the the empty optional field values to the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// to a Candid type, add the the empty optional field values to the
// to a Candid type, add the empty optional field values to the

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done.

@mstrasinskis
Copy link
Contributor

@dskloetd, thanks a lot for the explanation. I like this solution; it will definitely save some repetitive work in the future 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants