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

Optional fields #3

Closed
karolchmist opened this issue Nov 15, 2017 · 2 comments
Closed

Optional fields #3

karolchmist opened this issue Nov 15, 2017 · 2 comments

Comments

@karolchmist
Copy link

karolchmist commented Nov 15, 2017

Hello Anantha,

First of all, thanks for creating this library. We are evaluating different solutions for serializing json in the URL and u is our preferred so far.

I have a small doubt about a case when a property may be optional. For example :

const cart = {
  id : 123,
  giftCardId : undefined
}

giftCardId is not always present. Is there an axiomatic method of modeling this case?

A workaround would be to model it as an array with maximum of one element. Other solution would be to add an 'optional' type which would permit null/undefined values.

What do you think?

Cheers,
Karol

@ananthakumaran
Copy link
Owner

My memory is a bit hazy about this because it's been some time since I have written this library. I believe all the fields in an object are considered optional, we use one bit to encode that information https://github.com/ananthakumaran/u/blob/master/src/object.js#L13. So it should work without any issue.

@karolchmist
Copy link
Author

Thanks for super fast reply! You are right, the properties of an object are optional. I'm closing the issue.

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

No branches or pull requests

2 participants