Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ed3e97

Browse files
committed
feat(template): migrate PushPipe to standalone API
1 parent a342dfe commit 3ed3e97

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

libs/template/push/src/lib/push.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { NgModule } from '@angular/core';
22

33
import { PushPipe } from './push.pipe';
44

5+
/** @deprecated use the standalone import, will be removed with v16 */
56
@NgModule({
6-
declarations: [PushPipe],
7+
imports: [PushPipe],
78
exports: [PushPipe],
89
})
910
export class PushModule {}

libs/template/push/src/lib/push.pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import {
8484
*
8585
* @publicApi
8686
*/
87-
@Pipe({ name: 'push', pure: false })
87+
@Pipe({ name: 'push', pure: false, standalone: true })
8888
export class PushPipe implements PipeTransform, OnDestroy {
8989
/**
9090
* @internal

libs/template/push/src/lib/tests/push.pipe.spec.ts

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1-
21
import {
32
RX_RENDER_STRATEGIES_CONFIG,
43
RxStrategyCredentials,
5-
RxStrategyProvider
4+
RxStrategyProvider,
65
} from '@rx-angular/cdk/render-strategies';
76
import { map, tap } from 'rxjs/operators';
87
import { Promise as unpatchedPromise } from '@rx-angular/cdk/zone-less/browser';
98
import { PushModule } from '../push.module';
109
import { PushPipe } from '../push.pipe';
1110
import { ComponentFixture, TestBed } from '@angular/core/testing';
1211
import { ChangeDetectorRef, Component } from '@angular/core';
13-
import { asapScheduler, EMPTY, from, NEVER, Observable, of, scheduled, share, shareReplay, timer } from 'rxjs';
12+
import {
13+
asapScheduler,
14+
EMPTY,
15+
from,
16+
NEVER,
17+
Observable,
18+
of,
19+
scheduled,
20+
share,
21+
shareReplay,
22+
timer,
23+
} from 'rxjs';
1424
import { mockConsole } from '@test-helpers';
1525

1626
function wrapWithSpace(str: string): string {
1727
return ' ' + str + ' ';
1828
}
1929

2030
@Component({
21-
template: ` {{ (value$ | push: strategy | json) || 'undefined' }} `,
31+
template: ` {{ (value$ | push : strategy | json) || 'undefined' }} `,
2232
})
2333
class PushPipeTestComponent {
2434
value$: Observable<number> = of(42);
@@ -36,22 +46,25 @@ let strategyProvider: RxStrategyProvider;
3646
const setupPushPipeComponent = () => {
3747
TestBed.configureTestingModule({
3848
declarations: [PushPipeTestComponent],
39-
imports: [PushModule],
49+
imports: [PushPipe],
4050
providers: [
4151
ChangeDetectorRef,
4252
{
4353
provide: RX_RENDER_STRATEGIES_CONFIG,
4454
useValue: {
4555
primaryStrategy: 'native',
4656
customStrategies: {
47-
'custom': {
57+
custom: {
4858
name: 'custom',
49-
work: cdRef => {
59+
work: (cdRef) => {
5060
cdRef.detectChanges();
5161
},
52-
behavior: ({ work }) => o$ => o$.pipe(tap(() => work()))
53-
}
54-
}
62+
behavior:
63+
({ work }) =>
64+
(o$) =>
65+
o$.pipe(tap(() => work())),
66+
},
67+
},
5568
},
5669
},
5770
],
@@ -138,7 +151,7 @@ describe('PushPipe used as pipe in the template', () => {
138151
const strategy = strategyProvider.strategies['custom'];
139152
pushPipeTestComponent.strategy = 'custom';
140153
cdSpy = jest.spyOn(strategy, 'work');
141-
})
154+
});
142155

143156
it('should not detect changes with sync value', () => {
144157
fixturePushPipeTestComponent.detectChanges();
@@ -147,36 +160,40 @@ describe('PushPipe used as pipe in the template', () => {
147160
});
148161

149162
it('should detect changes with async value', async () => {
150-
const value$ = new Observable(sub => {
163+
const value$ = new Observable((sub) => {
151164
Promise.resolve().then(() => {
152165
sub.next(44);
153166
sub.complete();
154167
});
155168
return () => {
156169
sub.complete();
157-
}
170+
};
158171
});
159172
pushPipeTestComponent.value$ = value$;
160173
fixturePushPipeTestComponent.detectChanges();
161-
expect(componentNativeElement.textContent).toBe(wrapWithSpace('undefined'));
174+
expect(componentNativeElement.textContent).toBe(
175+
wrapWithSpace('undefined')
176+
);
162177
await Promise.resolve();
163178
expect(cdSpy).toBeCalledTimes(1);
164179
expect(componentNativeElement.textContent).toBe(wrapWithSpace('44'));
165180
});
166181

167182
it('should detect changes with unpatched Promise', async () => {
168-
const value$ = new Observable(sub => {
183+
const value$ = new Observable((sub) => {
169184
unpatchedPromise.resolve().then(() => {
170185
sub.next(44);
171186
sub.complete();
172187
});
173188
return () => {
174189
sub.complete();
175-
}
190+
};
176191
});
177192
pushPipeTestComponent.value$ = value$;
178193
fixturePushPipeTestComponent.detectChanges();
179-
expect(componentNativeElement.textContent).toBe(wrapWithSpace('undefined'));
194+
expect(componentNativeElement.textContent).toBe(
195+
wrapWithSpace('undefined')
196+
);
180197
await unpatchedPromise.resolve();
181198
expect(cdSpy).toBeCalledTimes(1);
182199
expect(componentNativeElement.textContent).toBe(wrapWithSpace('44'));
@@ -186,7 +203,9 @@ describe('PushPipe used as pipe in the template', () => {
186203
const value$ = timer(0, asapScheduler).pipe(map(() => 44));
187204
pushPipeTestComponent.value$ = value$;
188205
fixturePushPipeTestComponent.detectChanges();
189-
expect(componentNativeElement.textContent).toBe(wrapWithSpace('undefined'));
206+
expect(componentNativeElement.textContent).toBe(
207+
wrapWithSpace('undefined')
208+
);
190209
await Promise.resolve();
191210
expect(cdSpy).toBeCalledTimes(1);
192211
expect(componentNativeElement.textContent).toBe(wrapWithSpace('44'));
@@ -196,13 +215,14 @@ describe('PushPipe used as pipe in the template', () => {
196215
const value$ = timer(0).pipe(map(() => 44));
197216
pushPipeTestComponent.value$ = value$;
198217
fixturePushPipeTestComponent.detectChanges();
199-
expect(componentNativeElement.textContent).toBe(wrapWithSpace('undefined'));
200-
await new Promise(resolve => {
218+
expect(componentNativeElement.textContent).toBe(
219+
wrapWithSpace('undefined')
220+
);
221+
await new Promise((resolve) => {
201222
setTimeout(resolve);
202-
})
223+
});
203224
expect(cdSpy).toBeCalledTimes(1);
204225
expect(componentNativeElement.textContent).toBe(wrapWithSpace('44'));
205226
});
206-
207-
})
227+
});
208228
});

0 commit comments

Comments
 (0)