import {
  Scene
} from 'three';

export class SceneModule {
  constructor() {
    this.scene = new Scene();
  }

  manager(manager) {
    manager.addDependency('scene', this.scene, {alias: '$scene'});
  }

  integrate(params, self) {
    this.children = [];

    this.add = function (object) {
      object.parent = this;

      return new Promise((resolve, reject) => {
        const _add = () => {
          const {native} = object;
          if (!native) reject();

          const addPromise = this.applyBridge({onAdd: object}).onAdd;

          const resolver = () => {
            self.scene.add(native);
            this.children.push(object);

            resolve(object);
          };

          if (addPromise instanceof Promise) {
            addPromise.then(resolver);
          } else resolver();
        };

        if (object._wait.length > 0) Promise.all(object._wait).then(_add);
        else _add();
      });
    }
  }
}

@@ -72,28 +72,84 @@
 tor(
-) %7B%0A    this.scene =
+willSceneBeReplaced = false) %7B%0A    this.scene = willSceneBeReplaced ? null :
  new
@@ -433,21 +433,21 @@
     
-const _add = 
+object.defer(
 () =
@@ -789,18 +789,16 @@
 Promise)
- %7B
 %0A       
@@ -838,18 +838,16 @@
         
- %7D
  else re
@@ -869,122 +869,139 @@
    %7D
+)
 ;%0A
-%0A        if (object._wait.length %3E 0) Promise.all(object._wait).then(_add);%0A        else _add();%0A      %7D
+      %7D);%0A    %7D;%0A%0A    this.setScene = function (scene) %7B%0A      self.scene = scene;%0A      this.manager.set('scene', scene
 );%0A    %7D
 %0A  %7D
@@ -996,15 +996,16 @@
 );%0A    %7D
+;
 %0A  %7D%0A%7D%0A

Fix SceneModule & add .setScene()