For rxjs, can I provide an initial value when using distinctUntilChanged
? It seems that the equals check is skipped entirely when no previous value was received. I'd like to not emit anything when the first value it receives is the initial value.
Use case
In my case I'm working with angular, I'm working with reactive forms and subscribing to its value changes. Since it's an input field I have a typical pipe setup:
debounceTime(350)
distinctUntilChanged()
When the user changes the initial field from empty to something and then empty again within the debounce time, the event is triggered anyway which should not happen.
What I've tried
distinctUntilChanged
next
on the underlying subject with the default value
You can try startWith:
const valueChanges$ = this.form
.get('CONTROL_NAME')
.valueChanges
.pipe(
startWith('INITIAL_VALUE'),
distinctUntilChanged(),
skip(1)
)
.subscribe((value: string) => { ... });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With