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

Skip to content

Commit 3771fa8

Browse files
committed
test: use rxState for SSR specs
1 parent 08f4566 commit 3771fa8

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

apps/ssr-e2e/src/e2e/app.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe('@rx-angular/template universal rendering', () => {
1+
describe('RxAngular SSR', () => {
22
describe('PushPipe', () => {
33
it('should display green text', () => {
44
cy.request('http://localhost:4200')
@@ -10,7 +10,7 @@ describe('@rx-angular/template universal rendering', () => {
1010
});
1111
});
1212

13-
describe('LetDirective', () => {
13+
describe('RxLet', () => {
1414
it('should display green text', () => {
1515
cy.request('http://localhost:4200')
1616
.its('body')

apps/ssr/src/app/app.component.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
import { isPlatformServer } from '@angular/common';
22
import { Component, Inject, NgZone, OnInit, PLATFORM_ID } from '@angular/core';
3-
import { BehaviorSubject } from 'rxjs';
3+
import { rxState } from '@rx-angular/state';
4+
import { of } from 'rxjs';
45

56
@Component({
67
selector: 'rx-angular-root',
78
template: `
8-
<div id="let" *rxLet="color$ as color; strategy">{{ color }}</div>
9+
<div id="let" *rxLet="color$; let color">{{ color }}</div>
910
<div id="push">{{ color$ | push }}</div>
1011
<div id="unpatch" [unpatch]="['click']" (click)="onClick()"></div>
1112
<div class="for" *rxFor="let color of colors$">{{ color }}</div>
1213
`,
1314
})
1415
export class AppComponent implements OnInit {
15-
color$ = new BehaviorSubject('red');
16-
colors$ = new BehaviorSubject(['red']);
16+
private readonly state = rxState<{ color: string; colors: string[] }>(
17+
({ set, connect }) => {
18+
set('color', () => 'red');
19+
connect('colors', of(['red']));
20+
}
21+
);
22+
23+
readonly color$ = this.state.select('color');
24+
readonly colors$ = this.state.select('colors');
1725

1826
constructor(@Inject(PLATFORM_ID) private platformId: string) {}
1927

2028
ngOnInit() {
2129
if (isPlatformServer(this.platformId)) {
22-
this.color$.next('green');
23-
this.colors$.next(['green', 'purple']);
30+
this.state.set('color', () => 'green');
31+
this.state.set('colors', () => ['green', 'purple']);
2432
}
2533
}
2634

0 commit comments

Comments
 (0)