简体   繁体   中英

Bacon.js how to filter an event stream based on another property?

I have an event stream for when ENTER is presssed

var enter = 
  $('#text')
  .asEventStream('keydown')
  .filter(function(e){
    return e.keyCode === 13
  })

This works great. But, I want to only take action if ENTER is pressed and another property - textMatches - is true. How do I do this? I tried

var advance = textMatches.and(enter)

But it didn't work.

Boolean methods are defined for operations between two Properties, but enter is an EventStream. Properties can be used to filter EventStreams and the following should work for your use case:

var advance = enter.filter(textMatches)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM