From 23ace145ef6c6e837083a68483b779bb8bf35c8a Mon Sep 17 00:00:00 2001 From: Il Harper Date: Fri, 23 Aug 2024 13:43:39 +0800 Subject: [PATCH] feat(shell): uix: implement `UixEventEmitter` --- packages/shell/src/services/uix.ts | 31 +++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/shell/src/services/uix.ts b/packages/shell/src/services/uix.ts index b9e1728..c7d455b 100644 --- a/packages/shell/src/services/uix.ts +++ b/packages/shell/src/services/uix.ts @@ -1,6 +1,35 @@ +/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ + import { EventEmitter } from 'node:events' import { api } from './api' +interface UixEventEmitter { + /** + * 监听某键的获得。 + * + * @param key 键。 + * @param listener 值的监听器。 + */ + on(key: string, listener: (value: string) => void): this + + /** + * 等待某键的获得。 + * @param key 键。 + * @param listener 值的监听器。 + */ + once(key: string, listener: (value: string) => void): this + + /** + * 通知某键的值已获得。 + * + * @param key 键。 + * @param value 值。 + */ + emit(key: string, value: string): boolean +} + +class UixEventEmitter extends EventEmitter {} + const uinRegex = /\d+/ const isUin = (uin: unknown) => @@ -12,7 +41,7 @@ const isUid = (uid: unknown) => const isGroup = isUin -export class Uix extends EventEmitter { +export class Uix extends UixEventEmitter { map: Record = {} isUin = isUin