Skip to content

Commit

Permalink
docs: Fix usage of effect in examples (#29305)
Browse files Browse the repository at this point in the history
Ensure that `effect` code that emits on public rxjs streams is run as
untracked.
  • Loading branch information
mmalerba authored Jun 24, 2024
1 parent 5da528e commit c185c53
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
input,
model,
signal,
untracked,
viewChild,
} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
Expand Down Expand Up @@ -175,19 +176,20 @@ export class MyTelInput implements ControlValueAccessor, MatFormFieldControl<MyT
this._required();
this._disabled();
// Propagate state changes.
this.stateChanges.next();
untracked(() => this.stateChanges.next());
});

effect(() => {
if (this._disabled()) {
this.parts.disable();
untracked(() => this.parts.disable());
} else {
this.parts.enable();
untracked(() => this.parts.enable());
}
});

effect(() => {
this.parts.setValue(this._value() || new MyTel('', '', ''));
const value = this._value() || new MyTel('', '', '');
untracked(() => this.parts.setValue(value));
});

this.parts.statusChanges.pipe(takeUntilDestroyed()).subscribe(() => {
Expand Down

0 comments on commit c185c53

Please sign in to comment.