Skip to content

Commit

Permalink
test(loader): add realm test
Browse files Browse the repository at this point in the history
todo: fix isolation trigger reloading
  • Loading branch information
shigma committed Apr 30, 2024
1 parent b9d4778 commit db9530a
Show file tree
Hide file tree
Showing 3 changed files with 436 additions and 328 deletions.
33 changes: 19 additions & 14 deletions packages/loader/src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class Entry {
if (index >= 0) config.splice(index, 1)
}

amend(ctx?: Context) {
amend(ctx?: Context, initial = false) {
ctx ??= this.parent.extend({
[Context.intercept]: Object.create(this.parent[Context.intercept]),
[Context.isolate]: Object.create(this.parent[Context.isolate]),
Expand All @@ -69,22 +69,27 @@ export class Entry {
neoMap[key] = Symbol(key)
}
}
for (const key in { ...ctx[Context.isolate], ...neoMap }) {
if (neoMap[key] === ctx[Context.isolate][key]) continue
const self = Object.create(null)
self[Context.filter] = (ctx2: Context) => {
return ctx[Context.isolate][key] === ctx2[Context.isolate][key]
// FIXME
if (!initial) {
for (const key in { ...ctx[Context.isolate], ...neoMap }) {
if (neoMap[key] === ctx[Context.isolate][key]) continue
const self = Object.create(null)
self[Context.filter] = (ctx2: Context) => {
return ctx[Context.isolate][key] === ctx2[Context.isolate][key]
}
ctx.emit(self, 'internal/before-service', key)
}
ctx.emit(self, 'internal/before-service', key)
}
const oldMap = swapAssign(ctx[Context.isolate], neoMap)
for (const key in { ...oldMap, ...ctx[Context.isolate] }) {
if (oldMap[key] === ctx[Context.isolate][key]) continue
const self = Object.create(null)
self[Context.filter] = (ctx2: Context) => {
return ctx[Context.isolate][key] === ctx2[Context.isolate][key]
if (!initial) {
for (const key in { ...oldMap, ...ctx[Context.isolate] }) {
if (oldMap[key] === ctx[Context.isolate][key]) continue
const self = Object.create(null)
self[Context.filter] = (ctx2: Context) => {
return ctx[Context.isolate][key] === ctx2[Context.isolate][key]
}
ctx.emit(self, 'internal/service', key)
}
ctx.emit(self, 'internal/service', key)
}
return ctx
}
Expand All @@ -103,7 +108,7 @@ export class Entry {
this.parent.emit('loader/entry', 'apply', this)
const plugin = await this.loader.resolve(this.options.name)
if (!plugin) return
const ctx = this.amend()
const ctx = this.amend(undefined, true)
this.fork = ctx.plugin(plugin, this.options.config)
this.fork.entry = this
}
Expand Down
Loading

0 comments on commit db9530a

Please sign in to comment.