Skip to content

Commit 30cefde

Browse files
committed
Add asyncPipe example
1 parent 9b9db1c commit 30cefde

File tree

7 files changed

+58
-20
lines changed

7 files changed

+58
-20
lines changed

angular-app/src/app/app-routing.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
PATH_ROUTER_EVENTS,
1010
PATH_ROUTER_PARAM_MAP,
1111
PATH_RXJS_TIMER,
12-
PATH_RXJS_TIMER_COMPLETE,
12+
PATH_RXJS_TIMER_COMPLETE, PATH_UNSUBSCRIPTION_ASYNC_PIPE,
1313
PATH_UNSUBSCRIPTION_GATHER,
1414
PATH_UNSUBSCRIPTION_TAKE_UNTIL, PATH_UNSUBSCRIPTION_TAKE_UNTIL_DESTROYED,
1515
PATH_UNSUBSCRIPTION_UNTIL_DESTROYED
@@ -27,6 +27,7 @@ import {UntilDestroyedComponent} from "./unsubscription-methods/until-destroyed/
2727
import {
2828
TakeUntilDestroyedComponent
2929
} from "./unsubscription-methods/take-until-destroyed/take-until-destroyed.component";
30+
import {AsyncPipeComponent} from "./unsubscription-methods/async-pipe/async-pipe.component";
3031

3132

3233
const routes: Routes = [
@@ -42,6 +43,7 @@ const routes: Routes = [
4243
{path: PATH_UNSUBSCRIPTION_TAKE_UNTIL, component: TakeUntilComponent},
4344
{path: PATH_UNSUBSCRIPTION_UNTIL_DESTROYED, component: UntilDestroyedComponent},
4445
{path: PATH_UNSUBSCRIPTION_TAKE_UNTIL_DESTROYED, component: TakeUntilDestroyedComponent},
46+
{path: PATH_UNSUBSCRIPTION_ASYNC_PIPE, component: AsyncPipeComponent},
4547
];
4648

4749
@NgModule({

angular-app/src/app/app.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ <h2>Unsubscription methods</h2>
4444
<li>
4545
<a [routerLink]="RoutingLinks.unsubscriptionGather">Unsubscribe with subscription gathering</a>
4646
</li>
47+
<li>
48+
<a [routerLink]="RoutingLinks.unsubscriptionAsyncPipe">Async pipe</a>
49+
</li>
4750
</ul>
4851
<hr>
4952
<router-outlet></router-outlet>

angular-app/src/app/app.module.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
import { BrowserModule } from '@angular/platform-browser';
2-
import { NgModule } from '@angular/core';
1+
import {BrowserModule} from '@angular/platform-browser';
2+
import {NgModule} from '@angular/core';
33

4-
import { AppRoutingModule } from './app-routing.module';
5-
import { AppComponent } from './app.component';
6-
import { RxjsTimerComponent } from './rxjs-timer/rxjs-timer.component';
7-
import { EmptyComponent } from './empty/empty.component';
8-
import { RxjsTimerCompleteComponent } from './rxjs-timer-complete/rxjs-timer-complete.component';
9-
import { HttpclientComponent } from './httpclient/httpclient.component';
4+
import {AppRoutingModule} from './app-routing.module';
5+
import {AppComponent} from './app.component';
6+
import {RxjsTimerComponent} from './rxjs-timer/rxjs-timer.component';
7+
import {EmptyComponent} from './empty/empty.component';
8+
import {RxjsTimerCompleteComponent} from './rxjs-timer-complete/rxjs-timer-complete.component';
9+
import {HttpclientComponent} from './httpclient/httpclient.component';
1010
import {HttpClientModule} from '@angular/common/http';
11-
import { GatherSubscriptionsComponent } from './unsubscription-methods/gather-subscriptions/gather-subscriptions.component';
12-
import { TakeUntilComponent } from './unsubscription-methods/take-until/take-until.component';
13-
import { UntilDestroyedComponent } from './unsubscription-methods/until-destroyed/until-destroyed.component';
14-
import { RouterParamMapComponent } from './router-param-map/router-param-map.component';
15-
import { RouterEventsComponent } from './router-events/router-events.component';
16-
import { ComponentTreeComponent } from './component-tree/component-tree.component';
17-
import { SubComponentOneComponent } from './component-tree/sub-component-one/sub-component-one.component';
18-
import { SubComponentTwoComponent } from './component-tree/sub-component-one/sub-component-two/sub-component-two.component';
11+
import {
12+
GatherSubscriptionsComponent
13+
} from './unsubscription-methods/gather-subscriptions/gather-subscriptions.component';
14+
import {TakeUntilComponent} from './unsubscription-methods/take-until/take-until.component';
15+
import {UntilDestroyedComponent} from './unsubscription-methods/until-destroyed/until-destroyed.component';
16+
import {RouterParamMapComponent} from './router-param-map/router-param-map.component';
17+
import {RouterEventsComponent} from './router-events/router-events.component';
18+
import {ComponentTreeComponent} from './component-tree/component-tree.component';
19+
import {SubComponentOneComponent} from './component-tree/sub-component-one/sub-component-one.component';
20+
import {
21+
SubComponentTwoComponent
22+
} from './component-tree/sub-component-one/sub-component-two/sub-component-two.component';
1923
import {
2024
TakeUntilDestroyedComponent
2125
} from "./unsubscription-methods/take-until-destroyed/take-until-destroyed.component";
26+
import {AsyncPipeComponent} from "./unsubscription-methods/async-pipe/async-pipe.component";
27+
import {CommonModule} from '@angular/common';
2228

2329
@NgModule({
2430
declarations: [
@@ -35,14 +41,17 @@ import {
3541
ComponentTreeComponent,
3642
SubComponentOneComponent,
3743
SubComponentTwoComponent,
38-
TakeUntilDestroyedComponent
44+
TakeUntilDestroyedComponent,
45+
AsyncPipeComponent
3946
],
4047
imports: [
4148
BrowserModule,
4249
AppRoutingModule,
43-
HttpClientModule
50+
HttpClientModule,
51+
CommonModule
4452
],
4553
providers: [],
4654
bootstrap: [AppComponent]
4755
})
48-
export class AppModule { }
56+
export class AppModule {
57+
}

angular-app/src/app/routing-links.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const PATH_UNSUBSCRIPTION_GATHER = 'unsubscription-gather';
99
export const PATH_UNSUBSCRIPTION_TAKE_UNTIL = 'unsubscription-take-until';
1010
export const PATH_UNSUBSCRIPTION_UNTIL_DESTROYED = 'unsubscription-until-destroyed';
1111
export const PATH_UNSUBSCRIPTION_TAKE_UNTIL_DESTROYED = 'unsubscription-take-until-destroyed';
12+
export const PATH_UNSUBSCRIPTION_ASYNC_PIPE = 'unsubscription-async-pipe';
1213

1314
export class RoutingLinks {
1415
static emptyComponent = PATH_EMPTY;
@@ -22,4 +23,5 @@ export class RoutingLinks {
2223
static unsubscriptionTakeUntil = PATH_UNSUBSCRIPTION_TAKE_UNTIL;
2324
static unsubscriptionUntilDestroyed = PATH_UNSUBSCRIPTION_UNTIL_DESTROYED;
2425
static unsubscriptionTakeUntilDestroyed = PATH_UNSUBSCRIPTION_TAKE_UNTIL_DESTROYED;
26+
static unsubscriptionAsyncPipe = PATH_UNSUBSCRIPTION_ASYNC_PIPE;
2527
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{ everySecond$ | async }}
2+
{{ everyThirdSecond$ | async }}

angular-app/src/app/unsubscription-methods/async-pipe/async-pipe.component.scss

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {Component} from '@angular/core';
2+
import {tap, timer} from 'rxjs';
3+
4+
@Component({
5+
selector: 'app-until-destroyed',
6+
templateUrl: './async-pipe.component.html',
7+
styleUrls: ['./async-pipe.component.scss']
8+
})
9+
export class AsyncPipeComponent {
10+
11+
everySecond$ = timer(0, 1000).pipe(
12+
tap(() => console.log("AsyncPipeComponent everySecond$ emitted"))
13+
);
14+
everyThirdSecond$ = timer(0, 3000).pipe(
15+
tap(() => console.log("AsyncPipeComponent everyThirdSecond$ emitted"))
16+
);
17+
18+
constructor() {
19+
}
20+
}

0 commit comments

Comments
 (0)