baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript

Home Page:https://baconjs.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docs don't make clear the conceptual difference between Property & EventStream

Sequoia opened this issue · comments

I read the docs here, which is two short sentences describing what a property is

Bacon.Property a reactive property. Has the concept of "current value".

before jumping into how Properties are created & what methods they have. What's a "reactive property"?

I also looked at the tutorial and the FAQ & I'm still confused about what differentiates a property from an EventStream. You can subscribe to an EventStream... why would you create a property of it react to that? Why not just subscribe to the stream? I'm sure there's a good answer here I just don't get it. 😸

Request

Add a FAQ question "What's the difference between Property and EventStream (and when do I use one or the other)?"

A property is like a stream that gives you the latest value from that stream when you subscribe to it. Rx's BehaviourSubject is similar.

Some times you want a notion of events as "things that happen", for instance a button was clicked.

Some times you want a notion of events as "a changing value", for instance the current mouse position.

If you get and "extra" event when you subscribe to a stream of mouse clicks, you're probably happy, because you get to know where the mouse position was last time you got a mouse move event, and you don't have to wait until another mouse move occurs.

If you get an "extra" event from a stream of mouse clicks, you're probably unhappy, because it'll make you think the used clicked something when she didn't.

The distinction EventStream/Property exists to model these different intentions.

Thanks, that about clears it up for me! It would be great if that explanation were in somewhere in the docs, maybe the intro to the "properties" section?

"A property is stream you treat as a value & will always have a value, if you read it you'll get the latest published value (and they must be initiated with a value). A property's value may change but it exists thru time, fixed to it's last set value. An EventStream represents an ephemeral stream of events & the events "go away" once they are processed. A click stream, for example, does not have a fixed value representing the last click-- it emits that click event once & if a listener attaches later later, it will not have access to that event."

Anyway thanks for clearing it up.