Skip to content

Commit

Permalink
CLI: Added closure wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Apr 24, 2017
1 parent 7445da0 commit 3a95945
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 48 deletions.
1 change: 1 addition & 0 deletions cli/pbjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ exports.main = function main(args, callback) {
" commonjs CommonJS wrapper",
" amd AMD wrapper",
" es6 ES6 wrapper (implies --es6)",
" closure Just a closure adding to protobuf.roots (see -r)",
"",
" -r, --root Specifies an alternative protobuf.roots name.",
"",
Expand Down
7 changes: 7 additions & 0 deletions cli/wrappers/closure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function($protobuf) {
"use strict";

$OUTPUT;

return $root;
})(protobuf);
32 changes: 19 additions & 13 deletions dist/light/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/light/protobuf.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/light/protobuf.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/minimal/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/minimal/protobuf.min.js

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

Binary file modified dist/minimal/protobuf.min.js.gz
Binary file not shown.
32 changes: 19 additions & 13 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.

4 changes: 2 additions & 2 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.

7 changes: 4 additions & 3 deletions src/oneof.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ OneOf.prototype.onRemove = function onRemove(parent) {
* @template T extends string
*/
OneOf.d = function decorateOneOf() {
var fieldNames = [];
for (var i = 0; i < arguments.length; ++i)
fieldNames.push(arguments[i]);
var fieldNames = new Array(arguments.length),
index = 0;
while (index < arguments.length)
fieldNames[index] = arguments[index++];
return function oneOfDecorator(prototype, oneofName) {
util.decorateType(prototype.constructor)
.add(new OneOf(oneofName, fieldNames));
Expand Down
23 changes: 14 additions & 9 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ util.fs = util.inquire("fs");
* @returns {Array.<*>} Converted array
*/
util.toArray = function toArray(object) {
var array = [];
if (object)
for (var keys = Object.keys(object), i = 0; i < keys.length; ++i)
array.push(object[keys[i]]);
return array;
if (object) {
var keys = Object.keys(object),
array = new Array(keys.length),
index = 0;
while (index < keys.length)
array[index] = object[keys[index++]];
return array;
}
return [];
};

/**
Expand All @@ -40,10 +44,11 @@ util.toArray = function toArray(object) {
* @returns {Object.<string,*>} Converted object
*/
util.toObject = function toObject(array) {
var object = {};
for (var i = 0; i < array.length; i += 2) {
var key = array[i ],
val = array[i + 1];
var object = {},
index = 0;
while (index < array.length) {
var key = array[index++],
val = array[index++];
if (val !== undefined)
object[key] = val;
}
Expand Down

0 comments on commit 3a95945

Please sign in to comment.