cujojs / most

Ultra-high performance reactive programming
MIT License
3.49k stars 231 forks source link

Properties #171

Closed iofjuupasli closed 8 years ago

iofjuupasli commented 8 years ago

http://rpominov.github.io/kefir/#about-observables https://baconjs.github.io/api.html#property https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/subjects/behaviorsubject.md

Is there Properties in most.js?

briancavalier commented 8 years ago

Hi @iofjuupasli! Most.js's goal is efficient discrete events. It doesn't have a notion of a continuously-valued component, like Properties / Behaviors / Signals. The two concepts are complimentary, so I can imagine another package that provides a continuous component.

iofjuupasli commented 8 years ago

Can you please give a hint how to do it?

function toProperty(stream){
    var lastValue;
    return function(){
        return stream
            .tap(function (v) {
                lastValue = v;
            })
            .startWith(lastValue);
    };
}

then

var origStream = most.periodic(100, true);
var prop = toProperty(origStream);
prop().map()...
prop().map()...

What do you think, is it good way to do it?

briancavalier commented 8 years ago

@iofjuupasli Yeah, there are various ways to simulate properties. Something like your example looks like it'll work in many cases. Properties often have other features, though, like truly atomic updates of the dependency graph, and properties are usually continuous (at least conceptually), while events are discrete. So just be aware that there are differences.

Also, have a look at @TylorS's most-subject, as well as @most/hold. They may be helpful for you. Cheers!

TylorS commented 8 years ago

@iofjuupasli You could take a look at flyd which has atomic updates, although from my understanding it's not continuous.

mkaemmerer commented 8 years ago

My understanding of Bacon and Kefir properties is that they are not continuous either. They are discrete, and retain their most recent value – analogous to @most/hold. If you don't need atomic updates, that's probably the easiest approach.

I do wish that the FRP landscape had a more agreed upon lexicon. It would make discussions like this one way easier.

briancavalier commented 8 years ago

I do wish that the FRP landscape had a more agreed upon lexicon

Me too.

I'd go so far as to say that none of the currently popular reactive libraries is actually FRP. That's not an insult. For the record, most.js isn't FRP and doesn't intend to be. Rather, I just feel like these libs take an imperative approach, and/or don't deal with continuous time very well (or at all), which are two important characteristics of FRP.

For the FRP lexicon, I think it's important to look to Conal Elliott and Paul Hudak for authoritative terminology, which means Event and Behavior as the two main types. I don't know the history of the name "Property", but I'd be interested to find out. The name "Signal" (another continuous time-varying value) came from, as far as I know, signal processing.

Closing this as @most/hold (plus startWith if you need an initial value) is reasonable approximation, and most-subject is good for other imperative cases.