let entitiesSet = new Set();
let componentEntities = new Map();

export default class Entity {
  static getEntities(ComponentClass) {
    if (!ComponentClass) {
      return entitiesSet;
    }
    let entities = componentEntities.get(ComponentClass);
    if (!entities) {
      entities = new Set();
      componentEntities.set(ComponentClass, entities);
    }
    return entities;
  }

  constructor({name = ""} = {}) {
    this._name = name;

    this._components = new Map();
    this._componentsSaved = new Map();

    this.active = true;

    entitiesSet.add(this);
  }

  get name() {
    return this._name;
  }

  getComponent(ComponentClass) {
    return this._components.get(ComponentClass);
  }

  hasComponent(ComponentClass) {
    return this._components.has(ComponentClass);
  }

  addComponent(ComponentClass, ...args) {
    let component = this._componentsSaved.get(ComponentClass) || this.getComponent(ComponentClass);
    if (component && !args.length) {
      this._componentsSaved.delete(ComponentClass);
    } else {
      component = new ComponentClass(this, ...args);
    }
    this._components.set(ComponentClass, component);
    let entities = Entity.getEntities(ComponentClass);
    entities.add(this);
    component.onAdd.dispatch();
    return component;
  }

  removeComponent(ComponentClass) {
    let component = this.getComponent(ComponentClass);
    if (!component) {
      return;
    }
    this._componentsSaved.set(ComponentClass, component);
    this._components.delete(ComponentClass);
    Entity.getEntities(ComponentClass).delete(this);
    component.onRemove.dispatch();
    return component;
  }

  toggleComponent(ComponentClass, force, ...args) {
    if (force || force === undefined && !this.getComponent(ComponentClass)) {
      this.addComponent(ComponentClass, ...args)
    } else {
      this.removeComponent(ComponentClass)
    }
  }
}

@@ -26,33 +26,109 @@
 ();%0Alet 
-componentEntities
+entitiesSetActive = new Set();%0Alet componentEntities = new Map();%0Alet componentEntitiesActive
  = new M
@@ -191,32 +191,67 @@
 s(ComponentClass
+, %7B%0A    onlyActive = false%0A  %7D = %7B%7D
 ) %7B%0A    if (!Com
@@ -269,32 +269,65 @@
 ) %7B%0A      return
+ onlyActive ? entitiesSetActive :
  entitiesSet;%0A  
@@ -348,16 +348,30 @@
 tities =
+ (onlyActive ?
  compone
@@ -380,16 +380,43 @@
 Entities
+Active : componentEntities)
 .get(Com
@@ -479,24 +479,38 @@
 Set();%0A     
+ (onlyActive ?
  componentEn
@@ -515,16 +515,43 @@
 Entities
+Active : componentEntities)
 .set(Com
@@ -632,10 +632,29 @@
 e = 
-%22%22
+this.constructor.name
 %7D = 
@@ -766,16 +766,17 @@
    this.
+_
 active =
@@ -854,24 +854,389 @@
 _name;%0A  %7D%0A%0A
+  set active(value) %7B%0A    this._active = value;%0A    for (let ComponentClass of this._components.keys()) %7B%0A      if(this._active) %7B%0A        Entity.getEntities(ComponentClass, %7BonlyActive : true%7D).add(this);%0A      %7D else %7B%0A        Entity.getEntities(ComponentClass, %7BonlyActive : true%7D).delete(this);%0A      %7D%0A    %7D%0A  %7D%0A%0A  get active() %7B%0A    return this._active;%0A  %7D%0A%0A
   getCompone
@@ -1757,30 +1757,89 @@
 t);%0A    
-let entities =
+Entity.getEntities(ComponentClass).add(this);%0A    if(this.active) %7B%0A     
  Entity.
@@ -1868,23 +1868,29 @@
 lass
-);%0A    entities
+, %7BonlyActive: true%7D)
 .add
@@ -1889,32 +1889,38 @@
 ue%7D).add(this);%0A
+    %7D%0A
     component.on
@@ -2247,24 +2247,97 @@
 lete(this);%0A
+    Entity.getEntities(ComponentClass, %7BonlyActive: true%7D).delete(this);%0A
     componen

add onlyActive to getEntities