import {system} from '../polyfill';
import {ModuleSystem} from './ModuleSystem';
import {ModuleManager} from './ModuleManager';

class App extends ModuleSystem {
  simulate = false;
  updateEnabled = true;
  loops = [];

  constructor(modules = []) {
    super();
    this.manager = new ModuleManager(this);
    this.modules = modules;

    this.integrateModules();
  }

  // CONTROLS & UPDATING

  start() {
    const requestAnimFrame = (() => {
      return system.window.requestAnimationFrame
        || system.window.webkitRequestAnimationFrame
        || system.window.mozRequestAnimationFrame
        || function (callback) {
          system.window.setTimeout(callback, 1000 / 60);
        };
    })();

    const {loops, updateEnabled} = this;

    function process() {
      requestAnimFrame(process);
      if (!updateEnabled) return;

      for (let i = 0, ll = loops.length; i < ll; i++) {
        const e = loops[i];
        if (e.enabled) e.execute(e.clock);
      }
    }

    this.updateEnabled = true;
    process();
  }

  stop() {
    this.updateEnabled = false;
  }

  addLoop(loop) {
    return new Promise(resolve => {
      this.loops.push(loop);
      resolve(loop);
    });
  }

  removeLoop(loop) {
    return new Promise(resolve => {
      let index = this.loops.indexOf(loop);
      if(index!==-1){
        this.loops.splice(index,1)
      }
      resolve(loop);
    });
  }
}

export {
  App
};

@@ -1310,29 +1310,23 @@
   if
+ 
 (index
+ 
 !==
+ 
 -1)
-%7B%0A       
  thi
@@ -1348,24 +1348,24 @@
 index,1)
+;
 %0A      
-%7D
 %0A      r

Fix code style