@@ -4,10 +4,10 @@ import {
4
4
Component ,
5
5
ElementRef ,
6
6
Input ,
7
- Output ,
8
7
inject ,
9
8
viewChild ,
10
9
} from '@angular/core' ;
10
+ import { outputFromObservable } from '@angular/core/rxjs-interop' ;
11
11
import { RxStrategyProvider } from '@rx-angular/cdk/render-strategies' ;
12
12
import { rxState } from '@rx-angular/state' ;
13
13
import { eventValue , rxActions } from '@rx-angular/state/actions' ;
@@ -53,24 +53,24 @@ const eventChecked = (e: Event): boolean => {
53
53
` ,
54
54
template : `
55
55
@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">
56
65
<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)"
62
70
/>
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>
74
74
}
75
75
` ,
76
76
} )
@@ -85,6 +85,13 @@ export class TodoComponent {
85
85
} )
86
86
) ;
87
87
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
+
88
95
private readonly state = rxState < State > ( ( { set, connect } ) => {
89
96
set ( { isEditing : false } ) ;
90
97
connect ( 'todo' , this . actions . toggleDone$ , ( { todo } , done : boolean ) => ( {
@@ -116,12 +123,6 @@ export class TodoComponent {
116
123
return this . state . get ( 'isEditing' ) ;
117
124
}
118
125
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
-
125
126
constructor ( ) {
126
127
rxEffects ( ( { register } ) => {
127
128
const focusInputWhenEditing$ = this . state . $ . pipe (
0 commit comments