-1

I want to debounce on all key presses excluding return. I have tried the following but it doesn't debounce.

some_stream.flatMap((event) => {
                            if(event.keyCode == 13){
                                return Kefir.stream(emitter => {
                                    emitter.emit(event.target.value);
                                });
                            }else{
                                const debounced_stream = Kefir.stream(emitter => {
                                    emitter.emit(event.target.value);
                                }).debounce(1000)
                                return debounced_stream;
                            }

                        })
user3743222
  • 18,345
  • 5
  • 69
  • 75
Tim.Willis
  • 307
  • 2
  • 10

1 Answers1

0

I was able to solve this with the code block below which debounces on every keyCode except 13:

const search_stream = Kefir.fromEvents(self.search_keyword._tag.input, 'keyup');
                const debounced_search_stream = search_stream
                        .filter((event) => {
                            return event.keyCode != 13;
                        })
                        .map((event) => {
                            return event.target.value;
                        })
                        .debounce(1000);
                const not_debounced_search_stream = search_stream
                        .filter((event) => {
                            return event.keyCode == 13;
                        })
                        .map((event) => {
                            return event.target.value;
                        })
                Kefir.merge([debounced_search_stream, not_debounced_search_stream]).onValue(keyword => {
                    if(keyword !== null){
                        if (keyword) {
                            //do something
                        }
                    }
                })
Tim.Willis
  • 307
  • 2
  • 10