Skip to content

Commit e49a91f

Browse files
committed
refactor(types): move LifecycleHook interface to types.ts
- Moved the LifecycleHook interface definition from world.ts to types.ts for better organization. - Updated imports in world.ts to reference the LifecycleHook from types.ts.
1 parent 105b6e2 commit e49a91f

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from "./world";
44
export * from "./archetype";
55
export * from "./query";
66
export * from "./system";
7+
export * from "./types";

src/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import type { EntityId, WildcardRelationId } from "./entity";
22

3+
/**
4+
* Hook types for component lifecycle events
5+
*/
6+
export interface LifecycleHook<T = unknown> {
7+
/**
8+
* Called when a component is added to an entity
9+
*/
10+
onAdded?: (entityId: EntityId, componentType: EntityId<T>, component: T) => void;
11+
/**
12+
* Called when a component is removed from an entity
13+
*/
14+
onRemoved?: (entityId: EntityId, componentType: EntityId<T>) => void;
15+
}
16+
317
/**
418
* Type helper for component tuples extracted from EntityId array
519
*/

src/world.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,10 @@ import type { EntityId } from "./entity";
44
import { EntityIdManager, getDetailedIdType } from "./entity";
55
import { Query } from "./query";
66
import type { QueryFilter } from "./query-filter";
7-
import type { ComponentTuple } from "./types";
7+
import type { ComponentTuple, LifecycleHook } from "./types";
88
import type { System } from "./system";
99
import { getOrCreateWithSideEffect } from "./utils";
1010

11-
/**
12-
* Hook types for component lifecycle events
13-
*/
14-
export interface LifecycleHook<T = unknown> {
15-
/**
16-
* Called when a component is added to an entity
17-
*/
18-
onAdded?: (entityId: EntityId, componentType: EntityId<T>, component: T) => void;
19-
/**
20-
* Called when a component is removed from an entity
21-
*/
22-
onRemoved?: (entityId: EntityId, componentType: EntityId<T>) => void;
23-
}
24-
2511
/**
2612
* World class for ECS architecture
2713
* Manages entities, components, and systems

0 commit comments

Comments
 (0)