-
Notifications
You must be signed in to change notification settings - Fork 0
/
container.js.map
1 lines (1 loc) · 3.5 KB
/
container.js.map
1
{"version":3,"sources":["../../src/container.ts"],"names":[],"mappings":";;AAiBA;;;GAGG;AACU,QAAA,gBAAgB,GAAmE,IAAI;IAAC;QACzF,cAAS,GAAsC,EAAE,CAAC;IAW9D,CAAC;IATG,qBAAG,GAAH,UAAO,SAAsC;QACzC,IAAI,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAA,QAAQ,IAAI,OAAA,QAAQ,CAAC,IAAI,KAAK,SAAS,EAA3B,CAA2B,CAAC,CAAC;QAC5E,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;YACZ,QAAQ,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,SAAS,EAAE,EAAE,CAAC;YACxD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;QAED,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC3B,CAAC;IACL,cAAC;AAAD,CAZqG,AAYpG,IAAC,EAAE,CAAC;AAEL,IAAI,aAA6E,CAAC;AAClF,IAAI,oBAAmD,CAAC;AAExD;;GAEG;AACH,sBAA6B,YAA0C,EAAE,OAA6B;IAClG,aAAa,GAAG,YAAY,CAAC;IAC7B,oBAAoB,GAAG,OAAO,CAAC;AACnC,CAAC;AAHD,oCAGC;AAED;;GAEG;AACH,0BAAoC,SAA+C;IAC/E,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;QAChB,IAAI,CAAC;YACD,IAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAC9C,EAAE,CAAC,CAAC,QAAQ,CAAC;gBACT,MAAM,CAAC,QAAQ,CAAC;YAEpB,EAAE,CAAC,CAAC,CAAC,oBAAoB,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC;gBACxD,MAAM,CAAC,QAAQ,CAAC;QAExB,CAAC;QAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YACb,EAAE,CAAC,CAAC,CAAC,oBAAoB,IAAI,CAAC,oBAAoB,CAAC,gBAAgB,CAAC;gBAChE,MAAM,KAAK,CAAC;QACpB,CAAC;IACL,CAAC;IACD,MAAM,CAAC,wBAAgB,CAAC,GAAG,CAAI,SAAS,CAAC,CAAC;AAC9C,CAAC;AAhBD,4CAgBC","file":"container.js","sourcesContent":["/**\r\n * Container options.\r\n */\r\nexport interface UseContainerOptions {\r\n\r\n /**\r\n * If set to true, then default container will be used in the case if given container haven't returned anything.\r\n */\r\n fallback?: boolean;\r\n\r\n /**\r\n * If set to true, then default container will be used in the case if given container thrown an exception.\r\n */\r\n fallbackOnErrors?: boolean;\r\n\r\n}\r\n\r\n/**\r\n * Container to be used by this library for inversion control. If container was not implicitly set then by default\r\n * container simply creates a new instance of the given class.\r\n */\r\nexport const defaultContainer: { get<T>(someClass: { new (...args: any[]): T }|Function): T } = new (class {\r\n private instances: { type: Function, object: any }[] = [];\r\n\r\n get<T>(someClass: { new (...args: any[]): T }): T {\r\n let instance = this.instances.find(instance => instance.type === someClass);\r\n if (!instance) {\r\n instance = { type: someClass, object: new someClass() };\r\n this.instances.push(instance);\r\n }\r\n\r\n return instance.object;\r\n }\r\n})();\r\n\r\nlet userContainer: { get<T>(someClass: { new (...args: any[]): T }|Function): T };\r\nlet userContainerOptions: UseContainerOptions|undefined;\r\n\r\n/**\r\n * Sets container to be used by this library.\r\n */\r\nexport function useContainer(iocContainer: { get(someClass: any): any }, options?: UseContainerOptions) {\r\n userContainer = iocContainer;\r\n userContainerOptions = options;\r\n}\r\n\r\n/**\r\n * Gets the IOC container used by this library.\r\n */\r\nexport function getFromContainer<T>(someClass: { new (...args: any[]): T }|Function): T {\r\n if (userContainer) {\r\n try {\r\n const instance = userContainer.get(someClass);\r\n if (instance)\r\n return instance;\r\n\r\n if (!userContainerOptions || !userContainerOptions.fallback)\r\n return instance;\r\n\r\n } catch (error) {\r\n if (!userContainerOptions || !userContainerOptions.fallbackOnErrors)\r\n throw error;\r\n }\r\n }\r\n return defaultContainer.get<T>(someClass);\r\n}"],"sourceRoot":"."}