Skip to content

Commit

Permalink
chore: remove unnecessary _dynamic and DynamicWrapper
Browse files Browse the repository at this point in the history
The `_dynamic` property was set but never read.
  • Loading branch information
kevinbuhmann committed Dec 19, 2024
1 parent 71e6d5d commit 867322c
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 74 deletions.
5 changes: 1 addition & 4 deletions projects/angular/src/data/datagrid/wrapped-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import { AfterViewInit, Component, EmbeddedViewRef, OnDestroy, TemplateRef, ViewChild } from '@angular/core';

import { DynamicWrapper } from '../../utils/host-wrapping/dynamic-wrapper';

@Component({
selector: 'dg-wrapped-cell',
template: `
Expand All @@ -17,8 +15,7 @@ import { DynamicWrapper } from '../../utils/host-wrapping/dynamic-wrapper';
</ng-template>
`,
})
export class WrappedCell implements DynamicWrapper, AfterViewInit, OnDestroy {
_dynamic = false;
export class WrappedCell implements AfterViewInit, OnDestroy {
@ViewChild('cellPortal') templateRef: TemplateRef<void>;
cellView: EmbeddedViewRef<void>; // the cells projected view

Expand Down
6 changes: 1 addition & 5 deletions projects/angular/src/data/datagrid/wrapped-column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import { AfterViewInit, Component, EmbeddedViewRef, OnDestroy, TemplateRef, ViewChild } from '@angular/core';

import { DynamicWrapper } from '../../utils/host-wrapping/dynamic-wrapper';

@Component({
selector: 'dg-wrapped-column',
template: `
Expand All @@ -17,9 +15,7 @@ import { DynamicWrapper } from '../../utils/host-wrapping/dynamic-wrapper';
</ng-template>
`,
})
export class WrappedColumn implements DynamicWrapper, AfterViewInit, OnDestroy {
_dynamic = false;

export class WrappedColumn implements AfterViewInit, OnDestroy {
@ViewChild('columnPortal') templateRef: TemplateRef<void>;
columnView: EmbeddedViewRef<void>; // the columns projected view (in memory)

Expand Down
6 changes: 1 addition & 5 deletions projects/angular/src/data/datagrid/wrapped-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import { AfterViewInit, Component, EmbeddedViewRef, OnDestroy, TemplateRef, ViewChild } from '@angular/core';

import { DynamicWrapper } from '../../utils/host-wrapping/dynamic-wrapper';

@Component({
selector: 'dg-wrapped-row',
template: `
Expand All @@ -17,9 +15,7 @@ import { DynamicWrapper } from '../../utils/host-wrapping/dynamic-wrapper';
</ng-template>
`,
})
export class WrappedRow implements DynamicWrapper, AfterViewInit, OnDestroy {
_dynamic = false;

export class WrappedRow implements AfterViewInit, OnDestroy {
@ViewChild('rowPortal') templateRef: TemplateRef<void>;
rowView: EmbeddedViewRef<void>; // the rows projected view (in memory)

Expand Down
7 changes: 1 addition & 6 deletions projects/angular/src/forms/checkbox/checkbox-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { Component, ContentChild, Inject, InjectionToken, OnDestroy, OnInit } from '@angular/core';
import { BehaviorSubject, Subscription } from 'rxjs';

import { DynamicWrapper } from '../../utils/host-wrapping/dynamic-wrapper';
import { ClrLabel } from '../common/label';
import { ControlIdService } from '../common/providers/control-id.service';

Expand All @@ -31,11 +30,7 @@ export const IS_TOGGLE_PROVIDER = { provide: IS_TOGGLE, useFactory: isToggleFact
},
providers: [ControlIdService, IS_TOGGLE_PROVIDER],
})
export class ClrCheckboxWrapper implements DynamicWrapper, OnInit, OnDestroy {
// We need both _dynamic for HostWrapper and ContentChild(ClrLabel) in cases where
// the user puts a radio inside a wrapper without a label, host wrapping doesn't apply
// but we'd still need to insert a label
_dynamic = false;
export class ClrCheckboxWrapper implements OnInit, OnDestroy {
@ContentChild(ClrLabel, { static: true }) label: ClrLabel;
toggle = false;
private subscriptions: Subscription[] = [];
Expand Down
4 changes: 1 addition & 3 deletions projects/angular/src/forms/common/abstract-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { AfterContentInit, ContentChild, Directive, OnDestroy, Optional } from '
import { NgControl } from '@angular/forms';
import { Subscription } from 'rxjs';

import { DynamicWrapper } from '../../utils/host-wrapping/dynamic-wrapper';
import { ClrControlError } from './error';
import { ClrControlHelper } from './helper';
import { CONTROL_STATE, IfControlStateService } from './if-control-state/if-control-state.service';
Expand All @@ -20,14 +19,13 @@ import { NgControlService } from './providers/ng-control.service';
import { ClrControlSuccess } from './success';

@Directive()
export abstract class ClrAbstractContainer implements DynamicWrapper, OnDestroy, AfterContentInit {
export abstract class ClrAbstractContainer implements OnDestroy, AfterContentInit {
@ContentChild(ClrLabel, { static: false }) label: ClrLabel;
@ContentChild(ClrControlSuccess) controlSuccessComponent: ClrControlSuccess;
@ContentChild(ClrControlError) controlErrorComponent: ClrControlError;
@ContentChild(ClrControlHelper) controlHelperComponent: ClrControlHelper;

control: NgControl;
_dynamic = false;

protected subscriptions: Subscription[] = [];

Expand Down
5 changes: 1 addition & 4 deletions projects/angular/src/forms/common/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Component, Directive, NgModule, Type, ViewContainerRef } from '@angular
import { TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { DynamicWrapper } from '../../utils/host-wrapping/dynamic-wrapper';
import { ClrHostWrappingModule } from '../../utils/host-wrapping/host-wrapping.module';
import { ClrCommonFormsModule } from './common.module';
import { ControlIdService } from './providers/control-id.service';
Expand All @@ -27,9 +26,7 @@ import { WrappedFormControl } from './wrapped-control';
`,
providers: [ControlIdService],
})
class GenericWrapper implements DynamicWrapper {
_dynamic = false;
}
class GenericWrapper {}

@Directive({
selector: '[genericControl]',
Expand Down
15 changes: 3 additions & 12 deletions projects/angular/src/forms/common/wrapped-control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testin
import { FormControl, FormGroup, FormsModule, NgControl, ReactiveFormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';

import { DynamicWrapper } from '../../utils/host-wrapping/dynamic-wrapper';
import { HostWrapper } from '../../utils/host-wrapping/host-wrapper';
import { ClrHostWrappingModule } from '../../utils/host-wrapping/host-wrapping.module';
import { ClrAbstractContainer } from './abstract-container';
Expand All @@ -33,9 +32,7 @@ import { WrappedFormControl } from './wrapped-control';
template: `<ng-content></ng-content>`,
providers: [ControlIdService],
})
class TestWrapper implements DynamicWrapper {
_dynamic = false;
}
class TestWrapper {}

@Directive({
selector: '[testControl]',
Expand All @@ -54,9 +51,7 @@ class TestControl extends WrappedFormControl<TestWrapper> {
`,
providers: [ControlIdService],
})
class TestWrapper2 implements DynamicWrapper {
_dynamic = false;
}
class TestWrapper2 {}

@Directive({
selector: '[testControl2]',
Expand All @@ -72,9 +67,7 @@ class TestControl2 extends WrappedFormControl<TestWrapper2> {
template: `<div id="wrapper"><ng-content></ng-content></div>`,
providers: [ControlIdService, NgControlService, IfControlStateService, ControlClassService],
})
class TestWrapper3 extends ClrAbstractContainer implements DynamicWrapper {
_dynamic = false;
}
class TestWrapper3 extends ClrAbstractContainer {}

@Directive({
selector: '[testControl3]',
Expand Down Expand Up @@ -297,7 +290,6 @@ export default function (): void {
spyOn(HostWrapper.prototype, 'get').and.callThrough();
setupTest(this, WithWrapperNoId, TestControl);
expect(HostWrapper.prototype.get).toHaveBeenCalledWith(ControlIdService);
expect(this.wrapper._dynamic).toBe(false);
});

it('sets the id of the host to the id given by the service', function (this: TestContext) {
Expand All @@ -317,7 +309,6 @@ export default function (): void {
spyOn(HostWrapper.prototype, 'get').and.callThrough();
setupTest(this, NoWrapperNoId, TestControl);
expect(HostWrapper.prototype.get).toHaveBeenCalledWith(ControlIdService);
expect(this.wrapper._dynamic).toBe(true);
});

it('sets the id of the host to the id given by the service', function (this: TestContext) {
Expand Down
3 changes: 1 addition & 2 deletions projects/angular/src/forms/common/wrapped-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import { NgControl } from '@angular/forms';
import { Subscription } from 'rxjs';

import { DynamicWrapper } from '../../utils/host-wrapping/dynamic-wrapper';
import { HostWrapper } from '../../utils/host-wrapping/host-wrapper';
import { CONTROL_SUFFIX } from './abstract-control';
import { IfControlStateService } from './if-control-state/if-control-state.service';
Expand All @@ -41,7 +40,7 @@ export enum CHANGE_KEYS {
}

@Directive()
export class WrappedFormControl<W extends DynamicWrapper> implements OnInit, DoCheck, OnDestroy {
export class WrappedFormControl<W> implements OnInit, DoCheck, OnDestroy {
_id: string;

protected controlIdService: ControlIdService;
Expand Down
7 changes: 1 addition & 6 deletions projects/angular/src/forms/radio/radio-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import { Component, ContentChild, OnInit } from '@angular/core';

import { DynamicWrapper } from '../../utils/host-wrapping/dynamic-wrapper';
import { ClrLabel } from '../common/label';
import { ControlIdService } from '../common/providers/control-id.service';

Expand All @@ -23,11 +22,7 @@ import { ControlIdService } from '../common/providers/control-id.service';
},
providers: [ControlIdService],
})
export class ClrRadioWrapper implements DynamicWrapper, OnInit {
// We need both _dynamic for HostWrapper and ContentChild(ClrLabel) in cases where
// the user puts a radio inside a wrapper without a label, host wrapping doesn't apply
// but we'd still need to insert a label
_dynamic = false;
export class ClrRadioWrapper implements OnInit {
@ContentChild(ClrLabel, { static: true }) label: ClrLabel;

ngOnInit() {
Expand Down
10 changes: 0 additions & 10 deletions projects/angular/src/utils/host-wrapping/dynamic-wrapper.ts

This file was deleted.

6 changes: 1 addition & 5 deletions projects/angular/src/utils/host-wrapping/host-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ import {
ViewContainerRef,
} from '@angular/core';

import { DynamicWrapper } from './dynamic-wrapper';
import { EmptyAnchor } from './empty-anchor';

/**
* HostWrapper must be called in OnInit to ensure that the Views are ready. If its called in a constructor the view is
* still undefined.
* TODO - make sure these comment annotations do not break ng-packgr.
*/
export class HostWrapper<W extends DynamicWrapper> implements Injector {
export class HostWrapper<W> implements Injector {
private injector: Injector;

constructor(containerType: Type<W>, vcr: ViewContainerRef, index = 0) {
Expand All @@ -47,9 +46,6 @@ export class HostWrapper<W extends DynamicWrapper> implements Injector {
// We can now remove the useless anchor
vcr.remove(0);

// We note that the container was dynamically created
containerRef.instance._dynamic = true;

// We keep the wrapper's injector to access the dependencies that weren't available before.
this.injector = containerRef.injector;
}
Expand Down
13 changes: 1 addition & 12 deletions projects/angular/src/utils/host-wrapping/host-wrapping.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

import { DynamicWrapper } from './dynamic-wrapper';
import { HostWrapper } from './host-wrapper';
import { ClrHostWrappingModule } from './host-wrapping.module';

Expand All @@ -21,9 +20,7 @@ const WRAPPER_SERVICE = new InjectionToken<number>('WrapperService');
template: `Hello <ng-content></ng-content>!`,
providers: [{ provide: WRAPPER_SERVICE, useValue: 42 }],
})
class WrapperComponent implements DynamicWrapper {
_dynamic = false;
}
class WrapperComponent {}

@Directive({
selector: '[wrappedDirective]',
Expand Down Expand Up @@ -94,10 +91,6 @@ describe('Host wrapping', function () {
expect(this.fixture.nativeElement.textContent.trim()).toBe('Hello World!');
});

it("doesn't mark the wrapper as dynamically created", function (this: TestContext<ExplicitTest>) {
expect(this.wrapper._dynamic).toBe(false);
});

it('proxies to the default injector', function (this: TestContext<ExplicitTest>) {
expect(this.wrapped.injected).toBe(42);
});
Expand All @@ -121,10 +114,6 @@ describe('Host wrapping', function () {
expect(this.fixture.nativeElement.textContent.trim()).toBe('Hello World!');
});

it('marks the wrapper as dynamically created', function (this: TestContext<WrappingTest>) {
expect(this.wrapper._dynamic).toBe(true);
});

it("proxies to the newly created wrapper's injector", function (this: TestContext<WrappingTest>) {
expect(this.wrapped.injected).toBe(42);
});
Expand Down

0 comments on commit 867322c

Please sign in to comment.