Skip to content

Commit b521392

Browse files
committed
fix: Drop model() in favor of input().
1 parent 187b290 commit b521392

14 files changed

+58
-55
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v17.2.0
4+
- Drop `model()` in favor of `input()` where possible.
5+
36
## v17.1.0
47
- Drop `@Input` in favor of `signals`.
58

src/lib/components/abstract.loader.directive.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
88
*/
99

10-
import { Directive, model } from '@angular/core';
10+
import { Directive, input } from '@angular/core';
1111

1212
@Directive()
1313
export abstract class AbstractLoaderDirective {
1414

15-
readonly backgroundColor = model<string>();
15+
readonly backgroundColor = input<string>();
1616
}

src/lib/components/ng-http-loader.component.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
88
*/
99

10-
import { Component, model, OnInit, Type } from '@angular/core';
10+
import { AsyncPipe, NgComponentOutlet, NgIf, NgStyle } from '@angular/common';
11+
import { Component, input, model, OnInit, Type } from '@angular/core';
1112
import { merge, Observable, partition, timer } from 'rxjs';
1213
import { debounce, distinctUntilChanged, switchMap, tap } from 'rxjs/operators';
14+
import { PendingRequestsInterceptorConfigurer } from '../services/pending-requests-interceptor-configurer.service';
1315
import { SpinnerVisibilityService } from '../services/spinner-visibility.service';
1416
import { Spinkit, SPINKIT_COMPONENTS } from '../spinkits';
15-
import { AsyncPipe, NgComponentOutlet, NgIf, NgStyle } from "@angular/common";
16-
import { PendingRequestsInterceptorConfigurer } from "../services/pending-requests-interceptor-configurer.service";
1717

1818
@Component({
1919
selector: 'ng-http-loader',
@@ -28,17 +28,17 @@ export class NgHttpLoaderComponent implements OnInit {
2828
isVisible$!: Observable<boolean>;
2929
visibleUntil = Date.now();
3030

31-
readonly backdrop = model<boolean>(true);
32-
readonly backgroundColor = model<string>();
33-
readonly debounceDelay = model<number>(0);
34-
readonly entryComponent = model<Type<unknown> | null>(null);
35-
readonly extraDuration = model<number>(0);
36-
readonly filteredHeaders = model<string[]>([]);
37-
readonly filteredMethods = model<string[]>([]);
38-
readonly filteredUrlPatterns = model<string[]>([]);
39-
readonly minDuration = model<number>(0);
40-
readonly opacity = model<string>('.7');
41-
readonly backdropBackgroundColor = model<string>('#f1f1f1');
31+
readonly backdrop = input<boolean>(true);
32+
readonly backgroundColor = input<string>();
33+
readonly debounceDelay = input<number>(0);
34+
readonly entryComponent = input<Type<unknown> | null>(null);
35+
readonly extraDuration = input<number>(0);
36+
readonly filteredHeaders = input<string[]>([]);
37+
readonly filteredMethods = input<string[]>([]);
38+
readonly filteredUrlPatterns = input<string[]>([]);
39+
readonly minDuration = input<number>(0);
40+
readonly opacity = input<string>('.7');
41+
readonly backdropBackgroundColor = input<string>('#f1f1f1');
4242
readonly spinner = model<string | null>(Spinkit.skWave);
4343

4444
constructor(private pendingRequestsInterceptorConfigurer: PendingRequestsInterceptorConfigurer, private spinnerVisibility: SpinnerVisibilityService) {
@@ -67,7 +67,7 @@ export class NgHttpLoaderComponent implements OnInit {
6767

6868
private nullifySpinnerIfEntryComponentIsDefined(): void {
6969
if (this.entryComponent()) {
70-
this.spinner.set(null);
70+
this.spinner.update(() => null);
7171
}
7272
}
7373

src/test/components/ng-http-loader.component.on-push.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { HttpTestingController, provideHttpClientTesting } from '@angular/common
1212
import { ChangeDetectionStrategy, Component } from '@angular/core';
1313
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
1414
import { By } from '@angular/platform-browser';
15-
import { NgHttpLoaderComponent } from "../../lib/components/ng-http-loader.component";
16-
import { pendingRequestsInterceptor$ } from "../../lib/services/pending-requests-interceptor";
15+
import { NgHttpLoaderComponent } from '../../lib/components/ng-http-loader.component';
16+
import { pendingRequestsInterceptor$ } from '../../lib/services/pending-requests-interceptor';
1717

1818
@Component({
1919
standalone: true,

src/test/components/ng-http-loader.component.outlet.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('NgHttpLoaderComponentOutlet', () => {
3232

3333
it('should be possible to specify an entryComponent', () => {
3434
component.isVisible$ = of(true);
35-
component.entryComponent.set(SkThreeBounceComponent);
35+
fixture.componentRef.setInput('entryComponent', SkThreeBounceComponent);
3636
fixture.detectChanges();
3737

3838
const element = fixture
@@ -45,7 +45,7 @@ describe('NgHttpLoaderComponentOutlet', () => {
4545

4646
it('should force [spinner] to null if [entryComponent] is defined', () => {
4747
component.spinner.set('spinner-name');
48-
component.entryComponent.set(SkThreeBounceComponent);
48+
fixture.componentRef.setInput('entryComponent', SkThreeBounceComponent);
4949
component.ngOnInit();
5050

5151
expect(component.spinner()).toBeNull();
@@ -54,7 +54,7 @@ describe('NgHttpLoaderComponentOutlet', () => {
5454
it('should correctly check [entryComponent] with null', () => {
5555
const spinnerName = 'spinner-name';
5656
component.spinner.set(spinnerName);
57-
component.entryComponent.set(null);
57+
fixture.componentRef.setInput('entryComponent', null);
5858
component.ngOnInit();
5959

6060
expect(component.spinner()).toBe(spinnerName);

src/test/components/ng-http-loader.component.spec.ts

+25-25
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angul
1313
import { By } from '@angular/platform-browser';
1414
import { forkJoin, Observable, of, Subscription } from 'rxjs';
1515
import { NgHttpLoaderComponent } from '../../lib/components/ng-http-loader.component';
16+
import { pendingRequestsInterceptor$ } from '../../lib/services/pending-requests-interceptor';
1617
import { SpinnerVisibilityService } from '../../lib/services/spinner-visibility.service';
1718
import { Spinkit } from '../../lib/spinkits';
18-
import { pendingRequestsInterceptor$ } from "../../lib/services/pending-requests-interceptor";
1919

2020
describe('NgHttpLoaderComponent', () => {
2121
let component: NgHttpLoaderComponent;
@@ -67,7 +67,7 @@ describe('NgHttpLoaderComponent', () => {
6767

6868
it('should not set the colored class if background-color is defined', () => {
6969
component.isVisible$ = of(true);
70-
component.backgroundColor.set('#ff0000');
70+
fixture.componentRef.setInput('backgroundColor', '#ff0000');
7171
fixture.detectChanges();
7272

7373
const element = fixture
@@ -101,7 +101,7 @@ describe('NgHttpLoaderComponent', () => {
101101

102102
it('should allow us to specify a custom background-color', () => {
103103
component.isVisible$ = of(true);
104-
component.backgroundColor.set('#ff0000');
104+
fixture.componentRef.setInput('backgroundColor', '#ff0000');
105105
fixture.detectChanges();
106106

107107
const element = fixture
@@ -271,7 +271,7 @@ describe('NgHttpLoaderComponent', () => {
271271
}));
272272

273273
it('should correctly handle the debounce delay for a single HTTP request', fakeAsync(() => {
274-
component.debounceDelay.set(2000);
274+
fixture.componentRef.setInput('debounceDelay', 2000);
275275
http.get('/fake').subscribe();
276276

277277
// the HTTP request is pending for 1 second now
@@ -297,7 +297,7 @@ describe('NgHttpLoaderComponent', () => {
297297
}));
298298

299299
it('should correctly handle the debounce delay for HTTP request finished before spinner should be shown', fakeAsync(() => {
300-
component.debounceDelay.set(2000);
300+
fixture.componentRef.setInput('debounceDelay', 2000);
301301
http.get('/fake').subscribe();
302302

303303
// the HTTP request is pending for 1 second now
@@ -311,7 +311,7 @@ describe('NgHttpLoaderComponent', () => {
311311
}));
312312

313313
it('should correctly handle the debounce delay for HTTP sequential requests finished before spinner should be shown', fakeAsync(() => {
314-
component.debounceDelay.set(5000);
314+
fixture.componentRef.setInput('debounceDelay', 5000);
315315
http.get('/fake').subscribe();
316316

317317
// the first HTTP request is pending for 1 second now
@@ -339,7 +339,7 @@ describe('NgHttpLoaderComponent', () => {
339339
}));
340340

341341
it('should correctly handle the debounce delay for HTTP parallel requests finished before spinner should be shown', fakeAsync(() => {
342-
component.debounceDelay.set(5000);
342+
fixture.componentRef.setInput('debounceDelay', 5000);
343343
http.get('/fake').subscribe();
344344
http.get('/fake2').subscribe();
345345

@@ -365,7 +365,7 @@ describe('NgHttpLoaderComponent', () => {
365365
}));
366366

367367
it('should correctly handle the debounce delay for multiple HTTP requests', fakeAsync(() => {
368-
component.debounceDelay.set(2000);
368+
fixture.componentRef.setInput('debounceDelay', 2000);
369369
const runQuery$ = (url: string): Observable<unknown> => http.get(url);
370370
forkJoin([runQuery$('/fake'), runQuery$('/fake2')]).subscribe();
371371
const firstRequest = httpMock.expectOne('/fake');
@@ -448,7 +448,7 @@ describe('NgHttpLoaderComponent', () => {
448448
}));
449449

450450
it('should correctly handle the minimum spinner duration for a single HTTP request', fakeAsync(() => {
451-
component.minDuration.set(5000);
451+
fixture.componentRef.setInput('minDuration', 5000);
452452
http.get('/fake').subscribe();
453453

454454
// the HTTP request is pending for 1 second now
@@ -482,7 +482,7 @@ describe('NgHttpLoaderComponent', () => {
482482
}));
483483

484484
it('should correctly handle the extra spinner duration for a single HTTP request', fakeAsync(() => {
485-
component.extraDuration.set(5000);
485+
fixture.componentRef.setInput('extraDuration', 5000);
486486
http.get('/fake').subscribe();
487487

488488
// the HTTP request is pending for 1 second now
@@ -508,7 +508,7 @@ describe('NgHttpLoaderComponent', () => {
508508
}));
509509

510510
it('should correctly handle the minimum spinner duration for multiple HTTP requests', fakeAsync(() => {
511-
component.minDuration.set(5000);
511+
fixture.componentRef.setInput('minDuration', 5000);
512512
const runQuery$ = (url: string): Observable<unknown> => http.get(url);
513513
forkJoin([runQuery$('/fake'), runQuery$('/fake2')]).subscribe();
514514
const firstRequest = httpMock.expectOne('/fake');
@@ -546,7 +546,7 @@ describe('NgHttpLoaderComponent', () => {
546546
}));
547547

548548
it('should correctly handle the extra spinner duration for multiple HTTP requests', fakeAsync(() => {
549-
component.extraDuration.set(5000);
549+
fixture.componentRef.setInput('extraDuration', 5000);
550550
const runQuery$ = (url: string): Observable<unknown> => http.get(url);
551551
forkJoin([runQuery$('/fake'), runQuery$('/fake2')]).subscribe();
552552
const firstRequest = httpMock.expectOne('/fake');
@@ -588,7 +588,7 @@ describe('NgHttpLoaderComponent', () => {
588588
}));
589589

590590
it('should correctly handle the minimum spinner duration for multiple HTTP requests ran one after the others', fakeAsync(() => {
591-
component.minDuration.set(2000);
591+
fixture.componentRef.setInput('minDuration', 2000);
592592
http.get('/fake').subscribe();
593593
const firstRequest = httpMock.expectOne('/fake');
594594

@@ -620,7 +620,7 @@ describe('NgHttpLoaderComponent', () => {
620620
}));
621621

622622
it('should handle the extra spinner duration for multiple HTTP requests ran one after the others', fakeAsync(() => {
623-
component.extraDuration.set(10);
623+
fixture.componentRef.setInput('extraDuration', 10);
624624
const runQuery$ = (url: string): Observable<unknown> => http.get(url);
625625
runQuery$('/fake').subscribe();
626626
const firstRequest = httpMock.expectOne('/fake');
@@ -648,7 +648,7 @@ describe('NgHttpLoaderComponent', () => {
648648
}));
649649

650650
it('should still display the spinner when the minimum duration is inferior to the HTTP request duration', fakeAsync(() => {
651-
component.minDuration.set(1000);
651+
fixture.componentRef.setInput('minDuration', 1000);
652652
http.get('/fake').subscribe();
653653

654654
// the HTTP request is pending for 1 second now
@@ -666,7 +666,7 @@ describe('NgHttpLoaderComponent', () => {
666666
}));
667667

668668
it('should be possible to set the minimum duration without side effect on manual show/hide', () => {
669-
component.minDuration.set(10000);
669+
fixture.componentRef.setInput('minDuration', 10000);
670670
spinner.show();
671671
expect(isVisible).toBeTruthy();
672672

@@ -675,7 +675,7 @@ describe('NgHttpLoaderComponent', () => {
675675
});
676676

677677
it('should be possible to set the extra duration without side effect on manual show/hide', () => {
678-
component.extraDuration.set(10000);
678+
fixture.componentRef.setInput('extraDuration', 10000);
679679
spinner.show();
680680
expect(isVisible).toBeTruthy();
681681

@@ -685,8 +685,8 @@ describe('NgHttpLoaderComponent', () => {
685685

686686
it('should be possible to mix debounce delay and minimum duration', fakeAsync(() => {
687687
// the spinner should not be visible the first second, then visible for 5 seconds
688-
component.minDuration.set(5000);
689-
component.debounceDelay.set(1000);
688+
fixture.componentRef.setInput('minDuration', 5000);
689+
fixture.componentRef.setInput('debounceDelay', 1000);
690690

691691
http.get('/fake').subscribe();
692692

@@ -718,8 +718,8 @@ describe('NgHttpLoaderComponent', () => {
718718

719719
it('should be possible to mix debounce delay and extra duration', fakeAsync(() => {
720720
// the spinner should not be visible the first second, then visible for 5 seconds
721-
component.extraDuration.set(5000);
722-
component.debounceDelay.set(1000);
721+
fixture.componentRef.setInput('extraDuration', 5000);
722+
fixture.componentRef.setInput('debounceDelay', 1000);
723723

724724
http.get('/fake').subscribe();
725725

@@ -763,7 +763,7 @@ describe('NgHttpLoaderComponent', () => {
763763

764764
it('should be possible to remove the backdrop CSS class', () => {
765765
component.isVisible$ = of(true);
766-
component.backdrop.set(false);
766+
fixture.componentRef.setInput('backdrop', false);
767767
fixture.detectChanges();
768768

769769
const element = fixture
@@ -787,7 +787,7 @@ describe('NgHttpLoaderComponent', () => {
787787

788788
it('should be possible to override opacity', () => {
789789
component.isVisible$ = of(true);
790-
component.opacity.set('.3');
790+
fixture.componentRef.setInput('opacity', '.3');
791791
fixture.detectChanges();
792792

793793
const element: HTMLElement = fixture
@@ -812,7 +812,7 @@ describe('NgHttpLoaderComponent', () => {
812812

813813
it('should be possible to override backdrop background color when backdrop is true', () => {
814814
component.isVisible$ = of(true);
815-
component.backdropBackgroundColor.set('#777777');
815+
fixture.componentRef.setInput('backdropBackgroundColor', '#777777');
816816
fixture.detectChanges();
817817

818818
const element: HTMLElement = fixture
@@ -825,7 +825,7 @@ describe('NgHttpLoaderComponent', () => {
825825

826826
it('should not have a transparent backdrop background color if backdrop is false', () => {
827827
component.isVisible$ = of(true);
828-
component.backdrop.set(false);
828+
fixture.componentRef.setInput('backdrop', false);
829829
fixture.detectChanges();
830830

831831
const element: HTMLElement = fixture

src/test/components/sk-chasing-dots/sk-chasing-dots.component.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('SkChasingDotsComponent', () => {
3232
});
3333

3434
it('should be possible to set background-color', () => {
35-
component.backgroundColor.set('#ff0000');
35+
fixture.componentRef.setInput('backgroundColor', '#ff0000');
3636
fixture.detectChanges();
3737

3838
const element = fixture

src/test/components/sk-cube-grid/sk-cube-grid.component.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('SkCubeGridComponent', () => {
3232
});
3333

3434
it('should be possible to set background-color', () => {
35-
component.backgroundColor.set('#ff0000');
35+
fixture.componentRef.setInput('backgroundColor', '#ff0000');
3636
fixture.detectChanges();
3737

3838
const element = fixture

src/test/components/sk-double-bounce/sk-double-bounce.component.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('SkDoubleBounceComponent', () => {
3232
});
3333

3434
it('should be possible to set background-color', () => {
35-
component.backgroundColor.set('#ff0000');
35+
fixture.componentRef.setInput('backgroundColor', '#ff0000');
3636
fixture.detectChanges();
3737

3838
const element = fixture

src/test/components/sk-rotating-plane/sk-rotating-plane.component.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('SkRotatingPlaneComponent', () => {
3232
});
3333

3434
it('should be possible to set background-color', () => {
35-
component.backgroundColor.set('#ff0000');
35+
fixture.componentRef.setInput('backgroundColor', '#ff0000');
3636
fixture.detectChanges();
3737

3838
const element = fixture

src/test/components/sk-spinner-pulse/sk-spinner-pulse.component.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('SkSpinnerPulseComponent', () => {
3232
});
3333

3434
it('should be possible to set background-color', () => {
35-
component.backgroundColor.set('#ff0000');
35+
fixture.componentRef.setInput('backgroundColor', '#ff0000');
3636
fixture.detectChanges();
3737

3838
const element = fixture

src/test/components/sk-three-bounce/sk-three-bounce.component.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('SkThreeBounceComponent', () => {
3232
});
3333

3434
it('should be possible to set background-color', () => {
35-
component.backgroundColor.set('#ff0000');
35+
fixture.componentRef.setInput('backgroundColor', '#ff0000');
3636
fixture.detectChanges();
3737

3838
const element = fixture

src/test/components/sk-wandering-cubes/sk-wandering-cubes.component.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('SkWanderingCubesComponent', () => {
3232
});
3333

3434
it('should be possible to set background-color', () => {
35-
component.backgroundColor.set('#ff0000');
35+
fixture.componentRef.setInput('backgroundColor', '#ff0000');
3636
fixture.detectChanges();
3737

3838
const element = fixture

src/test/components/sk-wave/sk-wave.component.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('SkWaveComponent', () => {
3232
});
3333

3434
it('should be possible to set background-color', () => {
35-
component.backgroundColor.set('#ff0000');
35+
fixture.componentRef.setInput('backgroundColor', '#ff0000');
3636
fixture.detectChanges();
3737

3838
const element = fixture

0 commit comments

Comments
 (0)