Skip to content

Commit

Permalink
Use outputFromObservable
Browse files Browse the repository at this point in the history
  • Loading branch information
edbzn committed Nov 27, 2024
1 parent 4841f88 commit 1775485
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions projects/todo-mvc/src/app/todo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
Component,
ElementRef,
Input,
Output,
inject,
viewChild,
} from '@angular/core';
import { outputFromObservable } from '@angular/core/rxjs-interop';
import { RxStrategyProvider } from '@rx-angular/cdk/render-strategies';
import { rxState } from '@rx-angular/state';
import { eventValue, rxActions } from '@rx-angular/state/actions';
Expand Down Expand Up @@ -53,24 +53,24 @@ const eventChecked = (e: Event): boolean => {
`,
template: `
@if (isEditing) {
<input
#input
class="edit"
[value]="todo.text"
(blur)="actions.updateText($event)"
(keyup.enter)="actions.updateText($event)"
/>
} @else {
<div class="view">
<input
#input
class="edit"
[value]="todo.text"
(blur)="actions.updateText($event)"
(keyup.enter)="actions.updateText($event)"
class="toggle"
type="checkbox"
[checked]="todo.done"
(input)="actions.toggleDone($event)"
/>
} @else {
<div class="view">
<input
class="toggle"
type="checkbox"
[checked]="todo.done"
(input)="actions.toggleDone($event)"
/>
<label (dblclick)="actions.edit()">{{ todo.text }}</label>
<button class="destroy" (click)="actions.remove(todo)"></button>
</div>
<label (dblclick)="actions.edit()">{{ todo.text }}</label>

Check failure on line 71 in projects/todo-mvc/src/app/todo.component.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (18.x)

A label component must be associated with a form element
<button class="destroy" (click)="actions.remove(todo)"></button>

Check failure on line 72 in projects/todo-mvc/src/app/todo.component.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (18.x)

<button> should have content
</div>
}
`,
})
Expand All @@ -85,6 +85,13 @@ export class TodoComponent {
})
);

readonly remove = outputFromObservable(this.actions.remove$);
readonly update = outputFromObservable(
merge(this.actions.toggleDone$, this.actions.updateText$).pipe(
switchMap(() => this.state.select('todo').pipe(take(1)))
)
);

private readonly state = rxState<State>(({ set, connect }) => {
set({ isEditing: false });
connect('todo', this.actions.toggleDone$, ({ todo }, done: boolean) => ({
Expand Down Expand Up @@ -116,12 +123,6 @@ export class TodoComponent {
return this.state.get('isEditing');
}

@Output() remove = this.actions.remove$;
@Output() update = merge(
this.actions.toggleDone$,
this.actions.updateText$
).pipe(switchMap(() => this.state.select('todo').pipe(take(1))));

constructor() {
rxEffects(({ register }) => {
const focusInputWhenEditing$ = this.state.$.pipe(
Expand Down

0 comments on commit 1775485

Please sign in to comment.