Skip to content

Commit a44c68e

Browse files
chore(demo): migrate to use onpush
1 parent 46c0077 commit a44c68e

60 files changed

Lines changed: 59 additions & 297 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/component-store/spec/integration.spec.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
Component,
3-
Type,
4-
Injectable,
5-
ChangeDetectionStrategy,
6-
} from '@angular/core';
1+
import { ChangeDetectorRef, Component, Type, Injectable } from '@angular/core';
72
import { ComponentStore } from '../src';
83
import {
94
TestBed,
@@ -111,8 +106,8 @@ describe('ComponentStore integration', () => {
111106
expect(state.prop2Changes).toEqual([undefined, 0, 1, 2, 3]);
112107

113108
state.parent.isChildVisible = false;
114-
state.fixture.changeDetectorRef.markForCheck();
115-
state.fixture.changeDetectorRef.detectChanges();
109+
state.fixture.componentRef.injector.get(ChangeDetectorRef).markForCheck();
110+
state.fixture.detectChanges();
116111

117112
tick(20);
118113
// Still at the same values, so effect stopped running
@@ -123,8 +118,8 @@ describe('ComponentStore integration', () => {
123118
state.child.init();
124119

125120
state.parent.isChildVisible = false;
126-
state.fixture.changeDetectorRef.markForCheck();
127-
state.fixture.changeDetectorRef.detectChanges();
121+
state.fixture.componentRef.injector.get(ChangeDetectorRef).markForCheck();
122+
state.fixture.detectChanges();
128123

129124
state.destroy();
130125

@@ -211,7 +206,6 @@ describe('ComponentStore integration', () => {
211206
<child></child>
212207
}`,
213208
standalone: false,
214-
changeDetection: ChangeDetectionStrategy.Eager,
215209
})
216210
class ParentComponent implements Parent {
217211
isChildVisible = true;

modules/component/spec/let/let.directive.spec.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
ChangeDetectionStrategy,
32
ChangeDetectorRef,
43
Component,
54
Directive,
@@ -37,7 +36,6 @@ import { LetDirective } from '../..';
3736
}}</ng-container>
3837
`,
3938
imports: [JsonPipe, LetDirective],
40-
changeDetection: ChangeDetectionStrategy.Eager,
4139
})
4240
class LetDirectiveTestComponent {
4341
value$: unknown;
@@ -50,7 +48,6 @@ class LetDirectiveTestComponent {
5048
}}</ng-container>
5149
`,
5250
imports: [LetDirective],
53-
changeDetection: ChangeDetectionStrategy.Eager,
5451
})
5552
class LetDirectiveTestErrorComponent {
5653
value$ = of(42);
@@ -63,7 +60,6 @@ class LetDirectiveTestErrorComponent {
6360
}}</ng-container>
6461
`,
6562
imports: [LetDirective],
66-
changeDetection: ChangeDetectionStrategy.Eager,
6763
})
6864
class LetDirectiveTestCompleteComponent {
6965
value$ = of(42);
@@ -74,7 +70,6 @@ class LetDirectiveTestCompleteComponent {
7470
<ng-container *ngrxLet="value$ as value">{{ value }}</ng-container>
7571
`,
7672
imports: [LetDirective],
77-
changeDetection: ChangeDetectionStrategy.Eager,
7873
})
7974
class LetDirectiveTestSuspenseComponent {
8075
value$ = of(42);
@@ -88,7 +83,6 @@ class LetDirectiveTestSuspenseComponent {
8883
<ng-template #loading>Loading...</ng-template>
8984
`,
9085
imports: [LetDirective],
91-
changeDetection: ChangeDetectionStrategy.Eager,
9286
})
9387
class LetDirectiveTestSuspenseTplComponent {
9488
value$ = of(42);
@@ -110,7 +104,6 @@ export class RecursiveDirective {
110104
}}</ng-container>
111105
`,
112106
imports: [RecursiveDirective, LetDirective],
113-
changeDetection: ChangeDetectionStrategy.Eager,
114107
})
115108
class LetDirectiveTestRecursionComponent {
116109
constructor(public subject: BehaviorSubject<number>) {}
@@ -220,7 +213,9 @@ const setupLetDirectiveTestRecursionComponent = (): void => {
220213
};
221214

222215
function markAndDetect() {
223-
fixtureLetDirectiveTestComponent.componentRef.changeDetectorRef.markForCheck();
216+
fixtureLetDirectiveTestComponent.componentRef.injector
217+
.get(ChangeDetectorRef)
218+
.markForCheck();
224219
fixtureLetDirectiveTestComponent.detectChanges();
225220
}
226221

modules/component/spec/push/push.pipe.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
ChangeDetectionStrategy,
32
ChangeDetectorRef,
43
Component,
54
ErrorHandler,
@@ -32,7 +31,6 @@ let pushPipe: PushPipe;
3231
@Component({
3332
template: ` {{ (value$ | ngrxPush | json) || 'undefined' }} `,
3433
imports: [PushPipe, JsonPipe],
35-
changeDetection: ChangeDetectionStrategy.Eager,
3634
})
3735
class PushPipeTestComponent {
3836
value$: unknown = of(42);
@@ -56,7 +54,9 @@ const setupPushPipeComponent = () => {
5654
};
5755

5856
function markAndDetect() {
59-
fixturePushPipeTestComponent.componentRef.changeDetectorRef.markForCheck();
57+
fixturePushPipeTestComponent.componentRef.injector
58+
.get(ChangeDetectorRef)
59+
.markForCheck();
6060
fixturePushPipeTestComponent.detectChanges();
6161
}
6262

projects/example-app/src/app/auth/components/login-form.component.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
Component,
3-
Input,
4-
Output,
5-
EventEmitter,
6-
ChangeDetectionStrategy,
7-
} from '@angular/core';
1+
import { Component, Input, Output, EventEmitter } from '@angular/core';
82
import { FormGroup, FormControl } from '@angular/forms';
93
import { Credentials } from '@example-app/auth/models';
104

@@ -84,7 +78,6 @@ import { Credentials } from '@example-app/auth/models';
8478
}
8579
`,
8680
],
87-
changeDetection: ChangeDetectionStrategy.Eager,
8881
standalone: false,
8982
})
9083
export class LoginFormComponent {

projects/example-app/src/app/auth/components/logout-confirmation-dialog.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ChangeDetectionStrategy } from '@angular/core';
1+
import { Component } from '@angular/core';
22

33
/**
44
* The dialog will close with true if user clicks the ok button,
@@ -31,7 +31,6 @@ import { Component, ChangeDetectionStrategy } from '@angular/core';
3131
}
3232
`,
3333
],
34-
changeDetection: ChangeDetectionStrategy.Eager,
3534
standalone: false,
3635
})
3736
export class LogoutConfirmationDialogComponent {}

projects/example-app/src/app/auth/containers/login-page.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ChangeDetectionStrategy } from '@angular/core';
1+
import { Component } from '@angular/core';
22
import { Store } from '@ngrx/store';
33
import { Credentials } from '@example-app/auth/models';
44
import * as fromAuth from '@example-app/auth/reducers';
@@ -15,7 +15,6 @@ import { LoginPageActions } from '@example-app/auth/actions/login-page.actions';
1515
</bc-login-form>
1616
`,
1717
styles: [],
18-
changeDetection: ChangeDetectionStrategy.Eager,
1918
standalone: false,
2019
})
2120
export class LoginPageComponent {

projects/example-app/src/app/books/components/book-authors.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
1+
import { Component, Input } from '@angular/core';
22

33
import { Book } from '@example-app/books/models';
44

@@ -17,7 +17,6 @@ import { Book } from '@example-app/books/models';
1717
}
1818
`,
1919
],
20-
changeDetection: ChangeDetectionStrategy.Eager,
2120
standalone: false,
2221
})
2322
export class BookAuthorsComponent {

projects/example-app/src/app/books/components/book-detail.component.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
Component,
3-
EventEmitter,
4-
Input,
5-
Output,
6-
ChangeDetectionStrategy,
7-
} from '@angular/core';
1+
import { Component, EventEmitter, Input, Output } from '@angular/core';
82

93
import { Book } from '@example-app/books/models';
104

@@ -73,7 +67,6 @@ import { Book } from '@example-app/books/models';
7367
}
7468
`,
7569
],
76-
changeDetection: ChangeDetectionStrategy.Eager,
7770
standalone: false,
7871
})
7972
export class BookDetailComponent {

projects/example-app/src/app/books/components/book-preview-list.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
1+
import { Component, Input } from '@angular/core';
22

33
import { Book } from '@example-app/books/models';
44

@@ -16,7 +16,6 @@ import { Book } from '@example-app/books/models';
1616
}
1717
`,
1818
],
19-
changeDetection: ChangeDetectionStrategy.Eager,
2019
standalone: false,
2120
})
2221
export class BookPreviewListComponent {

projects/example-app/src/app/books/components/book-preview.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
1+
import { Component, Input } from '@angular/core';
22

33
import { Book } from '@example-app/books/models';
44

@@ -76,7 +76,6 @@ import { Book } from '@example-app/books/models';
7676
}
7777
`,
7878
],
79-
changeDetection: ChangeDetectionStrategy.Eager,
8079
standalone: false,
8180
})
8281
export class BookPreviewComponent {

0 commit comments

Comments
 (0)