From dfe587e61bea0e6051388545d3f08eee3a6cdce1 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:02:14 -0500 Subject: [PATCH] finalize hook swap, actually delete from hook list --- packages/ioc/src/container.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/ioc/src/container.ts b/packages/ioc/src/container.ts index 05d8c3b..08f5a39 100644 --- a/packages/ioc/src/container.ts +++ b/packages/ioc/src/container.ts @@ -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);