Skip to content

Commit

Permalink
refa: remove deprecated apis
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Nov 9, 2024
1 parent 79774a7 commit 92644d9
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 47 deletions.
5 changes: 1 addition & 4 deletions packages/cordis/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from '@cordisjs/core'
import { Logger, LoggerService } from '@cordisjs/logger'
import { LoggerService } from '@cordisjs/logger'
import { SchemaService } from '@cordisjs/schema'

export * from '@cordisjs/core'
Expand All @@ -26,13 +26,10 @@ export class Context extends core.Context {
}

export abstract class Service<C extends Context = Context> extends core.Service<C> {
/** @deprecated use `this.ctx.logger` instead */
public logger: Logger
public schema: SchemaService

constructor(ctx: C, name: string) {
super(ctx, name)
this.logger = this.ctx.logger(this.name)
this.schema = new SchemaService(this.ctx)
}
}
Expand Down
12 changes: 0 additions & 12 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ export { EventsService, ReflectService, Registry }
export namespace Context {
export type Parameterized<C, T = any> = C & { config: T }

/** @deprecated use `string[]` instead */
export interface MixinOptions {
methods?: string[]
accessors?: string[]
prototype?: {}
}

export interface Item<C extends Context> {
name: string
value?: any
Expand Down Expand Up @@ -80,11 +73,6 @@ export class Context {
Context.prototype[Context.is as any] = true
}

/** @deprecated use `Service.traceable` instead */
static associate<T extends {}>(object: T, name: string) {
return object
}

constructor() {
this[symbols.store] = Object.create(null)
this[symbols.isolate] = Object.create(null)
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export type Plugin<C extends Context = Context, T = any> =
export namespace Plugin {
export interface Base<T = any> {
name?: string
reactive?: boolean
Config?: (config: any) => T
inject?: Inject
provide?: string | string[]
Expand Down Expand Up @@ -86,7 +85,6 @@ export namespace Plugin {
name?: string
schema: any
inject: Dict<Inject.Meta>
isReactive?: boolean
scopes: DisposableList<EffectScope<C>>
plugin: Plugin
}
Expand All @@ -96,8 +94,7 @@ export namespace Plugin {
if (name === 'apply') name = undefined
const schema = plugin['Config'] || plugin['schema']
const inject = Inject.resolve(plugin['using'] || plugin['inject'])
const isReactive = plugin['reactive']
return { name, schema, inject, isReactive, plugin, scopes: new DisposableList() }
return { name, schema, inject, plugin, scopes: new DisposableList() }
}
}

Expand Down
27 changes: 3 additions & 24 deletions packages/core/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,7 @@ declare module './context' {

export type Disposable = () => void

export type DisposableLike = Disposable | Generator<Disposable, void, void>

export type Effect = () => DisposableLike

export interface AcceptOptions {
passive?: boolean
immediate?: boolean
}

export interface Acceptor extends AcceptOptions {
keys?: string[]
callback?: (config: any) => void | boolean
}
export type Effect = () => Disposable | Generator<Disposable, void, void>

export const enum ScopeStatus {
PENDING,
Expand Down Expand Up @@ -59,7 +47,6 @@ export class EffectScope<C extends Context = Context> {

// Same as `this.ctx`, but with a more specific type.
protected context: Context
protected proxy: any
protected tasks = new Set<Promise<void>>()
protected hasError = false

Expand All @@ -79,10 +66,6 @@ export class EffectScope<C extends Context = Context> {
this.ctx.registry.delete(this.runtime.plugin)
}
})
this.proxy = new Proxy({}, {
get: (target, key, receiver) => Reflect.get(this.config, key, receiver),
ownKeys: (target) => Reflect.ownKeys(this.config),
})
this.context.emit('internal/plugin', this)
} else {
this.uid = 0
Expand All @@ -95,10 +78,6 @@ export class EffectScope<C extends Context = Context> {
}
}

protected get _config() {
return this.runtime?.isReactive ? this.proxy : this.config
}

assertActive() {
if (this.isActive) return
throw new CordisError('INACTIVE_EFFECT')
Expand Down Expand Up @@ -179,7 +158,7 @@ export class EffectScope<C extends Context = Context> {
async reset() {
this.isActive = false
this.disposables.popAll().forEach((dispose) => {
;(async () => dispose())().catch((reason) => {
(async () => dispose())().catch((reason) => {
this.context.emit(this.ctx, 'internal/error', reason)
})
})
Expand All @@ -188,7 +167,7 @@ export class EffectScope<C extends Context = Context> {
async start() {
if (!this.isReady || this.isActive || this.uid === null) return true
this.isActive = true
await this.apply(this.ctx, this._config)
await this.apply(this.ctx, this.config)
this.updateStatus()
}

Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ export abstract class Service<C extends Context = Context> {
static readonly invoke: unique symbol = symbols.invoke as any
static readonly extend: unique symbol = symbols.extend as any
static readonly tracker: unique symbol = symbols.tracker as any
static readonly immediate: unique symbol = symbols.immediate as any
static readonly provide = 'provide' as any

protected start(): Awaitable<void> {}
protected stop(): Awaitable<void> {}
protected fork?(ctx: C, config: any): void

public name!: string

Expand Down
1 change: 0 additions & 1 deletion packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const symbols = {
invoke: Symbol.for('cordis.invoke') as typeof Service.invoke,
extend: Symbol.for('cordis.extend') as typeof Service.extend,
tracker: Symbol.for('cordis.tracker') as typeof Service.tracker,
immediate: Symbol.for('cordis.immediate') as typeof Service.immediate,
}

const GeneratorFunction = function* () {}.constructor
Expand Down

0 comments on commit 92644d9

Please sign in to comment.