Use closures instead of genfun?
See original GitHub issueYour compile logic currently uses generate-function to build some code, e.g. https://github.com/mafintosh/protocol-buffers/blob/012e982de02db16693ac777816677cbf6f38697e/compile.js#L105.
This is neat (it looks like in some cases you are dynamically including/excluding entire sections of code!) — however it does mean that it won’t work on the current Tessel runtime, where JavaScript code is actually compiled “offline” before it is pushed, and later eval
/Function
is not currently possible.
I know this is just one platform, and it’s not really your fault that its “JavaScript” implementation is incomplete, but this was kind of a bummer. Protocol buffers seem like a great fit there. (FWIW, you may also run into this restriction in-browser with default Content Security Policy settings in affect.)
Anyway, just thought I’d mention this for future consideration. I know performance is a big focus here, but seems like simply returning closures instead of “generated functions” would bring compatibility (and readability) benefits, and [speculatively] might not be appreciably slower on modern optimizing JS engines.
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
We could bundle a command line tool that would allows you to compile the protobuf schema into a javascript file. I.e.
Then run
Then in your js code you’ll be able to
A fun thought (just the fact that it’s possible): one could also generate the Javascript code in a browserified Service Worker. Something like:
With some more code to cache the result and maybe wrap it. Then to use it somewhere in your app, you’d include it like
<script src="schema.js">
or with some async module loader. Apart from the missingprotobuf.generate()
function, this works in Chrome today.