-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What else people call "behavior" in FRP :) #28
Comments
A behavior can't be explained as an event stream and a value in memory. A behavior is more powerful since it can change infinitely often. |
@paldepind Having the change events included in the behavior Running some sort of request animation frame and then checking for changes every time It is perhaps useful with animations, but with typical discrete states |
Hareactive uses a combination of push and pull. Behaviors that changes at discrete points in time (for instance if they're based on browser events) are push and behaviors that changes continuously are pulled. When you observe a behavior in Hareactive you'll be told if the behavior changes at discrete points in time or if it changes infinitely often. If the behavior changes infinitely often it is the observer's job to pull when it suits him. You can see how we do it in Turbine here. If the behavior is continuous we update on every frame and if it pushes values we update whenever that happens. |
This sounds like you are splitting behaviors into 2 different kinds - discrete changing to be pushed, and continuous to be pulled. Isn't the first effectively equivalent to having the separate memory stream type? :) It seems to me, using the memory stream for both streams and discrete behaviours Am I missing something? |
Correct. But, we are going this internally precisely so that users don't have to. Complexity is moved away from the API and into hidden implementation details.
Indeed. Expect that a behavior can switch between the two. So it might pull now but switch to pull a minute later.
Easier for who? 😄 A normal user doesn't have to call Part of being simple means that both behavior and stream has a simple and precise semantic meaning. It also means that implementation details are hidden. We have a clear distinction between behaviors and streams. Adding an extra type that provides no extra power only seems to make the API more complex and muddy the distinction between behaviors and streams. |
You mean from pull to push?
Then how can I reliably attach my custom renderer to a behavior? Like here I can take arbitrary renderer and subscribe to the event stream: But if the I must be looking confused now 😕 |
Yes 👍
I probably didn't make myself clear enough. As a library consumer, you have to worry about push vs pull. But only so that regular users don't have to. To do that one uses the But, let me warn you. If you have a behavior of vnode's and the behavior is pulling then you have to create a new vdom, diff it and patch it 60 times per seconds which may be problematic. That is one of the reasons why we don't use virtual dom in Turbine. |
Thank you for the explanation. Unfortunately, if I am to be honest, that makes the behavior in this form harder to use. A possible slightly different type separation based on the pull/push would seem easier to use. It might not require major changes, |
It makes it harder for people who needs to call
Such a separation would make it easier for library writers. Harder for normal users. It would expose implementation details and break the behavior abstraction. Normal should never call observe. What you suggest would make Hareactive harder to use and more complex for average users. |
That probably means I was trying to use it the wrong way :) |
Might be interesting to take into consideration:
http://stackoverflow.com/questions/1028250/what-is-functional-reactive-programming/1033066#1033066
Actually quite useful to describe e.g. the user's
inputValue
as you want both the value and to react to its changes.
The text was updated successfully, but these errors were encountered: