-
-
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.
docs(playground): 📘 update all playground examples
- Loading branch information
Showing
17 changed files
with
282 additions
and
202 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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
<h1>Observable</h1> | ||
@if(todosResult.result$ | async; as result) { @if(result.isLoading) { | ||
<p>Loading</p> | ||
} @if(result.isSuccess) { | ||
<p>{{ result.data[0].title }}</p> | ||
} @if(result.isError) { | ||
<p>Error</p> | ||
} } | ||
<div class="content"> | ||
<h1>Basic Example</h1> | ||
<p> | ||
This is a basic example of <code>injectQuery()</code>, it will fetch the specified todo from the API. | ||
</p> | ||
<p> | ||
To see the result changing, open the <b>devtools</b> in the <b>bottom-right</b> corner, from there you can | ||
trigger a refetch of the query, invalidate it or even trigger the loading and error state. | ||
Feel free to play around with it. | ||
</p> | ||
|
||
<h1>Signals</h1> | ||
<h3>Signal Result</h3> | ||
<blockquote> | ||
@if (todos();as result) { @if (result.isLoading) { | ||
<p>Loading</p> | ||
} @if (result.isSuccess) { | ||
<p>{{ result.data[0].title }}</p> | ||
} @if (result.isError) { | ||
<p>Error</p> | ||
} } | ||
</blockquote> | ||
|
||
@if(todos(); as result) { @if(result.isLoading) { | ||
<p>Loading</p> | ||
} @if(result.isSuccess) { | ||
<p>{{ result.data[0].title }}</p> | ||
} @if(result.isError) { | ||
<p>Error</p> | ||
} } | ||
<h3>Observable Result</h3> | ||
|
||
<h1>Signals Intersection</h1> | ||
@if(intersection(); as intersectionResult) { @if(intersectionResult.isLoading) { | ||
<p>Loading</p> | ||
} @if(intersectionResult.isSuccess) { | ||
<p>{{ intersectionResult.data }}</p> | ||
} @if(intersectionResult.isError) { | ||
<p>Error</p> | ||
} } | ||
<blockquote> | ||
@if (todosResult.result$ | async;as result) { @if (result.isLoading) { | ||
<p>Loading</p> | ||
} @if (result.isSuccess) { | ||
<p>{{ result.data[0].title }}</p> | ||
} @if (result.isError) { | ||
<p>Error</p> | ||
} } | ||
</blockquote> | ||
</div> |
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 |
---|---|---|
@@ -1,35 +1,20 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
Injector, | ||
inject, | ||
} from '@angular/core'; | ||
import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { TodosService } from '../services/todos.service'; | ||
import { intersectResults } from '@ngneat/query'; | ||
import { TabsComponent } from '../ui/query-tabs/tabs.component'; | ||
import { TabComponent } from '../ui/query-tab/tab.component'; | ||
|
||
@Component({ | ||
selector: 'query-todos-page', | ||
standalone: true, | ||
imports: [CommonModule], | ||
imports: [CommonModule, TabsComponent, TabComponent], | ||
templateUrl: './todos-page.component.html', | ||
styles: [], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class TodosPageComponent { | ||
#todosService = inject(TodosService); | ||
#injector = inject(Injector); | ||
|
||
todosResult = this.#todosService.getTodos(); | ||
todos = this.todosResult.result; | ||
|
||
intersection = intersectResults( | ||
[ | ||
this.#todosService.getTodo('1').result, | ||
this.#todosService.getTodo('2').result, | ||
], | ||
([todoOne, todoTwo]) => { | ||
return todoOne.title + todoTwo.title; | ||
} | ||
); | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/app/intersecting-page/intersecting-page.component.html
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,44 @@ | ||
<div class="content"> | ||
<h1>Intersecting Queries Example</h1> | ||
<p> | ||
This example uses the <code>intersectResults(mapFn)</code> method (for | ||
Signals) and <code>intersectResults$(mapFn)</code> operator (for RxJS | ||
Streams) to merge the results of two queries. | ||
</p> | ||
|
||
<p> | ||
The two queries <code>getTodo(1)</code> and <code>getTodo(2)</code> will be | ||
merged together and the result of each query will be concatenated into a | ||
single string. | ||
</p> | ||
|
||
<p> | ||
To see the result changing, open the <b>devtools</b> in the <b>bottom-right</b> corner, from there you can | ||
trigger a refetch of the query, invalidate it or even trigger the loading and error state. | ||
Feel free to play around with it. | ||
</p> | ||
|
||
<h3>Signal Result</h3> | ||
|
||
<blockquote> | ||
@if(intersection(); as intersectionResult) { @if(intersectionResult.isLoading) { | ||
<p>Loading</p> | ||
} @if(intersectionResult.isSuccess) { | ||
<p>{{ intersectionResult.data }}</p> | ||
} @if(intersectionResult.isError) { | ||
<p>Error</p> | ||
} } | ||
</blockquote> | ||
|
||
<h3>Observable Result</h3> | ||
|
||
<blockquote> | ||
@if(intersection$ | async; as intersectionResult) { @if(intersectionResult.isLoading) { | ||
<p>Loading</p> | ||
} @if(intersectionResult.isSuccess) { | ||
<p>{{ intersectionResult.data }}</p> | ||
} @if(intersectionResult.isError) { | ||
<p>Error</p> | ||
} } | ||
</blockquote> | ||
</div> |
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,39 @@ | ||
import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { TodosService } from '../services/todos.service'; | ||
import { intersectResults, intersectResults$ } from '@ngneat/query'; | ||
import { combineLatest } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'query-intersecting-page', | ||
standalone: true, | ||
imports: [CommonModule], | ||
templateUrl: './intersecting-page.component.html', | ||
styles: [], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class IntersectingPageComponent { | ||
#todosService = inject(TodosService); | ||
|
||
todosResult = this.#todosService.getTodos(); | ||
todos = this.todosResult.result; | ||
|
||
intersection = intersectResults( | ||
[ | ||
this.#todosService.getTodo('1').result, | ||
this.#todosService.getTodo('2').result, | ||
], | ||
([todoOne, todoTwo]) => { | ||
return todoOne.title + todoTwo.title; | ||
} | ||
); | ||
|
||
intersection$ = combineLatest({ | ||
todoOne: this.#todosService.getTodo('1').result$, | ||
todoTwo: this.#todosService.getTodo('2').result$, | ||
}).pipe( | ||
intersectResults$(({ todoOne, todoTwo }) => { | ||
return todoOne.title + todoTwo.title; | ||
}) | ||
); | ||
} |
Oops, something went wrong.