File tree 8 files changed +152
-10
lines changed
shared/debug-helper/visualizer/visualizer
8 files changed +152
-10
lines changed Original file line number Diff line number Diff line change
1
+ import { ChangeDetectionStrategy , Component , OnInit } from '@angular/core' ;
2
+ import { Subject } from 'rxjs' ;
3
+ import { map } from 'rxjs/operators' ;
4
+
5
+ @Component ( {
6
+ selector : 'rx-chunk-basic' ,
7
+ template : `
8
+ <rxa-visualizer>
9
+ <ng-container visualizerHeader>
10
+ <h3>*rxChunk</h3>
11
+ <rxa-strategy-select
12
+ (strategyChange)="strategy = $event"
13
+ ></rxa-strategy-select>
14
+ <div>
15
+ Rendercallback:
16
+ <ng-container *rxLet="rendered$; let rendered">{{
17
+ rendered
18
+ }}</ng-container>
19
+ </div>
20
+ <div>
21
+ <button mat-button (click)="showContent = !showContent">
22
+ Toggle Content
23
+ </button>
24
+ </div>
25
+ </ng-container>
26
+ <div class="row w-100 mt-5">
27
+ <ng-container *ngIf="showContent">
28
+ <div class="col-6">
29
+ <div><strong>Non-Chunked</strong></div>
30
+ <rxa-work-visualizer
31
+ [reCreateContentOnCd]="false"
32
+ [work]="250"
33
+ ></rxa-work-visualizer>
34
+ </div>
35
+ <div class="col-6">
36
+ <div><strong>Chunked</strong></div>
37
+ <ng-container *rxChunk="strategy; renderCallback: renderCallback">
38
+ <rxa-work-visualizer
39
+ [reCreateContentOnCd]="false"
40
+ [work]="250"
41
+ ></rxa-work-visualizer>
42
+ </ng-container>
43
+ </div>
44
+ </ng-container>
45
+ </div>
46
+ </rxa-visualizer>
47
+ ` ,
48
+ changeDetection : ChangeDetectionStrategy . OnPush ,
49
+ } )
50
+ export class RxChunkBasicComponent {
51
+ strategy : string ;
52
+
53
+ showContent = true ;
54
+
55
+ renderCallback = new Subject < void > ( ) ;
56
+ private _rendered = 1 ;
57
+ rendered$ = this . renderCallback . pipe ( map ( ( ) => this . _rendered ++ ) ) ;
58
+ }
Original file line number Diff line number Diff line change
1
+ import { CommonModule } from '@angular/common' ;
2
+ import { NgModule } from '@angular/core' ;
3
+ import { MatButtonModule } from '@angular/material/button' ;
4
+ import { RouterModule , Routes } from '@angular/router' ;
5
+ import { RxChunk } from '@rx-angular/template/chunk' ;
6
+ import { RxLet } from '@rx-angular/template/let' ;
7
+ import { RenderingWorkModule } from '../../../../shared/debug-helper/rendering-work/rendering-work.module' ;
8
+ import { StrategySelectModule } from '../../../../shared/debug-helper/strategy-select/index' ;
9
+ import { VisualizerModule } from '../../../../shared/debug-helper/visualizer/index' ;
10
+ import { WorkModule } from '../../../../shared/debug-helper/work/work.module' ;
11
+ import { RxChunkBasicComponent } from './rx-chunk-basic.component' ;
12
+
13
+ const routes : Routes = [
14
+ {
15
+ path : '' ,
16
+ component : RxChunkBasicComponent ,
17
+ } ,
18
+ ] ;
19
+
20
+ @NgModule ( {
21
+ imports : [
22
+ RouterModule . forChild ( routes ) ,
23
+ VisualizerModule ,
24
+ StrategySelectModule ,
25
+ RxChunk ,
26
+ CommonModule ,
27
+ RxLet ,
28
+ RenderingWorkModule ,
29
+ WorkModule ,
30
+ MatButtonModule ,
31
+ ] ,
32
+ exports : [ ] ,
33
+ declarations : [ RxChunkBasicComponent ] ,
34
+ providers : [ ] ,
35
+ } )
36
+ export class RxChunkBasicModule { }
Original file line number Diff line number Diff line change
1
+ import { NgModule } from '@angular/core' ;
2
+ import { CommonModule } from '@angular/common' ;
3
+ import { RouterModule } from '@angular/router' ;
4
+ import { ROUTES } from './rx-chunk.routes' ;
5
+
6
+ @NgModule ( {
7
+ imports : [ CommonModule , RouterModule . forChild ( ROUTES ) ] ,
8
+ } )
9
+ export class RxChunkDemoModule { }
Original file line number Diff line number Diff line change
1
+ export const RX_CHUNK_MENU_ITEMS = [
2
+ {
3
+ label : 'Basic' ,
4
+ link : 'basic' ,
5
+ } ,
6
+ ] ;
Original file line number Diff line number Diff line change
1
+ import { Routes } from '@angular/router' ;
2
+
3
+ export const ROUTES : Routes = [
4
+ {
5
+ path : '' ,
6
+ redirectTo : 'basic' ,
7
+ pathMatch : 'full' ,
8
+ } ,
9
+ {
10
+ path : 'basic' ,
11
+ loadChildren : ( ) =>
12
+ import ( './basic/rx-chunk-basic.module' ) . then ( ( m ) => m . RxChunkBasicModule ) ,
13
+ } ,
14
+ ] ;
Original file line number Diff line number Diff line change
1
+ import { RX_CHUNK_MENU_ITEMS } from './chunk/rx-chunk.menu' ;
1
2
import { PUSH_PIPE_MENU } from './push/push.menu' ;
2
3
import { MENU_ITEMS as RX_LET_MENU_ITEMS } from './rx-let/rx-let.menu' ;
3
4
import { MENU_ITEMS as RX_IF_MENU_ITEMS } from './rx-if/rx-if.menu' ;
@@ -39,6 +40,11 @@ export const TEMPLATE_MENU = [
39
40
link : 'rx-for' ,
40
41
children : RX_FOR_MENU_ITEMS ,
41
42
} ,
43
+ {
44
+ label : '*rxChunk' ,
45
+ link : 'rx-chunk' ,
46
+ children : RX_CHUNK_MENU_ITEMS ,
47
+ } ,
42
48
{
43
49
label : 'Virtual Scrolling' ,
44
50
link : 'rx-virtual-for' ,
Original file line number Diff line number Diff line change @@ -17,6 +17,11 @@ const ROUTES: Routes = [
17
17
loadChildren : ( ) =>
18
18
import ( './rx-let/rx-let-demo.module' ) . then ( ( m ) => m . RxLetDemoModule ) ,
19
19
} ,
20
+ {
21
+ path : 'rx-chunk' ,
22
+ loadChildren : ( ) =>
23
+ import ( './chunk/rx-chunk-demo.module' ) . then ( ( m ) => m . RxChunkDemoModule ) ,
24
+ } ,
20
25
{
21
26
path : 'rx-if' ,
22
27
loadChildren : ( ) =>
@@ -31,7 +36,7 @@ const ROUTES: Routes = [
31
36
path : 'rx-virtual-for' ,
32
37
loadChildren : ( ) =>
33
38
import ( './rx-virtual-for/rx-virtual-for.module' ) . then (
34
- ( m ) => m . RxVirtualForDemoModule
39
+ ( m ) => m . RxVirtualForDemoModule ,
35
40
) ,
36
41
} ,
37
42
{
@@ -48,7 +53,7 @@ const ROUTES: Routes = [
48
53
path : 'rx-context' ,
49
54
loadChildren : ( ) =>
50
55
import ( './rx-context/rx-context.routed.module' ) . then (
51
- ( m ) => m . RxContextRoutedModule
56
+ ( m ) => m . RxContextRoutedModule ,
52
57
) ,
53
58
} ,
54
59
{
@@ -60,14 +65,14 @@ const ROUTES: Routes = [
60
65
path : 'view-port-prio' ,
61
66
loadChildren : ( ) =>
62
67
import ( './viewport-prio/viewport-prio-demo.module' ) . then (
63
- ( m ) => m . ViewportPrioModule
68
+ ( m ) => m . ViewportPrioModule ,
64
69
) ,
65
70
} ,
66
71
{
67
72
path : 'render-callback' ,
68
73
loadChildren : ( ) =>
69
74
import ( './render-callback/render-callback.module' ) . then (
70
- ( m ) => m . RenderCallbackModule
75
+ ( m ) => m . RenderCallbackModule ,
71
76
) ,
72
77
} ,
73
78
] ;
Original file line number Diff line number Diff line change @@ -81,6 +81,8 @@ export class WorkVisualizerComponent extends Hooks {
81
81
@Input ( )
82
82
renderingsOn = false ;
83
83
84
+ @Input ( ) reCreateContentOnCd = true ;
85
+
84
86
changeO$ = new ReplaySubject < Observable < any > > ( 1 ) ;
85
87
86
88
@Input ( )
@@ -105,24 +107,30 @@ export class WorkVisualizerComponent extends Hooks {
105
107
this . changeO$ . pipe (
106
108
distinctUntilChanged ( ) ,
107
109
switchMap ( ( o$ ) =>
108
- ! ! this . key ? o$ . pipe ( map ( ( s ) => s [ this . key ] ) ) : o$
110
+ ! ! this . key ? o$ . pipe ( map ( ( s ) => s [ this . key ] ) ) : o$ ,
109
111
) ,
110
112
distinctUntilChanged ( ) ,
111
- tap ( ( v ) => console . log ( 'value' , v ) )
112
- )
113
- )
114
- )
113
+ tap ( ( v ) => console . log ( 'value' , v ) ) ,
114
+ ) ,
115
+ ) ,
116
+ ) ,
115
117
) ;
116
118
119
+ private items : any [ ] ;
120
+
117
121
constructor ( ) {
118
122
super ( ) ;
119
123
}
120
124
121
125
getChildren ( ) : number [ ] {
126
+ if ( ! this . reCreateContentOnCd && this . items ) {
127
+ return this . items ;
128
+ }
122
129
const items = [ ] ;
123
130
for ( let i = 0 ; i <= this . work * 10 ; i ++ ) {
124
131
items . push ( Math . ceil ( Math . random ( ) * 100 ) ) ;
125
132
}
126
- return items ;
133
+ this . items = items ;
134
+ return this . items ;
127
135
}
128
136
}
You can’t perform that action at this time.
0 commit comments