Просмотр исходного кода

fix: container inheritance in cjs mode

e22m4u 1 год назад
Родитель
Сommit
b6b9500089
4 измененных файлов с 10 добавлено и 13 удалено
  1. 5 5
      dist/cjs/index.cjs
  2. 3 6
      src/service-container.js
  3. 1 1
      src/service.d.ts
  4. 1 1
      src/service.js

+ 5 - 5
dist/cjs/index.cjs

@@ -169,7 +169,7 @@ var ServiceContainer = class _ServiceContainer {
     }
     let service = this._services.get(ctor);
     if (!service || args.length) {
-      service = ctor.kind === Service.name ? new ctor(this, ...args) : new ctor(...args);
+      service = ctor.kind === "Service" ? new ctor(this, ...args) : new ctor(...args);
       this._services.set(ctor, service);
     } else if (typeof service === "function") {
       service = service();
@@ -201,7 +201,7 @@ var ServiceContainer = class _ServiceContainer {
         "The first argument of ServicesContainer.add must be a class constructor, but %v given.",
         ctor
       );
-    const factory = () => ctor.kind === Service.name ? new ctor(this, ...args) : new ctor(...args);
+    const factory = () => ctor.kind === "Service" ? new ctor(this, ...args) : new ctor(...args);
     this._services.set(ctor, factory);
     return this;
   }
@@ -218,7 +218,7 @@ var ServiceContainer = class _ServiceContainer {
         "The first argument of ServicesContainer.use must be a class constructor, but %v given.",
         ctor
       );
-    const service = ctor.kind === Service.name ? new ctor(this, ...args) : new ctor(...args);
+    const service = ctor.kind === "Service" ? new ctor(this, ...args) : new ctor(...args);
     this._services.set(ctor, service);
     return this;
   }
@@ -246,13 +246,13 @@ var ServiceContainer = class _ServiceContainer {
 };
 
 // src/service.js
-var Service = class _Service {
+var Service = class {
   /**
    * Kind.
    *
    * @type {string}
    */
-  static kind = _Service.name;
+  static kind = "Service";
   /**
    * Container.
    *

+ 3 - 6
src/service-container.js

@@ -1,4 +1,3 @@
-import {Service} from './service.js';
 import {InvalidArgumentError} from './errors/index.js';
 
 /**
@@ -64,9 +63,7 @@ export class ServiceContainer {
     // новый экземпляр
     if (!service || args.length) {
       service =
-        ctor.kind === Service.name
-          ? new ctor(this, ...args)
-          : new ctor(...args);
+        ctor.kind === 'Service' ? new ctor(this, ...args) : new ctor(...args);
       this._services.set(ctor, service);
       // instantiates from a factory function
     } else if (typeof service === 'function') {
@@ -103,7 +100,7 @@ export class ServiceContainer {
         ctor,
       );
     const factory = () =>
-      ctor.kind === Service.name ? new ctor(this, ...args) : new ctor(...args);
+      ctor.kind === 'Service' ? new ctor(this, ...args) : new ctor(...args);
     this._services.set(ctor, factory);
     return this;
   }
@@ -123,7 +120,7 @@ export class ServiceContainer {
         ctor,
       );
     const service =
-      ctor.kind === Service.name ? new ctor(this, ...args) : new ctor(...args);
+      ctor.kind === 'Service' ? new ctor(this, ...args) : new ctor(...args);
     this._services.set(ctor, service);
     return this;
   }

+ 1 - 1
src/service.d.ts

@@ -8,7 +8,7 @@ export declare class Service {
   /**
    * Kind.
    */
-  get kind(): string;
+  static kind: string;
 
   /**
    * Container.

+ 1 - 1
src/service.js

@@ -9,7 +9,7 @@ export class Service {
    *
    * @type {string}
    */
-  static kind = Service.name;
+  static kind = 'Service';
 
   /**
    * Container.