noob question: Which could be the best approach?..and clarification about properties

46 views
Skip to first unread message

carlos

unread,
Aug 9, 2014, 9:05:43 PM8/9/14
to bac...@googlegroups.com
Hi!!..I'm newbie with baconjs..so probably you will find me here frecuently asking question :D ...I've a few questions

1) My first impression about properties was then they are similar to reactive variables...something like this concept


so..for instance...if I have
var trueOrFalseProperty = ....

var streamOfNumbers = .....

if I only wish sum the values of streamOfNumbers when trueOrFalseProperty is true then I could do something lik

streamOfNumbers.scan(0,function(mem,_){
  return (trueOrFalseProperty==true ? mem+1 : mem)

})

but wait, trueOrFalseProperty is not the value, instead is a container (is a stream too?)  with the bool value inside..then my approach was something like this

var counter = update.scan(0,function (mem, _) {
      trueOrFalsePropert.flatMap(function (_bool) { //I try map too
            console.dir(_bool);  //this never run
            return (_bool == "true" ? : mem+1 : mem)
      })
}).log();

this doesn't works, even doesn't run...

2) I wish know what could be the best approach for archieve this sample..where I don't need listen the change in a property but I need access to it in a future, based in other stream...

thanks and sorry for the noob question or any mistake in my code, I can't access to the original code than I wrote and I did this following as I remembered  it...

thanks again :D.....

carlos

unread,
Aug 9, 2014, 10:08:53 PM8/9/14
to bac...@googlegroups.com



I got it!!..I use sampledBy, then I group both values in the same stream and I can scan over this

 
var boolAndValue = trueOrFalseProperty.sampledBy(update, function (s, v) {
      return [s, v]
});

boolAndValue.scan(.... update value if boolAndValue is [true,_])

I think looks nice, but I wish know if exist other approach 

--------------------------------------------------------------------------------------------

I still wish know why my first counter implementation fails...
Reply all
Reply to author
Forward
0 new messages