-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Feature presence fields 2 #147
Feature presence fields 2 #147
Conversation
… from src/descriptor.ts and src/field.ts
…user assigns them explicitly
… default value of '0' rather than empty string - at least that is how Google's implementation works
…f getField() calls
Additional tests have been added, and I made a few further corrections to the @thesayyn, please review the pull request when you have some time. Should a rework be needed, I will probably be able to do the rework next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks way better now. but I'd prefer to have presence fields as getter instead of method.
Also, why do we need clear methods? is it part of the spec? If not, how is it different from setting the field to undefined
?
src/compiler/plugin.ts
Outdated
get patch() { | ||
return pb_1.Message.getFieldWithDefault(this, 3, 0) as number; | ||
} | ||
set patch(value: number) { | ||
pb_1.Message.setField(this, 3, value); | ||
} | ||
clear_patch() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware that we needed this. How's this any different than setting patch = undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an internal project file, and the whole project seems to be compiling from typescript to javascript without strictNullChecks
option of tsc
enabled. So I guess the clear_patch()
method is really unnecessary here.
On the other hand, for users of protoc-gen-ts who have the strictNullChecks
option enabled in their projects the existence of the clear_property()
methods makes sense. With strictNullChecks
enabled the tsc
compiler will not allow the assignment of undefined, like patch = undefined
in this example, simply because the setter accepts a value of some specific type other than undefined
(a number
in this example.)
I changed the Forgetting the
I think the
so I guess to really make the setter accept
As mentioned in an earlier comment, that would only be important for protoc-gen-ts users who have I kept the clear methods for now, but I can remove them (and change setters signatures) if you insist. |
That's actually what issue #80 is about. if a field is optional, then you should be able to set it to undefined. That's why i am opposed to adding the clear methods. Maybe we keep it out of this PR and handle it with another PR? |
Amazing work so far @tomasz-szypenbejl-td |
Alright, I will remove the clear methods so that this pull request can be merged.
Thank you. |
I removed the clear methods. @thesayyn please take a look - if there is anything that still needs to be fixed, just let me know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome. just @deprecated
annotations are missing for has getters are belongs to a deprecated field.
…named hasPresenceFunctions -> hasPresenceGetter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job!
Thank you. I have to give credit to @Yurzel. He did most of the hard work writing the code using Thank you for approving and merging this pull request :) |
Ah I probably should have mentioned this tool: |
@thesayyn any chance for the release, please? Will be much appreciated! |
This pull request is a new attempt to add field presence/absence indicators, and to optimize the serialization code. It mostly contains @Yurzel's commits from #136.
Additionally this pull request alters the generated
toObject()
methods so that the returned objects contain default values.I would still like to write some additional tests to make sure that serialization really works as expected with regard to skipping fields that are OK to be skipped (i.e. unset fields for proto2 and defaults for proto3). Thus I am creating this as a draft for now. I should be able to complete work on this on Friday (2022-06-17), but it may take more time if some unexpected difficulties arise.