-
-
Notifications
You must be signed in to change notification settings - Fork 232
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
Broadcast/Listen example #138
Comments
Would also be nice to see an example for the |
@i-am-the-slime Sure, will do. I did a quick search and realised there's a tiny little demo from the early days that hasn't been integrated with the online/live demos yet: If you were motivated to add this comment because you want to use it and you're not sure about how, my advice is to look at the signatures and just follow the types. If you can satisfy those types and scalac is happy then it will just work. As far as other examples, there's also this in the |
@i-am-the-slime Actually, both of the examples above use state monads. I'll give you an example of not using state monads, this is from a private project of mine (so I can't give you too much): final class ClientData(init: Project) extends Broadcaster[Changes] {
// This holds all global state in my app
// When it receives an update from the server, it does something like this:
def acceptDataFromServer(data): IO[Unit] = IO {
val changes: Changes = ...
broadcast(changes)
}
}
// Then I have some helper code for components to accept changes
class UpdateState[S](val f: Changes => S => S) extends AnyVal {
def install[P, B <: OnUnmount, N <: TopNode](cd: P => ClientData) =
Listenable.install[P, S, B, N, Changes](cd, $ => changes =>
$.modState(f(changes)))
}
class Refresh(val refresh: Changes => Boolean) extends AnyVal {
def install[P, S, B <: OnUnmount, N <: TopNode](cd: P => ClientData) =
Listenable.install[P, S, B, N, Changes](cd, $ => changes =>
if (refresh(changes))
$.forceUpdate())
} As you can see from the types, Hope that helps. |
Add to live demos.
Show that listener works for any type of external event, including ajax.
The text was updated successfully, but these errors were encountered: