I'm learning to use the fantastic Bacon.js library for functional reactive programming. Adding handlers to a property or stream is easy:
handler = function(value){... do something ...}
property.onValue(handler)
Say somewhere down the line I want to cancel this subscription, like this (pseudocode):
property.unsubscribe(handler)
Is there a way to do this with Bacon.js?
Both answers above are correct. Personally, I've never used either solution though. In fact, they mainly exist for internal purposes and for writing custom combinators and integrations.
So instead I recommend combinators like take, takeWhile and takeUntil. In an FRP application, the signal that triggers the need can usually be modeled as an EventStream. In that case you can do
var data, stopper // EventStreams
data.takeUntil(stopper).onValue( .. )
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