Skip to content

Commit

Permalink
Docs: Added static/JSON module interchangeability to README; Minor op…
Browse files Browse the repository at this point in the history
…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 ab3e236
Show file tree
Hide file tree
Showing 22 changed files with 281 additions and 248 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------

Expand Down
2 changes: 1 addition & 1 deletion cli/pbjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion cli/targets/json-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
201 changes: 108 additions & 93 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit ab3e236

Please sign in to comment.