Skip to content

Commit ab3e236

Browse files
committed
Docs: Added static/JSON module interchangeability to README; Minor optimizations through providing type-hints; Performance: Reverted shortened switch statements in verifier; Compatibility: Enums can't be map key types
1 parent 3e7e4fc commit ab3e236

22 files changed

+281
-248
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ Static code, on the other hand, requires just the minimal runtime (about 5.5kb g
404404

405405
There is no difference performance-wise as the code generated statically is pretty much the same as generated at runtime.
406406

407+
Additionally, JSON modules can be used with TypeScript definitions generated for their static counterparts as long as the following conditions are met:
408+
409+
1. Always use `SomeMessage.create(...)` instead of `new SomeMessage(...)` because reflection does not provide such a constructor.
410+
2. Types, services and enums must start with an uppercase letter to become available on the reflected types as well.
411+
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).
412+
407413
Building
408414
--------
409415

cli/pbjs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ exports.main = function(args, callback) {
123123

124124
var root;
125125
try {
126-
root = root.loadSync(files, parseOptions);
126+
root = root.loadSync(files, parseOptions); // sync is deterministic while async is not
127127
} catch (err) {
128128
if (callback) {
129129
callback(err);

cli/targets/json-module.js

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ var protobuf = require("../..");
1010
json_module.description = "JSON representation as a module"
1111

1212
function json_module(root, options, callback) {
13-
1413
try {
1514
var output = "var $root = protobuf.Root.fromJSON(" + JSON.stringify(root, null, 2).replace(/^(?!$)/mg, " ").trim() + ").resolveAll();";
1615
output = util.wrap(options.wrap || "default", output, options.root);

dist/protobuf.js

+108-93
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js.gz

-49 Bytes
Binary file not shown.

dist/protobuf.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)