Skip to content

Commit 9c76950

Browse files
committed
Lazily resolve (some) cyclic dependencies, see #560
1 parent 9b7b92a commit 9c76950

14 files changed

+126
-78
lines changed

dist/protobuf.js

+59-34
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

143 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.

dist/runtime/protobuf.js

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

dist/runtime/protobuf.min.js

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

dist/runtime/protobuf.min.js.gz

-1 Bytes
Binary file not shown.

src/field.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ var ReflectionObject = require("./object");
77
/** @alias Field.prototype */
88
var FieldPrototype = ReflectionObject.extend(Field);
99

10-
var Type = require("./type"),
11-
Enum = require("./enum"),
12-
MapField = require("./mapfield"),
10+
var Enum = require("./enum"),
1311
types = require("./types"),
1412
util = require("./util");
1513

14+
var Type, // cyclic
15+
MapField; // cyclic
16+
1617
var _TypeError = util._TypeError;
1718

1819
/**
@@ -193,8 +194,11 @@ Field.testJSON = function testJSON(json) {
193194
* @throws {TypeError} If arguments are invalid
194195
*/
195196
Field.fromJSON = function fromJSON(name, json) {
196-
if (json.keyType !== undefined)
197+
if (json.keyType !== undefined) {
198+
if (!MapField)
199+
MapField = require("./mapfield");
197200
return MapField.fromJSON(name, json);
201+
}
198202
return new Field(name, json.id, json.type, json.rule, json.extend, json.options);
199203
};
200204

@@ -225,6 +229,8 @@ FieldPrototype.resolve = function resolve() {
225229
// if not a basic type, resolve it
226230
if (typeDefault === undefined) {
227231
var resolved = this.parent.lookup(this.type);
232+
if (!Type)
233+
Type = require("./type");
228234
if (resolved instanceof Type) {
229235
this.resolvedType = resolved;
230236
typeDefault = null;

src/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ protobuf.configure = configure;
117117
* @returns {undefined}
118118
*/
119119
function configure() {
120-
util._configure();
121120
Reader._configure();
122121
}
123122

0 commit comments

Comments
 (0)