Skip to content

Commit

Permalink
feat(core): use spread for service config
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 20, 2024
1 parent d280231 commit b3bf879
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions packages/cordis/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TimerService } from '@cordisjs/timer'
export * from '@cordisjs/core'
export { default as Schema, default as z } from 'schemastery'
export { Logger } from '@cordisjs/logger'
export { TimerService } from '@cordisjs/timer'

export interface Events<C extends Context = Context> extends core.Events<C> {}

Expand Down Expand Up @@ -35,11 +36,11 @@ export abstract class Service<T = unknown, C extends Context = Context> extends
/** @deprecated use `this.ctx.logger` instead */
public logger: Logger

constructor(config: T)
constructor(ctx: C, config: T)
constructor(...args: core.Spread<T>)
constructor(ctx: C, ...args: core.Spread<T>)
constructor(ctx: C, name: string, immediate?: boolean)
constructor(...args: any[]) {
super(args[0], args[1], args[2])
constructor(...args: any) {
super(...args)
this.logger = this.ctx.logger(this.name)
}

Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Awaitable, defineProperty } from 'cosmokit'
import { Context } from './context.ts'
import { createCallable, joinPrototype, symbols } from './utils.ts'
import { Spread } from './registry.ts'

export abstract class Service<T = unknown, C extends Context = Context> {
static readonly setup: unique symbol = symbols.setup as any
Expand All @@ -19,8 +20,8 @@ export abstract class Service<T = unknown, C extends Context = Context> {
public name!: string
public config!: T

constructor(config: T)
constructor(ctx: C, config: T)
constructor(...args: Spread<T>)
constructor(ctx: C, ...args: Spread<T>)
constructor(ctx: C, name: string, immediate?: boolean)
constructor(...args: any[]) {
let _ctx: C | undefined, name: string | undefined, immediate: boolean | undefined, config: any
Expand Down

0 comments on commit b3bf879

Please sign in to comment.