refactor(core): CORE-17 type input events and own interaction lifetimes

This commit is contained in:
Harvey Zhao committed 2026-09-11 11:24:15 +08:00
1 parent 88aef830df
commit a842058136
72 files changed
+31156 -1219

No files matched your search

@@ -0,0 +1,17 @@
import type { SubscriptionHost } from '../component/resources'
import { getScope, isClosing } from '../lifecycle/instance'
export function eventSubscriptions<Events extends { [Name in keyof Events]: readonly unknown[] }>(art: SubscriptionHost<Events>) {
return <Name extends keyof Events>(name: Name, callback: (...args: [...Events[Name]]) => unknown): void => {
if (isClosing(art))
return
const listener = (...args: [...Events[Name]]) => {
if (!isClosing(art))
return callback(...args)
}
art.on(name, listener)
getScope(art).add(() => {
art.off(name, listener)
})
}
}