These are chat archives for pozadi/kefir

31st
Mar 2015
Petr Myazin
@pqr
Mar 31 2015 13:14
Home work done! Implemented TodoMVC with React + Flux + Kefir + ES6 by myself: https://github.com/pqr/react-flux-kefir-es6-todomvc-example/
Sergey Lapin
@lapanoid
Mar 31 2015 13:15
great!
Petr Myazin
@pqr
Mar 31 2015 13:16
any suggestions will be appreciated
but it's still not a library I can reuse in any project, still have no clear understading on it
Sergey Lapin
@lapanoid
Mar 31 2015 13:17
I think that it is natural to use streams in frp and flux rather than events, but this is only my opinion)
Petr Myazin
@pqr
Mar 31 2015 13:17
my next home task is to implement Flux Chat example
@lapanoid "events" and "streams" are not clearly separated in my mind, could you give me more details what do you mean?
Sergey Lapin
@lapanoid
Mar 31 2015 13:24
@pqr Any organized sequence of events can be represented as stream and stream is actually more flexible for next usage, so I always prefer them. In my realization of frp-flux I decided that dispatcher is just a holder of "actionstreams"
Petr Myazin
@pqr
Mar 31 2015 13:34
Sergey Lapin
@lapanoid
Mar 31 2015 13:35
Yeah, but it is a little difference here, I just don't see any reason to keep events
This approach is from bacon repo, I just liked it and kept)
Sergey Lapin
@lapanoid
Mar 31 2015 13:41

And I didn't understand this construction

 Kefir
    .merge([
        createActionsStream,
        updateActionsStream,
        undoCompleteActionsStream,
        doCompleteActionsStream,
        togleCompleteAllActionsStream,
        destroyActionsStream,
        destroyCompletedActionsStream
    ])
    .scan((prevTodos, modificationFunc) => modificationFunc(prevTodos), {});

I think you can achieve what you what with simple combine and code will be cleaner

Petr Myazin
@pqr
Mar 31 2015 14:15
Could you show me combine approach for this? (when you have time ofcause)
Sergey Lapin
@lapanoid
Mar 31 2015 14:23
@pqr My bad I use this too in https://github.com/lapanoid/react-kefir-flux, but in production I simply use kefir emmiters and props
This message was deleted
module.exports = function(actions) {
    var boundsPropEmmiter, boundsPropProp, dateFilterModeEmmiter, dateFilterModeProp, dateFilteredPostsEmmiter, dateFilteredPostsProp, filterByModeFuncProp, postsEmmiter, postsProp, res, skippedFiltered;
    res = {};
    boundsPropEmmiter = Kefir.emitter();
    postsEmmiter = Kefir.emitter();
    dateFilteredPostsEmmiter = Kefir.emitter();

    dateFilterModeEmmiter = Kefir.emitter();
    boundsPropProp = boundsPropEmmiter.toProperty();
    dateFilteredPostsProp = dateFilteredPostsEmmiter.toProperty();
    dateFilterModeProp = dateFilterModeEmmiter.toProperty();
    filterByModeFuncProp = Kefir.combine([boundsPropProp, dateFilterModeProp], function(boundsProp, dateFilterMode) {
      return filterByDateModeAndMoments(boundsProp.firstMoment, boundsProp.lastMoment)(dateFilterMode);
    }).toProperty();
    postsProp = postsEmmiter.toProperty();
    dateFilteredPostsProp = Kefir.combine([postsProp, filterByModeFuncProp], function(posts, filterByModeFunc) {
      return filterByModeFunc(posts);
    }).toProperty();

    /*actions*/
    actions.postsToFilter.onValue(function(val) {
      return postsEmmiter.emit(val);
    });
    actions.boundsProp.onValue(function(val) {
      return boundsPropEmmiter.emit(val);
    });
    actions.dateFilterModeChanged.onValue(function(val) {
      return dateFilterModeEmmiter.emit(val);
    });
    /*end actions*/

    skippedFiltered = dateFilteredPostsProp.skipDuplicates(function(a, b) {
      return a.length === b.length;
    });
    res.getFilteredPosts = skippedFiltered;
    return res;
  };
Not the best code ever I know=)
Petr Myazin
@pqr
Mar 31 2015 14:50
I can read your code, but can't apply it on top of my code :)
Also I fill that call .emit() inside .onValue() is not FRP-way
Sergey Lapin
@lapanoid
Mar 31 2015 15:10
Sure it is =( But point is that if u don't need concentrate state in one object u don't need Kefir.merge.scan stuff. Concentration is good when your store serve some component and even in this case u can simply combine streams.
Sergey Lapin
@lapanoid
Mar 31 2015 15:29
@pqr Kefir.merge.scan stuff is just a bad translation of join patterns from bacon version that keeps going on( It was justified there and in my kefir version because they operate with immutable map and it could not be done via plain combine.
Sergey Lapin
@lapanoid
Mar 31 2015 15:56
Hah I am totally wrong you still need to pass previous state and it can be done with combine sorry if I confused you.