Skip to content

Commit

Permalink
fix(core): fix disposable for ctx.schema / ctx.i18n, close #215
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Oct 12, 2023
1 parent 7a313b5 commit f19c035
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ export class I18n {
define(locale: string, dict: I18n.Store): () => void
define(locale: string, key: string, value: I18n.Node): () => void
define(locale: string, ...args: [I18n.Store] | [string, I18n.Node]) {
const caller = this[Context.current] || this.ctx
const dict = this._data[locale] ||= {}
const paths = [...typeof args[0] === 'string'
? this.set(locale, args[0] + '.', args[1])
: this.set(locale, '', args[0])]
this.ctx.emit('internal/i18n')
return this[Context.current]?.collect('i18n', () => {
return caller.collect('i18n', () => {
for (const path of paths) {
delete dict[path]
}
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class SchemaService {
constructor(public ctx: Context) {}

extend(name: string, schema: Schema, order = 0) {
const caller = this[Context.current]
const target = this.get(name)
const index = target.list.findIndex(a => a[kSchemaOrder] < order)
schema[kSchemaOrder] = order
Expand All @@ -70,7 +71,7 @@ export class SchemaService {
target.list.push(schema)
}
this.ctx.emit('internal/schema', name)
this[Context.current]?.on('dispose', () => {
caller?.on('dispose', () => {
remove(target.list, schema)
this.ctx.emit('internal/schema', name)
})
Expand All @@ -81,9 +82,10 @@ export class SchemaService {
}

set(name: string, schema: Schema) {
const caller = this[Context.current]
this._data[name] = schema
this.ctx.emit('internal/schema', name)
this[Context.current]?.on('dispose', () => {
caller?.on('dispose', () => {
delete this._data[name]
this.ctx.emit('internal/schema', name)
})
Expand Down

0 comments on commit f19c035

Please sign in to comment.