Open aboodman opened 5 years ago
To the best of my undrestanding,I believe you would pass your protobuf in as an argument or import() it inside the blöck.
// Passing shared code in arguments
const messageHandler = {|
// MyMessage and name vars provided by reification
var message = new MyMessage();
message.setName(name);
return message.serializeBinary();
|};
import { messages } from './messages_pb.js';
messageHandler.reify({MyMessage: messages.MyMessage, name: "John Doe"});
// Importing shared code
const messageHandler {|
const [name] = arguments;
const {messages: {MyMessage}} = await fetch('./messages_pb');
var message = new MyMessage();
message.setName(name);
return message.serializeBinary();
|};
messageHandler.reify({name: "John Doe"});
I don't see an example of code reuse. Say I want to use protobufs implementation inside the blöck to serialize the data I send with fetch(). Does all code have to be inside the blöck?