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
Use closures instead of genfun? #18
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
|
👍 on CLI for compiling protobuf schemas We'd like to use this in the browser someday too, looks like compiling in advance using this approach would work for that case. |
@brendan-ward i'm working on it. you can use brfs to browserify your schemas today though :) |
Thanks, yeah…JS file generation would be great, and I think exactly what I'm requesting on #19 (I think I might have filed that as you were replying on this thread here ;-) |
Any update on this? |
A fun thought (just the fact that it's possible): one could also generate the Javascript code in a browserified Service Worker. Something like: const protobuf = require('protocol-buffers')
const schema = require('fs').readFileSync(__dirname+'/schema.proto', 'utf8')
self.addEventListener('fetch', function (event) {
const req = event.request
if (/\/schema\.js$/.test(req.url)) {
const js = protobuf.generate(schema)
event.respondWith(new Response(js, {
status: 200,
statusText: 'OK',
headers: {
'Content-Type': 'application/javascript',
'Content-Length': js.length.toString()
}
}))
}
}) 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 |
Your compile logic currently uses generate-function to build some code, e.g.
protocol-buffers/compile.js
Line 105 in 012e982
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.
The text was updated successfully, but these errors were encountered: