Skip to content

Commit

Permalink
Lazily resolve (some) cyclic dependencies, see #560
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Dec 15, 2016
1 parent 9b7b92a commit 9c76950
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 78 deletions.
93 changes: 59 additions & 34 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.

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

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

Binary file modified dist/runtime/protobuf.min.js.gz
Binary file not shown.
14 changes: 10 additions & 4 deletions src/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ var ReflectionObject = require("./object");
/** @alias Field.prototype */
var FieldPrototype = ReflectionObject.extend(Field);

var Type = require("./type"),
Enum = require("./enum"),
MapField = require("./mapfield"),
var Enum = require("./enum"),
types = require("./types"),
util = require("./util");

var Type, // cyclic
MapField; // cyclic

var _TypeError = util._TypeError;

/**
Expand Down Expand Up @@ -193,8 +194,11 @@ Field.testJSON = function testJSON(json) {
* @throws {TypeError} If arguments are invalid
*/
Field.fromJSON = function fromJSON(name, json) {
if (json.keyType !== undefined)
if (json.keyType !== undefined) {
if (!MapField)
MapField = require("./mapfield");
return MapField.fromJSON(name, json);
}
return new Field(name, json.id, json.type, json.rule, json.extend, json.options);
};

Expand Down Expand Up @@ -225,6 +229,8 @@ FieldPrototype.resolve = function resolve() {
// if not a basic type, resolve it
if (typeDefault === undefined) {
var resolved = this.parent.lookup(this.type);
if (!Type)
Type = require("./type");
if (resolved instanceof Type) {
this.resolvedType = resolved;
typeDefault = null;
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ protobuf.configure = configure;
* @returns {undefined}
*/
function configure() {
util._configure();
Reader._configure();
}

Expand Down
Loading

0 comments on commit 9c76950

Please sign in to comment.