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

refactor: reuse protobuf Vertex definition #164

Merged
merged 4 commits into from
Sep 23, 2024

Conversation

cwkang1998
Copy link
Contributor

@cwkang1998 cwkang1998 commented Sep 23, 2024

Re-use exisiting protobuf Vertex definition for packages/object, removing the need to maintain a separate TS typedef. This is done by re-exporting the protobuf-gen typedef with the same name.

Since protobuf makes its message field optional by default since proto3, to address the undefined warning, a few modification is done:

  1. addToFrontier now returns a Vertex with a defined operation field.
  2. merge now ignores vertex with an undefined operation field. Alternatively we can make merge throw or log an error when vertex with undefined operation is received.

Closes #151.

Re-use exisiting protobuf Vertex definition for `packages/object`,
removing the need to maintain a separate TS typedef. This is done by
re-exporting the protobuf-gen typedef with the same name.

Since protobuf makes all its field optional by default since proto3, to
address the undefined warning, a few modification is done:

1. `addToFrontier` now returns a Vertex with a defined `operation`
   field.
2. `merge` now ignores vertex with an undefined operation field.
    Alternatively we can make `merge` throw or log an error when vertex
    with undefined operation is received.

Closes drp-tech#151.
@cwkang1998
Copy link
Contributor Author

Might need to add some tests for the changes I make in merge, as its a logical change.

@cwkang1998 cwkang1998 requested a review from d-roak September 23, 2024 16:20
Comment on lines +49 to +50
vertices[0].operation &&
vertices[1].operation &&
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this needed? you changed correctly the other conditions e.g. vertices[0].operation?....

Copy link
Contributor Author

@cwkang1998 cwkang1998 Sep 23, 2024

Choose a reason for hiding this comment

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

Might be me overthinking, but my thought process was so:

In case of vertices 0 is undefined & vertices 1 having undefined value (null will not trigger this), without the first 2 checks, it'll resolve to:

undefined !== v1type && undefined === undefined === true && true

The next statement of vertices[0].operation.type === "add" will then result in false, resulting in. {action: ActionType.DropLeft}.

However my understanding is that if such a case happen that v0 have no ops & v1 have an ops, it should be a no ops since its invalid?

If this is way too much of an edge case then I am happy to remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

in theory, it's impossible for that function to receive an undefined operation there (unless u mess with the hg manually). Although i really like your approach and it makes the code more reliable, we can go with it. Although it'll troublesome in the future, to detect that the linearizeOps is returning undefined/null ops

Copy link
Contributor

@d-roak d-roak left a comment

Choose a reason for hiding this comment

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

lgtm

@d-roak d-roak merged commit 552b561 into drp-tech:main Sep 23, 2024
5 checks passed
@cwkang1998 cwkang1998 deleted the refactor/reuse-pb-vertex-def branch September 23, 2024 17:44
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.

Use Vertex from protobuf everywhere
2 participants