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

Add js tags to protobuf-generated types #39

Open
idcmp opened this issue Jan 2, 2019 · 2 comments
Open

Add js tags to protobuf-generated types #39

idcmp opened this issue Jan 2, 2019 · 2 comments

Comments

@idcmp
Copy link

idcmp commented Jan 2, 2019

In my use case, I'd like to have a model that is isomorphic and handlers against this model mutate the model. In a normal world, I'd have the model once in JavaScript with mutators written in JavaScript, then I'd have the model again in Go with Go-based mutators.

In a Protobuf/GopherJS world, I'd like to define my model in a proto, generate the appropriate code for the model, then ship an initalState from Go code to the JS-client as a protobuf-on-the-wire which is deserialized and kept as a JS model (used in this case as a React model). I'm quite happy with JSX and various JavaScript UI-isms, so I don't want to use Go for React completely.

When a change to the model is needed, I want the server to create an event that mutates the model, then send that event to the browser. The handler for that event on the JS client would make the same mutation (because it would a GopherJS compiled version of the Go code).

It's my understanding that to turn the Go object to a JS object, I would need to include a *js.Object and the fields would need to be tagged:

   Name string `js:"name"`

..it seems the protoc in gopherjs mode doesn't do this; am I missing something? Am I expected to use pairs of Marshal methods in Go/JS to shovel the protobuf-serialized bytes between the languages? That feels like it'd be much slower, but I'm not really sure what heavy-lifting happens in GopherJS otherwise?

@johanbrandhorst
Copy link
Owner

Hi!

Yeah, so the objects don't automatically include the *js.Object type because it's only relevant on the border between JS and GopherJS, whereas this project was designed with a pure-Go use case in mind. I'm not entirely sure I understand your use case, but I think you might just want to duplicate the relevant types? You might be able to create wrapper types that just compose the generated protobuf types?

@johanbrandhorst
Copy link
Owner

I should note as well that if you want to use JS and React in the frontend, this project is probably not as relevant to you as https://github.com/improbable-eng/grpc-web or https://github.com/grpc/grpc-web. All my examples and tutorials pretty much assume a pure-Go consumer.

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

No branches or pull requests

2 participants