Permalink
Browse files

Docs: Added static/JSON module interchangeability to README; Minor op…

…timizations through providing type-hints; Performance: Reverted shortened switch statements in verifier; Compatibility: Enums can't be map key types
  • Loading branch information...
dcodeIO committed Dec 20, 2016
1 parent 3e7e4fc commit ab3e236a967a032a98267a648f84d129fdb4d4a6
@@ -404,6 +404,12 @@ Static code, on the other hand, requires just the minimal runtime (about 5.5kb g
There is no difference performance-wise as the code generated statically is pretty much the same as generated at runtime.
Additionally, JSON modules can be used with TypeScript definitions generated for their static counterparts as long as the following conditions are met:
1. Always use `SomeMessage.create(...)` instead of `new SomeMessage(...)` because reflection does not provide such a constructor.
2. Types, services and enums must start with an uppercase letter to become available on the reflected types as well.
3. When using a TypeScript definition with code not generated by pbjs, `resolveAll()` must be called once on the root instance to populate these additional properties (JSON modules do this automatically).
Building
--------
@@ -123,7 +123,7 @@ exports.main = function(args, callback) {
var root;
try {
root = root.loadSync(files, parseOptions);
root = root.loadSync(files, parseOptions); // sync is deterministic while async is not
} catch (err) {
if (callback) {
callback(err);
@@ -10,7 +10,6 @@ var protobuf = require("../..");
json_module.description = "JSON representation as a module"
function json_module(root, options, callback) {
try {
var output = "var $root = protobuf.Root.fromJSON(" + JSON.stringify(root, null, 2).replace(/^(?!$)/mg, " ").trim() + ").resolveAll();";
output = util.wrap(options.wrap || "default", output, options.root);

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN -49 Bytes (100%) dist/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit ab3e236

Please sign in to comment.