From 76f73851a70ffe48ed87cc5304466d76d9519c16 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Sat, 5 Sep 2020 10:18:41 -0500 Subject: [PATCH] make container property of global window --- di/src/global.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/di/src/global.ts b/di/src/global.ts index 34639bd..e68b2d1 100644 --- a/di/src/global.ts +++ b/di/src/global.ts @@ -2,6 +2,15 @@ import { Container } from './Container.ts' import Instantiable from './type/Instantiable.ts' import { DependencyKey } from './type/DependencyKey.ts' -const container = new Container() -const make = (target: Instantiable|DependencyKey, ...parameters: any[]) => container.make(target, ...parameters) +declare global { + var container: Container + interface Window { container: any } +} + +if ( !window.container ) { + window.container = new Container() +} + +const container = window.container +const make = (target: Instantiable|DependencyKey, ...parameters: any[]) => window.container.make(target, ...parameters) export { container, make }