diff --git a/jecs.d.ts b/jecs.d.ts index daba057..b6d936d 100644 --- a/jecs.d.ts +++ b/jecs.d.ts @@ -151,6 +151,15 @@ export class World { */ add(entity: Entity, component: undefined extends InferComponent ? C : Id): void; + /** + * Installs a hook on the given component. + * @param component The target component. + * @param hook The hook to install. + * @param value The hook callback. + */ + set(component: Entity, hook: StatefulHook<(e: Entity, id: Id, data: T) => void>, value: (e: Entity, id: Id, data: T) => void): void; + set(component: Entity, hook: StatelessHook<(e: Entity, id: Id) => void>, value: (e: Entity, id: Id) => void): void; + /** * Assigns a value to a component on the given entity. * @param entity The target entity. @@ -280,9 +289,16 @@ export function pair_first(world: World, p: Pair): Entity

; */ export function pair_second(world: World, p: Pair): Entity; -export declare const OnAdd: Entity<(e: Entity, id: Id, data: T) => void>; -export declare const OnRemove: Entity<(e: Entity, id: Id) => void>; -export declare const OnChange: Entity<(e: Entity, id: Id, data: T) => void>; +type StatefulHook(e: Entity, id: Id, data: T) => void> = Entity & { + readonly __nominal_StatefulHook: unique symbol, +} +type StatelessHook(e: Entity, id: Id) => void> = Entity & { + readonly __nominal_StatelessHook: unique symbol, +} + +export declare const OnAdd: StatefulHook; +export declare const OnRemove: StatelessHook; +export declare const OnChange: StatefulHook; export declare const ChildOf: Tag; export declare const Wildcard: Entity; export declare const w: Entity;