Skip to content

Commit

Permalink
Cleanup of Entity constructor to remove circular dependency (#4736)
Browse files Browse the repository at this point in the history
* Cleanup of Entity constructor to remove circular dependency

* fixed internal use of the constructor

Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
mvaligursky and Martin Valigursky committed Oct 12, 2022
1 parent 8b93e82 commit 94a28c5
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/framework/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { guid } from '../core/guid.js';

import { GraphNode } from '../scene/graph-node.js';

import { AppBase } from './app-base.js';
import { getApplication } from './globals.js';

/** @typedef {import('./components/component.js').Component} Component */
/** @typedef {import('./components/anim/component.js').AnimComponent} AnimComponent */
Expand Down Expand Up @@ -278,18 +278,10 @@ class Entity extends GraphNode {
* // Or use rotateLocal
* entity.rotateLocal(0, 90, 0);
*/
constructor(name, app) {
constructor(name, app = getApplication()) {
super(name);

if (name instanceof AppBase) app = name;

if (!app) {
app = AppBase.getApplication(); // get the current application
if (!app) {
throw new Error("Couldn't find current application");
}
}

Debug.assert(app, 'Could not find current application');
this._app = app;
}

Expand Down Expand Up @@ -608,7 +600,7 @@ class Entity extends GraphNode {
*/
_cloneRecursively(duplicatedIdsMap) {
/** @type {this} */
const clone = new this.constructor(this._app);
const clone = new this.constructor(undefined, this._app);
super._cloneInternal(clone);

for (const type in this.c) {
Expand Down

0 comments on commit 94a28c5

Please sign in to comment.