These are chat archives for pozadi/kefir

14th
Feb 2015
Petr Myazin
@pqr
Feb 14 2015 04:33
Yes, I meant many rows... sorry for my confused description
one row example looks simplier than I thought! (I expect somthing like "keyp" or "change" event stream on input fields; but asKefirProperty - really nice!
and what if there are many (N) rows? Create many of .asKefirProperty and .combine for each row?
Roman Pominov
@rpominov
Feb 14 2015 10:38
@pqr yep, in case of many rows you can create multiple .asKefirProperty and .combine for each row (can be done in a loop)
also notice that 'input' argument in .asKefirProperty is just an event name, there could be 'change keyup' as well
Petr Myazin
@pqr
Feb 14 2015 11:12
@pozadi what I think: create multiple .asKefirProperty with 'change keyup' event llisteners on each input element could be a potential performance problem. I would like to create one event listener on root element and utilize event bubbling. I made an example, but I feel it looks ugly. Could you give an advice how to make it more idiomatic reactive or more "kefirish"? http://jsfiddle.net/oo1626g1/2/
Roman Pominov
@rpominov
Feb 14 2015 12:39
there was two common mistakes in your version:
1) if you find yourself doing emitter.emit() inside onValue you're probably doing something wrong. You should try to properly define observables dependency tree using .map for example
2) you should try to separate calculations and side effects (see how in my example side effects done only at the end, and there is no calculations in .onValue)
Roman Pominov
@rpominov
Feb 14 2015 12:45
ah, and third: you should try to never ever store state in variables outside of observables — this ruins all FRP idea
Petr Myazin
@pqr
Feb 14 2015 13:10
thank you for explanation and corrections in my example, verry valuable!
Petr Myazin
@pqr
Feb 14 2015 13:55
@pozadi I am playing with things, could you have a look on http://jsfiddle.net/oo1626g1/5/ - I want do not re-render total span if total actually not changed (e.g. keyup withing price or quantity event fired from arrow keys, not real number typing). What I do: add total.diff(...) to compare prevTotal and nextTotal - return null of equals and than total.filter(...) to filter null values
then I found .skipDuplicates!
Skips duplicate values using === for comparison
and what I am thinking now: I can use .skipDuplicates even for more complex data structures (in our example for curState property) without any comparator function if I use immutable data scructures, so === will be right comparator for my complex state
what do you think - am I digging in right direction?
Petr Myazin
@pqr
Feb 14 2015 14:26
what I have now: http://jsfiddle.net/oo1626g1/6/ - I put .skipDuplicates on currState and on ammounts properties, for me looks good. Do you see any conceptual mistakes here?
Roman Pominov
@rpominov
Feb 14 2015 15:08
@pqr yep, all looks good, nice optimizations. you can also think of using something like immutable.js for data manipulations
I believe immutable.js can automatically do what you're doing in .scan() handler, and === will work automatically
not sure though if it can preserve === when doing arr.map()