Skip to content

Commit 1775485

Browse files
committed
Use outputFromObservable
1 parent 4841f88 commit 1775485

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

projects/todo-mvc/src/app/todo.component.ts

+24-23
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {
44
Component,
55
ElementRef,
66
Input,
7-
Output,
87
inject,
98
viewChild,
109
} from '@angular/core';
10+
import { outputFromObservable } from '@angular/core/rxjs-interop';
1111
import { RxStrategyProvider } from '@rx-angular/cdk/render-strategies';
1212
import { rxState } from '@rx-angular/state';
1313
import { eventValue, rxActions } from '@rx-angular/state/actions';
@@ -53,24 +53,24 @@ const eventChecked = (e: Event): boolean => {
5353
`,
5454
template: `
5555
@if (isEditing) {
56+
<input
57+
#input
58+
class="edit"
59+
[value]="todo.text"
60+
(blur)="actions.updateText($event)"
61+
(keyup.enter)="actions.updateText($event)"
62+
/>
63+
} @else {
64+
<div class="view">
5665
<input
57-
#input
58-
class="edit"
59-
[value]="todo.text"
60-
(blur)="actions.updateText($event)"
61-
(keyup.enter)="actions.updateText($event)"
66+
class="toggle"
67+
type="checkbox"
68+
[checked]="todo.done"
69+
(input)="actions.toggleDone($event)"
6270
/>
63-
} @else {
64-
<div class="view">
65-
<input
66-
class="toggle"
67-
type="checkbox"
68-
[checked]="todo.done"
69-
(input)="actions.toggleDone($event)"
70-
/>
71-
<label (dblclick)="actions.edit()">{{ todo.text }}</label>
72-
<button class="destroy" (click)="actions.remove(todo)"></button>
73-
</div>
71+
<label (dblclick)="actions.edit()">{{ todo.text }}</label>
72+
<button class="destroy" (click)="actions.remove(todo)"></button>
73+
</div>
7474
}
7575
`,
7676
})
@@ -85,6 +85,13 @@ export class TodoComponent {
8585
})
8686
);
8787

88+
readonly remove = outputFromObservable(this.actions.remove$);
89+
readonly update = outputFromObservable(
90+
merge(this.actions.toggleDone$, this.actions.updateText$).pipe(
91+
switchMap(() => this.state.select('todo').pipe(take(1)))
92+
)
93+
);
94+
8895
private readonly state = rxState<State>(({ set, connect }) => {
8996
set({ isEditing: false });
9097
connect('todo', this.actions.toggleDone$, ({ todo }, done: boolean) => ({
@@ -116,12 +123,6 @@ export class TodoComponent {
116123
return this.state.get('isEditing');
117124
}
118125

119-
@Output() remove = this.actions.remove$;
120-
@Output() update = merge(
121-
this.actions.toggleDone$,
122-
this.actions.updateText$
123-
).pipe(switchMap(() => this.state.select('todo').pipe(take(1))));
124-
125126
constructor() {
126127
rxEffects(({ register }) => {
127128
const focusInputWhenEditing$ = this.state.$.pipe(

0 commit comments

Comments
 (0)