Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit 857b099

Browse files
committed
Patch toJSON methods on objects that are requested, but not yet discovered via an overview
1 parent cdde685 commit 857b099

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/content/EntityCache.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ return class EntityCache extends EventTarget {
110110
if (valid && !entitiesAdded.has(entity.uuid)) {
111111
addEntity(entity);
112112
}
113-
114-
return true;
115113
}, {
116114
recursive: true,
117115
});
@@ -175,6 +173,12 @@ return class EntityCache extends EventTarget {
175173
},
176174
}
177175

176+
// Register all dependencies, as they may not have
177+
// been patched with a custom toJSON yet.
178+
utils.forEachDependency(entity, dep => {
179+
this._registerEntity(dep);
180+
});
181+
178182
let entitiesAdded = new Set();
179183
let serializedEntity = this._serializeEntity(entity, meta);
180184

src/content/utils.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ const utils = {
3939
* @param {Object} options
4040
* @param {Function} options.recursive [false] whether or not an object should recursively iterate over
4141
* Object3D children and their dependencies.
42-
* @param {Function} options.filter a function that receives an entity, and returns
43-
* a boolean indicating whether or not this object should continue descent.
4442
*/
4543
forEachDependency(entity, fn, options={}) {
46-
const shouldDescend = fn(entity);
44+
fn(entity);
4745

4846
if (entity.isObject3D) {
4947
if (entity.material && entity.material.isMaterial) {
@@ -56,7 +54,7 @@ const utils = {
5654
utils.forEachDependency(entity.background, fn, options);
5755
}
5856

59-
if (shouldDescend && entity.children && entity.children.length > 0) {
57+
if (options.recursive && entity.children && entity.children.length > 0) {
6058
for (let child of entity.children) {
6159
utils.forEachDependency(child, fn, options);
6260
}

0 commit comments

Comments
 (0)