-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Implement EventStream.periodic #31
Comments
Until this is implemented, could you post an example of the "EventBus hack"? I finally decided to take the plunge and rewrite one of my projects with Laminar, but the first thing I need to do is trigger updates based on a clock tick. Basically-
|
Following the conversation on gitter, this seems to do the trick: import com.raquo.laminar.api.L._
import org.scalajs.dom
val diffBus = new EventBus[Int]
dom.window.setInterval(() => diffBus.writer.onNext(scala.util.Random.nextInt), 1000)
val x = div(
"Random number every second: ",
child.text <-- diffBus.events.map(_.toString)
)
render(dom.document.getElementById("output"), x) On ScalaFiddle: https://scalafiddle.io/sf/TbnkMEu/20 Seems like the simplest version of |
Alright, I implemented a proper |
Need a stream that emits values at an interval when it's active. it's possible to emulate with a DIY EventBus hack, but we should have a proper way to do this.
For API design, bare minimum is to emit Unit-s. But it might be quite cheap and useful to emit an index-like number instead. But then we need an option to reset the number on deactivation. Maybe make the counter a separate method.
Also, consider putting a limit on number of emitted values? But that will be more useful as a take() or until(), and well that's more of a #23 thing, so maybe another day.
The text was updated successfully, but these errors were encountered: