-
Notifications
You must be signed in to change notification settings - Fork 569
js: add MakeFullWrapper to expose exported methods and struct fields. #790
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
Conversation
cc @mvdan - this should make the wrapping of https://godoc.org/mvdan.cc/sh/syntax much easier. |
Would this be a breaking API change for |
Yes, I think it is backwards compatible, because we are only adding properties to the returned value. I've just pushed up a revised version with a test that demonstrate a more interesting scenario, asserting both ways for the getter and setter. |
74f2f10
to
5f0dd87
Compare
I can vouch for the awesomeness of this PR. It has enabled me publishing a rough first version of a Go package of mine on NPM: https://www.npmjs.com/package/mvdan-sh I can't speak about the code itself much, but it works very well :) |
969e860
to
911dcc9
Compare
@hajimehoshi @shurcooL - this is now ready for review. @mvdan - would appreciate if you can update us here on how your testing with this has gone? Thanks very much for helping to road-test the changes. |
The code that I have been using to expose the Go package as a JS module is here: https://github.com/mvdan/sh/tree/master/_js So far it works great with a minimal amount of boilerplate. I have been pinging Paul about specific runtime errors and problems that I was hitting, which he has been pushing fixes here for. At this moment, MakeWrapper is definitely useful to me, as all the basic features of the Go library work great in JS. I hope to get at least a few considerable users of the JS module in the next couple of weeks, so I am likely to provide more edge cases, potential bugs, and suggestions. But please don't let that hold back the reviewing and merging of this PR, as this seems like a great start to have in master. |
@mvdan - rebased this against recent merges into |
4335c97
to
b7d633f
Compare
Everything still works perfectly, at least as far as I have used and tested it. Just yesterday I was finally able to pass objects back and forth between JS and Go multiple times. So now, with the shell package, one can parse a shell program (Go -> JS), walk the syntax tree (JS -> Go and Go -> JS for the callbacks), modify nodes, and print the modified shell source code back (JS -> Go). The glue code is still in that No further requests or bug reports from me :) Happy to continue using this and report bugs on the tracker, once this is merged. |
cc @mpl - this approach could I think help in perkeep world. Avoids the need for any serialising etc. Will ping you more details offline |
@myitcv ACK, thanks. next week though. busy with preparing release/presentation this week. |
4988687
to
27f7ade
Compare
Currently the documentation for js.MakeWrapper is: > "MakeWrapper creates a JavaScript object which has wrappers for the exported methods of i. Use explicit getter and setter methods to expose struct fields to JavaScript." Where the value a struct value (or more interestingly a pointer to a struct value) we can actually auto-generate getters and setters for exported fields in the JavaScript world, rather than requiring explicit getters and setters to be defined on the Go side. We do this via a new MakeFullWrapper method.
Perhaps I'm missing something as I'm not involved in GopherJS development - has there been any progress in getting this reviewed and merged? :) |
GopherJS seems frozen right now! Need a merge here too :) |
If anyone else needs this, just use Paul's fork at https://github.com/myitcv/gopherjs - it includes this enhancement, as well as others like Go module support. |
Just one note @mvdan - all this is currently sitting in the https://github.com/myitcv/gopherjs/tree/go1.11 branch of my fork. There is a chain of PRs that, once merged, will enable full versioning of the fork with versions like |
Is this going to happen? |
@JounQin If memory serves, @flimzy and I discussed this and it seemed like a good thing to have, but it needs to be rebased before if can be merged. One of us was going to do it once there isn't a more pressing matter (like Go 1.18 support, sigh), but so far neither of us has gotten around to it. If you are interested and willing to do the rebase, it would be a welcome contribution. |
See #1112. I'm a js/ts frontend developer, not a go expert actually :( Hope it helps. |
Depends on #797
See the full actual diff here:
myitcv/gopherjs@upgrade_to_circle_ci_2...myitcv:getters
Currently the documentation for js.MakeWrapper is:
Where the value passed to MakeWrapper is a struct value (or more
interestingly a pointer to a struct value) we can actually auto-generate
getters and setters for exported fields in the Javascript world, rather
than requiring explicit getters and setters to be defined on the Go
side. We can also usefully expose a string representing the type of the wrapped value via a $type property.
This PR: