Skip to content

Commit e0f6038

Browse files
committed
feat(project): update 19
1 parent 3cea149 commit e0f6038

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

apps/testing/19-input-output/src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CounterComponent } from './counter.component';
55
imports: [CounterComponent],
66
selector: 'app-root',
77
template: `
8-
<app-counter [initialValue]="10" (send)="log($event)"></app-counter>
8+
<app-counter [initialValue]="10" (send)="log($event)" />
99
`,
1010
})
1111
export class AppComponent {
Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,32 @@
1-
import { AsyncPipe } from '@angular/common';
21
import {
32
ChangeDetectionStrategy,
43
Component,
5-
EventEmitter,
6-
Input,
7-
Output,
4+
input,
5+
linkedSignal,
6+
output,
87
} from '@angular/core';
9-
import { LetDirective } from '@ngrx/component';
10-
import { ComponentStore } from '@ngrx/component-store';
118

129
@Component({
1310
selector: 'app-counter',
14-
imports: [AsyncPipe, LetDirective],
1511
template: `
16-
<ng-container *ngrxLet="counter$ as counter">
17-
<p data-testid="counter">Counter: {{ counter }}</p>
18-
<button (click)="increment()">Increment</button>
19-
<button (click)="decrement()">Decrement</button>
20-
<button (click)="send.emit(counter)">Send</button>
21-
</ng-container>
12+
<p data-testid="counter">Counter: {{ counter() }}</p>
13+
<button (click)="increment()">Increment</button>
14+
<button (click)="decrement()">Decrement</button>
15+
<button (click)="send.emit(counter())">Send</button>
2216
`,
2317
changeDetection: ChangeDetectionStrategy.OnPush,
2418
})
25-
export class CounterComponent extends ComponentStore<{ counter: number }> {
26-
@Input() set initialValue(initialValue: number) {
27-
this.patchState({ counter: initialValue });
28-
}
19+
export class CounterComponent {
20+
initialValue = input.required<number>();
21+
public counter = linkedSignal(() => this.initialValue());
2922

30-
@Output() send = new EventEmitter<number>();
23+
send = output<number>();
3124

32-
readonly counter$ = this.select((state) => state.counter);
25+
public increment = () => {
26+
this.counter.set(this.counter() + 1);
27+
};
3328

34-
readonly increment = this.updater((state) => ({
35-
counter: state.counter + 1,
36-
}));
37-
readonly decrement = this.updater((state) => ({
38-
counter: state.counter - 1,
39-
}));
40-
41-
constructor() {
42-
super({ counter: 0 });
43-
}
29+
public decrement = () => {
30+
this.counter.set(this.counter() - 1);
31+
};
4432
}

0 commit comments

Comments
 (0)