Reputation: 12649
I was wondering if it was possible to reset the distinctUntilChanged
part
so that it would reaccept a repeated value.
So my situation is, right now I'm using the function like this (shortened greatly as just an example).
Rx.Observable.fromEvent(textInput, 'keyup')
.pluck('target','value')
.filter( (text) => {
text = text.trim();
if (!text.length) // empty input field
{
this.setState({ list: [] });
}
return text.length > 0;
})
.debounceTime(300)
.distinctUntilChanged()
So at the very end of this, the results create a series of divs which I can click on, which then changes the value of the input (calls function below).
fill_name(name)
{
$("#company_input").val(name);
this.setState({ list: [] });
}
So if I typed in a
in the input, then I delete it all with the backspace and retype a, the observable won't call my function.
I want some way for the fill_name
function to reset the distinctUntilChanged
part so I can search for a
again after clicking on my generated divs.
Upvotes: 3
Views: 2390
Reputation: 14687
Assuming you have an Observable of generatedDivClicks$:
const reset$ = generatedDivClicks$.mapTo('reset');
const input$ = Rx.Observable.fromEvent(textInput, 'keyup')
.pluck('target','value')
.filter( (text) => {
text = text.trim();
if (!text.length) // empty input field
{
this.setState({ list: [] });
}
return text.length > 0;
})
.debounceTime(300);
Rx.Observable.merge(reset$, input$)
.distinctUntilChanged()
.filter(x => x !== 'reset')
Upvotes: 2