Skip to content

Commit

Permalink
finalize hook swap, actually delete from hook list
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes committed Jun 13, 2024
1 parent 0a13cd4 commit dfe587e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/ioc/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ export class Container {
}
// check if there's dispose hook, and call it
if (hasCallableMethod(existing, 'dispose')) {
//this should technically be awaited to ensure synchronicity of swap
// but i dont want to ruin the function signature of swap.
existing.dispose();
// get the index of the existing singleton, now delete the dispose hook at that index
// .indexOf is safe because we only store singletons, and it should be a reference to
// the original object in this.__singletons
const hookIndex = this.hooks.get('dispose')!.indexOf(existing);
if (hookIndex > -1) {
this.hooks.get('dispose')!.splice(hookIndex, 1);
Expand Down

0 comments on commit dfe587e

Please sign in to comment.