Skip to content

Instantly share code, notes, and snippets.

View oyvindberg's full-sized avatar

Øyvind Raddum Berg oyvindberg

View GitHub Profile
class WrapBackendScope[P, S](b: BackendScope[P, S]){
def props = CallbackTo[P](b.props)
def state = CallbackTo[S](b.state)
def both = CallbackTo[(P, S)]((b.props, b.state))
def modState(f: S => S, cb: Callback = Callback.empty): Callback =
state >>= (s => b.setState(f(s), cb))
def modStateCB(f: S => CallbackTo[S], cb: Callback = Callback.empty): Callback =
state >>= (s => b.setStateCB(f(s), cb))
import japgolly.scalajs.react.BackendScope
import japgolly.scalajs.react.extra._
import scalaz.syntax.id._
final case class CachingBackendScope[P: Reusability, S: Reusability]
(b: BackendScope[P, S]){ outer ⇒
type PropVal[O] = ReactVal[P, O]
type StateVal[O] = ReactVal[(P, S), O]