From 44b466363b45778d70365e15e332cd217503fc9e Mon Sep 17 00:00:00 2001 From: "v.potekhin" Date: Tue, 5 Dec 2023 15:59:24 +0300 Subject: [PATCH] chore: comments --- .../ng-polymorpheus/src/classes/template.ts | 28 ------------------- .../ng-polymorpheus/src/directives/outlet.ts | 14 ++-------- projects/ng-polymorpheus/src/public-api.ts | 1 - .../ng-polymorpheus/src/tests/outlet.spec.ts | 6 ++-- projects/ng-polymorpheus/src/types/content.ts | 2 -- 5 files changed, 4 insertions(+), 47 deletions(-) delete mode 100644 projects/ng-polymorpheus/src/classes/template.ts diff --git a/projects/ng-polymorpheus/src/classes/template.ts b/projects/ng-polymorpheus/src/classes/template.ts deleted file mode 100644 index 5a96557e..00000000 --- a/projects/ng-polymorpheus/src/classes/template.ts +++ /dev/null @@ -1,28 +0,0 @@ -import {Injector, TemplateRef} from '@angular/core'; - -import {POLYMORPHEUS_CONTEXT} from '../tokens/context'; - -/** - * Wrapper class for a template that will be used as content for {@link PolymorpheusOutletDirective} - * - * @param template — an Angular template to be dynamically created - * @param injector — optional {@link Injector} for lazy loaded module case - */ -export class PolymorpheusTemplateContent { - constructor( - readonly template: TemplateRef, - private readonly i?: Injector | null, - ) {} - - createInjector(injector: Injector, useValue?: C): Injector { - return Injector.create({ - parent: this.i || injector, - providers: [ - { - provide: POLYMORPHEUS_CONTEXT, - useValue, - }, - ], - }); - } -} diff --git a/projects/ng-polymorpheus/src/directives/outlet.ts b/projects/ng-polymorpheus/src/directives/outlet.ts index 689e8f69..9050ca5c 100644 --- a/projects/ng-polymorpheus/src/directives/outlet.ts +++ b/projects/ng-polymorpheus/src/directives/outlet.ts @@ -13,7 +13,6 @@ import { import {PolymorpheusComponent} from '../classes/component'; import {PolymorpheusContext} from '../classes/context'; -import {PolymorpheusTemplateContent} from '../classes/template'; import {PolymorpheusContent} from '../types/content'; import {PolymorpheusPrimitive} from '../types/primitive'; import {PolymorpheusTemplate} from './template'; @@ -76,12 +75,7 @@ export class PolymorpheusOutletDirective implements OnChanges, DoCheck { // tslint:disable-next-line:triple-equals (context instanceof PolymorpheusContext && context.$implicit) !== null ) { - const injector = - this.content instanceof PolymorpheusTemplateContent - ? this.content.createInjector(this.i) - : this.i; - - this.vcr.createEmbeddedView(this.template, proxy, {injector}); + this.vcr.createEmbeddedView(this.template, proxy, {injector: this.i}); } } @@ -125,9 +119,5 @@ function isComponent( function isTemplate( content: PolymorpheusContent, ): content is PolymorpheusTemplate | TemplateRef { - return ( - isDirective(content) || - content instanceof TemplateRef || - content instanceof PolymorpheusTemplateContent - ); + return isDirective(content) || content instanceof TemplateRef; } diff --git a/projects/ng-polymorpheus/src/public-api.ts b/projects/ng-polymorpheus/src/public-api.ts index 1a60a748..c60828df 100644 --- a/projects/ng-polymorpheus/src/public-api.ts +++ b/projects/ng-polymorpheus/src/public-api.ts @@ -2,7 +2,6 @@ * Public API Surface of ng-polymorpheus */ export * from './classes/component'; -export * from './classes/template'; export * from './directives/outlet'; export * from './directives/outlet'; export * from './directives/template'; diff --git a/projects/ng-polymorpheus/src/tests/outlet.spec.ts b/projects/ng-polymorpheus/src/tests/outlet.spec.ts index 0cf17db8..47d35f39 100644 --- a/projects/ng-polymorpheus/src/tests/outlet.spec.ts +++ b/projects/ng-polymorpheus/src/tests/outlet.spec.ts @@ -63,12 +63,10 @@ describe('PolymorpheusOutlet', () => { element!: ElementRef; @ViewChild('plain') - // eslint-disable-next-line @typescript-eslint/ban-types - template!: TemplateRef<{}>; + template!: TemplateRef>; @ViewChild('polymorpheus') - // eslint-disable-next-line @typescript-eslint/ban-types - polymorpheus!: PolymorpheusTemplate<{}>; + polymorpheus!: PolymorpheusTemplate>; polymorphic = false; diff --git a/projects/ng-polymorpheus/src/types/content.ts b/projects/ng-polymorpheus/src/types/content.ts index 95412c7e..d7cca153 100644 --- a/projects/ng-polymorpheus/src/types/content.ts +++ b/projects/ng-polymorpheus/src/types/content.ts @@ -1,7 +1,6 @@ import {TemplateRef} from '@angular/core'; import {PolymorpheusComponent} from '../classes/component'; -import {PolymorpheusTemplateContent} from '../classes/template'; import {PolymorpheusTemplate} from '../directives/template'; import {PolymorpheusHandler} from './handler'; import {PolymorpheusPrimitive} from './primitive'; @@ -14,5 +13,4 @@ export type PolymorpheusContent = | PolymorpheusHandler | PolymorpheusPrimitive | PolymorpheusTemplate | ''> // string is untyped, e.g. 'any' - | PolymorpheusTemplateContent | TemplateRef>;