* Emit an event with data * @param event - The event name * @param data - The data to pass to the callback
( event: T, ...data: Parameters<ClackEvents<TValue>[T]> )
| 109 | * @param data - The data to pass to the callback |
| 110 | */ |
| 111 | public emit<T extends keyof ClackEvents<TValue>>( |
| 112 | event: T, |
| 113 | ...data: Parameters<ClackEvents<TValue>[T]> |
| 114 | ) { |
| 115 | const cbs = this._subscribers.get(event) ?? []; |
| 116 | const cleanup: (() => void)[] = []; |
| 117 | |
| 118 | for (const subscriber of cbs) { |
| 119 | subscriber.cb(...data); |
| 120 | |
| 121 | if (subscriber.once) { |
| 122 | cleanup.push(() => cbs.splice(cbs.indexOf(subscriber), 1)); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | for (const cb of cleanup) { |
| 127 | cb(); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | public prompt() { |
| 132 | return new Promise<TValue | symbol | undefined>((resolve) => { |
no outgoing calls
no test coverage detected