Browse Source

fix: error ctors.find is not a function

e22m4u 1 month ago
parent
commit
99cf9db7b8
2 changed files with 7 additions and 7 deletions
  1. 4 4
      dist/cjs/index.cjs
  2. 3 3
      src/service-container.js

+ 4 - 4
dist/cjs/index.cjs

@@ -105,9 +105,9 @@ var _ServiceContainer = class _ServiceContainer {
     let service = this._services.get(ctor);
     let service = this._services.get(ctor);
     let inheritedCtor = void 0;
     let inheritedCtor = void 0;
     if (!service) {
     if (!service) {
-      const ctors = this._services.keys();
-      const inheritedCtor2 = ctors.find((v) => v.prototype instanceof ctor);
-      if (inheritedCtor2) service = this._services.get(inheritedCtor2);
+      const ctors = Array.from(this._services.keys());
+      inheritedCtor = ctors.find((v) => v.prototype instanceof ctor);
+      if (inheritedCtor) service = this._services.get(inheritedCtor);
     }
     }
     if (!service && !isCtorRegistered && !inheritedCtor && this._parent && this._parent.has(ctor)) {
     if (!service && !isCtorRegistered && !inheritedCtor && this._parent && this._parent.has(ctor)) {
       return this._parent.get(ctor, ...args);
       return this._parent.get(ctor, ...args);
@@ -148,7 +148,7 @@ var _ServiceContainer = class _ServiceContainer {
    */
    */
   has(ctor) {
   has(ctor) {
     if (this._services.has(ctor)) return true;
     if (this._services.has(ctor)) return true;
-    const ctors = this._services.keys();
+    const ctors = Array.from(this._services.keys());
     const inheritedCtor = ctors.find((v) => v.prototype instanceof ctor);
     const inheritedCtor = ctors.find((v) => v.prototype instanceof ctor);
     if (inheritedCtor) return true;
     if (inheritedCtor) return true;
     if (this._parent) return this._parent.has(ctor);
     if (this._parent) return this._parent.has(ctor);

+ 3 - 3
src/service-container.js

@@ -92,8 +92,8 @@ export class ServiceContainer {
     // если экземпляр сервиса не найден,
     // если экземпляр сервиса не найден,
     // то выполняется поиск его наследника
     // то выполняется поиск его наследника
     if (!service) {
     if (!service) {
-      const ctors = this._services.keys();
-      const inheritedCtor = ctors.find(v => v.prototype instanceof ctor);
+      const ctors = Array.from(this._services.keys());
+      inheritedCtor = ctors.find(v => v.prototype instanceof ctor);
       if (inheritedCtor) service = this._services.get(inheritedCtor);
       if (inheritedCtor) service = this._services.get(inheritedCtor);
     }
     }
     // если
     // если
@@ -164,7 +164,7 @@ export class ServiceContainer {
     if (this._services.has(ctor)) return true;
     if (this._services.has(ctor)) return true;
     // если не удалось найти указанный конструктор,
     // если не удалось найти указанный конструктор,
     // то выполняется поиск его наследника
     // то выполняется поиск его наследника
-    const ctors = this._services.keys();
+    const ctors = Array.from(this._services.keys());
     const inheritedCtor = ctors.find(v => v.prototype instanceof ctor);
     const inheritedCtor = ctors.find(v => v.prototype instanceof ctor);
     if (inheritedCtor) return true;
     if (inheritedCtor) return true;
     // если определен родительский контейнер,
     // если определен родительский контейнер,