This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe('CatService', () => { | |
| let classUnderTest: CatService; | |
| beforeAll(() => { | |
| classUnderTest = new CatService(); | |
| }); | |
| it('returns undefined for an unknown cat breed', () => { | |
| const result = classUnderTest.getBreed('Maine Coon'); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| productsData$ = this.loadProductsClicks$.pipe( | |
| switchMap(() => this.http.get('/api/products').pipe(trackRemoteData())) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'app-products', | |
| template: ` | |
| <button (click)="loadProducts()">Load Products</button> | |
| <ng-container *ngIf="productsData$ | async as productsData"> | |
| <ng-container *ngIf="productsData.state === 'loading'"> | |
| Loading... | |
| </ng-container> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'app-products', | |
| template: ` | |
| <button (click)="loadProducts()">Load Products</button> | |
| <ng-container *ngIf="productsData.state === 'loading'"> | |
| Loading... | |
| </ng-container> | |
| <ng-container *ngIf="productsData.state === 'error'"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type RemoteData<T = unknown, E = Error> = | |
| | NotAskedState<T> | |
| | LoadingState<T> | |
| | SuccessState<T> | |
| | ErrorState<T, E>; | |
| export interface LoadingState<T = unknown> { | |
| readonly state: 'loading'; | |
| readonly isLoading: true; | |
| readonly value?: T; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function loadingState(): LoadingState { | |
| return { | |
| state: 'loading', | |
| isLoading: true, | |
| value, | |
| }; | |
| } | |
| function successState<T>(value?: T): SuccessState<T> { | |
| return { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface RemoteData<T, E> { | |
| state: 'notAsked' | 'loading' | 'success' | 'error'; | |
| isLoading: boolean; | |
| value?: T; | |
| error?: E; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'app-products', | |
| template: ` | |
| <button (click)="loadProducts()">Load Products</button> | |
| <ng-container *ngIf="isLoading else doneLoading"> | |
| Loading... | |
| </ng-container> | |
| <ng-template #doneLoading> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'app-products', | |
| template: ` | |
| <button (click)="loadProducts()">Load Products</button> | |
| <ng-container *ngIf="isLoading"> | |
| Loading... | |
| </ng-container> | |
| <ng-container *ngIf="!isLoading"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'app-products', | |
| template: ` | |
| <button (click)="loadProducts()">Load Products</button> | |
| <ng-container *ngFor="let product of products"> | |
| <app-product [product]="product"></app-product> | |
| </ng-container> | |
| ` | |
| }) |
NewerOlder