-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from luii/feature/map-results-data-docs
docs: add `mapResultsData` operator to `README.md` and playground
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
49 changes: 49 additions & 0 deletions
49
packages/playground/src/app/parallel-queries/parallel-queries-page.component.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {AsyncPipe, JsonPipe, NgIf} from '@angular/common'; | ||
import {Component, inject} from '@angular/core'; | ||
import {mapResultsData, QueryClientService} from '@ngneat/query'; | ||
import {SubscribeModule} from '@ngneat/subscribe'; | ||
import {combineLatest, Subject, switchMap} from 'rxjs'; | ||
import {GithubApiService} from '../github.service'; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [NgIf, SubscribeModule, AsyncPipe, JsonPipe], | ||
template: ` | ||
<ng-container *ngIf="repo$ | async as repo"> | ||
<p *ngIf="repo.isLoading">Loading...</p> | ||
<p *ngIf="repo.error">An error has occurred: {{ repo.error }}</p> | ||
<div *ngIf="repo.isSuccess"> | ||
<p><b>ngneat/query</b> {{ repo.data.ngQuery | json }}</p> | ||
<p><b>ngneat/spectator</b> {{ repo.data.spectator | json }}</p> | ||
</div> | ||
<div *ngIf="repo.isFetching">Updating...</div> | ||
</ng-container> | ||
<button (click)="invalidate()">Invalidate Queries</button> | ||
<button (click)="btn.next()">Switch to new Queries</button> | ||
` | ||
}) | ||
export class ParallelQueriesPageComponent { | ||
client = inject(QueryClientService); | ||
btn = new Subject<void>(); | ||
|
||
constructor(private githubApiService: GithubApiService) { | ||
} | ||
|
||
repo$ = this.btn.pipe( | ||
switchMap(() => combineLatest([ | ||
this.githubApiService.getRepository('ngneat/ng-query').result$, | ||
this.githubApiService.getRepository('ngneat/spectator').result$ | ||
])), | ||
mapResultsData(([ngQuery, spectator]) => { | ||
return { | ||
ngQuery, | ||
spectator | ||
}; | ||
}) | ||
); | ||
|
||
invalidate() { | ||
this.client.invalidateQueries(['repository', 'ngneat/ng-query']); | ||
this.client.invalidateQueries(['repository', 'ngneat/spectator']); | ||
} | ||
} |
This file contains 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