Skip to content

Commit ea511a0

Browse files
committed
fix(core): fix disposable for schema / i18n, close #215
1 parent 7a313b5 commit ea511a0

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/core/src/i18n.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,13 @@ export class I18n {
106106
define(locale: string, dict: I18n.Store): () => void
107107
define(locale: string, key: string, value: I18n.Node): () => void
108108
define(locale: string, ...args: [I18n.Store] | [string, I18n.Node]) {
109+
const caller = this[Context.current] || this.ctx
109110
const dict = this._data[locale] ||= {}
110111
const paths = [...typeof args[0] === 'string'
111112
? this.set(locale, args[0] + '.', args[1])
112113
: this.set(locale, '', args[0])]
113114
this.ctx.emit('internal/i18n')
114-
return this[Context.current]?.collect('i18n', () => {
115+
return caller.collect('i18n', () => {
115116
for (const path of paths) {
116117
delete dict[path]
117118
}

packages/core/src/schema.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export class SchemaService {
6161
constructor(public ctx: Context) {}
6262

6363
extend(name: string, schema: Schema, order = 0) {
64+
const caller = this[Context.current]
6465
const target = this.get(name)
6566
const index = target.list.findIndex(a => a[kSchemaOrder] < order)
6667
schema[kSchemaOrder] = order
@@ -70,7 +71,7 @@ export class SchemaService {
7071
target.list.push(schema)
7172
}
7273
this.ctx.emit('internal/schema', name)
73-
this[Context.current]?.on('dispose', () => {
74+
caller?.on('dispose', () => {
7475
remove(target.list, schema)
7576
this.ctx.emit('internal/schema', name)
7677
})
@@ -81,9 +82,10 @@ export class SchemaService {
8182
}
8283

8384
set(name: string, schema: Schema) {
85+
const caller = this[Context.current]
8486
this._data[name] = schema
8587
this.ctx.emit('internal/schema', name)
86-
this[Context.current]?.on('dispose', () => {
88+
caller?.on('dispose', () => {
8789
delete this._data[name]
8890
this.ctx.emit('internal/schema', name)
8991
})

0 commit comments

Comments
 (0)