---
# System prepended metadata

title: todo

---

# todo

* `stages` https://github.com/bevyengine/bevy/blob/b17f8a4bce5551b418654fffb1fe97ff0f9852f0/crates/bevy_app/src/lib.rs

* `world.single` (get a single entity for a component) throw if there exists more??
* `super components` components should follow OOP fetches, eg. if example Light is extended from Object3D, query(Object3D) will get both Light & Object3D entities.


```typescript=

export type ComponentStorage = {
  insert(entity: Entity, value: ComponentInstance, flags: ComponentFlags): ComponentInstance;
  remove(entity: Entity): boolean;
  get(entity: Entity): ComponentInstance;
  has(entity: Entity): boolean;
  set_flag(entity: Entity, fn: (flag: ComponentFlags) => ComponentFlags): void;
  get_with_flags(entity: Entity): [ComponentInstance, ComponentFlags];
  clear_flags(): void;
  realloc(length?: number): void;

  empty(): boolean;
  
  readonly length: number;
  readonly capacity: number;
}

export class DerivedComponentStorage {

}

```


```typescript=
class Point {}
class Point2D extends Point {}
class Point3D extends Point2D {}
class Point4D extends Point3D {}
class Point5D extends Point4D {}
class Point6D extends Point5D {}
class Point7D extends Point6D {}

class FloatPoint extends Point {}

class Bar {}
class Foo extends Bar {}

function find_closest_ancestor(classes) {
  const nodes = [];
  for (const cls of classes) {
    const ancestors = classes.filter((x) => cls.prototype instanceof x);

    if (ancestors.length === 0) {
      nodes.push({ parent: undefined, self: cls });
      continue;
    }

    if (ancestors.length === 1) {
      nodes.push({ parent: ancestors[0], self: cls });
      continue;
    }
		
 		let ancestorsWith = Array.from(ancestors).map(x => ({ value: 0, type: x }));
    
    for(let i = 0; i < ancestorsWith.length; i++) {
    	const current = ancestorsWith[i];
      for(let j = 0; j < ancestorsWith.length; j++) {
      	if (i === j) continue;
        const other = ancestorsWith[j];
        current.value += other.type.prototype instanceof current.type ? 1 : 0;
      }
    }
    
    ancestorsWith.sort((a, b) => ( a.value - b.value));
    nodes.push({ parent: ancestorsWith[0].type, self: cls });
  }
  return nodes;
}


function func(a, b) {  
  return 0.5 - Math.random();
}  


find_closest_ancestor([Point, Point2D, Point3D, Point4D, Point5D, Point6D, Point7D].sort(func))
```


```typescript

import { World, query } from "dreki";
import { not, observe } from "dreki/filters";

const world = World.build()
  .with({ capacity: 200 })
  .systems(added_sys)
  .done();

function added_sys() {
    for (const [pos] of query(not(Dead), observe(Position)) {
        pos.x += 9999;
    }
};






```