mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-16 12:51:39 +00:00
feat(shell): add emitter svc
This commit is contained in:
parent
0cde7ff772
commit
6d314503d1
@ -6,17 +6,16 @@ import { api } from './services/api'
|
||||
import { getAuthData } from './services/authData'
|
||||
import { baseDir } from './services/baseDir'
|
||||
import { getConfig } from './services/config'
|
||||
import { emitter } from './services/emitter'
|
||||
import { l } from './services/logger'
|
||||
import { validate } from './services/validate'
|
||||
import type { ChronocatContext, DispatchMessage, Engine } from './types'
|
||||
import type { ChronocatContext, Engine } from './types'
|
||||
|
||||
declare const __DEFINE_CHRONO_VERSION__: string
|
||||
|
||||
export const chronocat = async () => {
|
||||
l.info(`Chronocat v${__DEFINE_CHRONO_VERSION__}`)
|
||||
|
||||
let emitImpl = (_: DispatchMessage) => {}
|
||||
|
||||
let ready: () => void
|
||||
const readyPromise = new Promise<void>((res) => {
|
||||
ready = res
|
||||
@ -26,7 +25,7 @@ export const chronocat = async () => {
|
||||
chronocat: {
|
||||
api,
|
||||
baseDir,
|
||||
emit: (message: DispatchMessage) => emitImpl(message),
|
||||
emit: emitter.emit,
|
||||
getAuthData,
|
||||
getConfig,
|
||||
l,
|
||||
@ -96,7 +95,7 @@ export const chronocat = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
emitImpl = (await initServers()).emit
|
||||
emitter.register((await initServers()).emit)
|
||||
|
||||
l.info('中身はあんまりないよ~ (v0.x)', { code: 560 })
|
||||
|
||||
|
10
packages/shell/src/services/emitter.ts
Normal file
10
packages/shell/src/services/emitter.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import type { DispatchMessage } from '../types'
|
||||
|
||||
export type Emit = (message: DispatchMessage) => unknown
|
||||
|
||||
const handlers: Emit[] = []
|
||||
|
||||
export const emitter = {
|
||||
register: (e: Emit) => handlers.push(e),
|
||||
emit: (message: DispatchMessage) => handlers.forEach((e) => e(message)),
|
||||
}
|
Loading…
Reference in New Issue
Block a user