Skip to content

Commit

Permalink
Fix registry context
Browse files Browse the repository at this point in the history
  • Loading branch information
Exelord committed May 10, 2023
1 parent df4dcad commit 847a299
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ export type RegistryProviderProps = {
export const ServiceRegistryContext = createContext<Registry>();

export const ServiceRegistry: FlowComponent<RegistryProviderProps> = (props) => {
let registry: Registry | undefined;

return createComponent(ServiceRegistryContext.Provider, {
value: createRegistry({
get expose() {
return props.expose;
},
}),
get value() {
return (registry ??= createRegistry({
get expose() {
return props.expose;
},
}));
},

get children() {
return props.children;
Expand Down
11 changes: 6 additions & 5 deletions src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ export class Registry {
return parentRegistry.register(initializer);
}

const registration = this.#owner
? runInSubRoot(() => this.initializeService(initializer), this.#owner)
: this.initializeService(initializer);
const registration = runInSubRoot(
() => this.initializeService(initializer),
this.#owner
);

this.#cache.set(initializer, registration);

Expand All @@ -114,12 +115,12 @@ export class Registry {
}

private getParentRegistry(): Registry | undefined {
return this.#owner
return this.#owner?.owner
? runInSubRoot((dispose) => {
const context = useContext(ServiceRegistryContext);
dispose();
return context;
}, this.#owner)
}, this.#owner.owner)
: undefined;
}

Expand Down

0 comments on commit 847a299

Please sign in to comment.