当前位置: 首页>>代码示例>>Scala>>正文


Scala Callback类代码示例

本文整理汇总了Scala中japgolly.scalajs.react.Callback的典型用法代码示例。如果您正苦于以下问题:Scala Callback类的具体用法?Scala Callback怎么用?Scala Callback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Callback类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: SortableListItem

//设置package包名称以及导入依赖的类
package org.rebeam.tree.view.list

import japgolly.scalajs.react.vdom.prefix_<^._
import japgolly.scalajs.react.{Callback, ReactComponentB, ReactElement}

object SortableListItem {

  case class Props(leftIcon: ReactElement, content: ReactElement, onClick: Callback, onClickContents: Callback)

  val component = ReactComponentB[Props]("SortableListItem")
    .render_P(p => {

      <.div(
        ^.onClick --> p.onClick,
        ^.cursor := "pointer",
        ^.className := "react-sortable-item",
        ^.display := "flex",
        <.div(
          ^.flex := "0 0 56px",
          p.leftIcon
        ),
        <.div(
          ^.onClick --> p.onClickContents,
          ^.flex := "1 1 auto",
          p.content
        ),
        <.div(
          ^.flex := "0 0 56px",
          SortableView.handle
        )
      )

    })
    .build

  def apply(leftIcon: ReactElement, content: ReactElement, onClick: Callback = Callback.empty, onClickContents: Callback = Callback.empty) =
    component(Props(leftIcon, content, onClick, onClickContents))

  def twoLines(line1: String, line2: String) =
    <.div(
      <.span(line1),
      <.br,
      <.span(
        ^.color := "rgba(0, 0, 0, 0.541176)",
        line2
      )
    )
} 
开发者ID:trepidacious,项目名称:tree-material-ui,代码行数:49,代码来源:SortableListItem.scala

示例2: ListItemIconButton

//设置package包名称以及导入依赖的类
package org.rebeam.tree.view.list

import chandu0101.scalajs.react.components.materialui.{Mui, MuiIconButton}
import japgolly.scalajs.react.vdom.prefix_<^._
import japgolly.scalajs.react.{Callback, ReactComponentB, ReactElement}
import org.rebeam.tree.view.{RCP, View}

import scala.scalajs.js

object ListItemIconButton {

  case class Props(icon: ReactElement, onClick: Callback)

  private val component = ReactComponentB[Props]("ListItemIconButton")
    .render_P(p =>
      <.div(
        ^.margin := "4px 4px",
        MuiIconButton(
          onTouchTap = View.touch(p.onClick),
          touchRippleColor = Mui.Styles.colors.white,
          touchRippleOpacity = 0.5,
          iconStyle = js.Dynamic.literal("color" -> "#FFF")
        )(p.icon)
      )
    ).build

  def apply(icon: ReactElement, onClick: Callback): RCP[Props] = component(Props(icon, onClick))
} 
开发者ID:trepidacious,项目名称:tree-material-ui,代码行数:29,代码来源:ListItemIconButton.scala

示例3: onNewGameButtonClicked

//设置package包名称以及导入依赖的类
package checkers.core

import japgolly.scalajs.react.Callback

trait ApplicationCallbacks {
  def onNewGameButtonClicked: Callback
  def onRotateBoardButtonClicked: Callback
  def onRushButtonClicked: Callback
  def onHintButtonClicked: Callback
}

object EmptyApplicationCallbacks extends ApplicationCallbacks {
  val onNewGameButtonClicked: Callback = Callback.empty
  val onRotateBoardButtonClicked: Callback = Callback.empty
  val onRushButtonClicked: Callback = Callback.empty
  val onHintButtonClicked: Callback = Callback.empty
} 
开发者ID:kschuetz,项目名称:checkers,代码行数:18,代码来源:ApplicationCallbacks.scala

示例4: JsonProperties

//设置package包名称以及导入依赖的类
package tms.component

import japgolly.scalajs.react
import japgolly.scalajs.react.Callback
import japgolly.scalajs.react.component.Scala.BackendScope
import japgolly.scalajs.react.vdom.VdomElement
import japgolly.scalajs.react.vdom.html_<^._
import tms.model.{LocalizableJson, LocalizableObject}


case class JsonProperties(
    json: LocalizableJson,
    langs: List[String],
    onDelete: (LocalizableJson) => Callback,
    onUpdate: (LocalizableJson, LocalizableJson) => Callback,
    onAdd: (LocalizableJson, String, LocalizableJson) => Callback
) {

  def updateJson(j: LocalizableJson): JsonProperties = this.copy(json = j)
}

class JsonBackend(bs: BackendScope[JsonProperties, Unit]) {

  def render(prop: JsonProperties): VdomElement = {

    prop.json match {

      case LocalizableObject(v, _) =>
        <.div(^.className := "object-div")(
          v.filter { // (key, json)
              case _ => true
            }
            .toVdomArray {
              case (key, json) =>
                JsonWithKeyComponent(
                  JsonWithKeyProperty(key, prop.updateJson(json)))
            }
        )

      case _ =>
        JsonWithKeyComponent(
          JsonWithKeyProperty("[root]", prop)
        )

    }
  }
}

object JsonComponent {

  private val Comp = react.ScalaComponent
    .build[JsonProperties]("json")
    .renderBackend[JsonBackend]
    .build

  def apply(prop: JsonProperties) = Comp(prop)

} 
开发者ID:markotron,项目名称:localizable-json-editor,代码行数:59,代码来源:JsonComponent.scala

示例5: Tell

//设置package包名称以及导入依赖的类
package spatutorial.client.modules

import diode.data.Pot
import diode.react.ModelProxy
import japgolly.scalajs.react.{BackendScope, Callback, ReactComponentB}
import spatutorial.client.components.Bootstrap.Panel
import spatutorial.shared.TellItem
import japgolly.scalajs.react.vdom.prefix_<^._
import spatutorial.client.components.GlobalStyles

import scalacss.ScalaCssReact._


object Tell {

  @inline private def bss = GlobalStyles.bootstrapStyles

  case class Props(proxy: ModelProxy[Pot[TellItem]])

  case class State(selectedItem: Option[TellItem] = None)

  class Backend(t: BackendScope[Props, State]) {
    def sayIt(): Callback = {
      println("it")
      t.modState(s => s.copy(selectedItem = Some(TellItem("It!!"))))
      t.
    }

    def render(p: Props, s: State) =
      Panel(Panel.Props("What do you want to say?"),
        <.div(bss.formGroup,
          <.label(^.`for` := "tellText", "I want to tell you:"),
          <.input(^.id := "tellText", ^.name := "tellText"),
          <.button(^.onClick --> sayIt, "Say it!")
        )
      )
  }

  val component = ReactComponentB[Props]("Tell")
    .initialState(State())
    .renderBackend[Backend]
    .build

  def apply(proxy: ModelProxy[Pot[TellItem]]) = component(Props(proxy))
} 
开发者ID:adrijardi,项目名称:playing-scalajs,代码行数:46,代码来源:Tell.scala

示例6: FlowView

//设置package包名称以及导入依赖的类
package net.devkat.pegasus.view

import diode.react.ModelProxy
import japgolly.scalajs.react.vdom.prefix_<^._
import japgolly.scalajs.react.{Callback, _}
import net.devkat.pegasus.actions.{ClearSelection, InsertCharacter}
import net.devkat.pegasus.model.{Flow, Selection}

object FlowView {

  case class Props(flowProxy: ModelProxy[Flow], selectionProxy: ModelProxy[Option[Selection]])

  private val component = ReactComponentB[Props]("FlowView")
    .renderP { (_, props) =>
      val flowProxy = props.flowProxy
      val flow = flowProxy()
      val selectionOption = props.selectionProxy()

      def onKeyPress(e: ReactKeyboardEvent) = {
        e.preventDefault()
        selectionOption.map(sel =>
          flowProxy.dispatch(InsertCharacter(sel, e.charCode.toChar))
        ).getOrElse(Callback.empty)
      }

      def onClick(e: ReactMouseEvent) =
        flowProxy.dispatch(ClearSelection)

      <.div(
        ^.`class` := "pegasus",
        ^.tabIndex := 0,
        ^.onKeyPress ==> onKeyPress,
        //^.onKeyDown ==> { (e: ReactKeyboardEvent) => Callback(e.preventDefault()) },
        ^.onKeyUp ==> { (e: ReactKeyboardEvent) => Callback(e.preventDefault()) },
        ^.onClick ==> onClick,
        flow.children.zipWithIndex map { case (section, index) =>
          SectionView(
            index,
            props.flowProxy.zoom(_.children(index)),
            props.selectionProxy)
        }
      )
    }.
    build

  def apply(flowProxy: ModelProxy[Flow], selectionProxy: ModelProxy[Option[Selection]]) =
    component(Props(flowProxy, selectionProxy))
} 
开发者ID:devkat,项目名称:pegasus,代码行数:49,代码来源:FlowView.scala

示例7: FeedsPage

//设置package包名称以及导入依赖的类
package me.mmcoulombe.aad.pages

import diode.data.Pot
import diode.react.ModelProxy
import diode.react.ReactPot._
import japgolly.scalajs.react.{Callback, ScalaComponent}
import japgolly.scalajs.react.component.Scala.{BackendScope, Unmounted}
import japgolly.scalajs.react.vdom.html_<^._
import me.mmcoulombe.aad.FetchFeeds
import me.mmcoulombe.aad.components.FeedsView
import me.mmcoulombe.add.models.RSSFeed


object FeedsPage {
  case class Props(proxy: ModelProxy[Pot[Map[Long, RSSFeed]]])
  class Backend($: BackendScope[Props, Unit]) {
    def mounted(props: Props): Callback = {
      props.proxy.dispatchCB(FetchFeeds())
    }

    def render(props: Props): VdomElement = {
      <.div(
        props.proxy().renderReady(feeds =>
          FeedsView(feeds.values)
        )
      )
    }
  }

  private val component = ScalaComponent.builder[Props]("FeedsPage")
    .stateless
    .renderBackend[Backend]
    .componentDidMount($ => $.backend.mounted($.props))
    .build

  def apply(proxy: ModelProxy[Pot[Map[Long, RSSFeed]]]): Unmounted[Props, Unit, Backend] =
    component(Props(proxy))
} 
开发者ID:mmcoulombe,项目名称:poc-aad,代码行数:39,代码来源:FeedsPage.scala

示例8: CityModule

//设置package包名称以及导入依赖的类
package kidstravel.client.modules

import diode.data.Pot
import diode.react.ModelProxy
import diode.react.ReactPot._
import japgolly.scalajs.react.extra.router.RouterCtl
import japgolly.scalajs.react.vdom.prefix_<^._
import japgolly.scalajs.react.{BackendScope, Callback, ReactComponentB}
import kidstravel.client.KidsTravelMain.{Loc, NewPoiLoc}
import kidstravel.client.components.Bootstrap.Button
import kidstravel.client.services.GetCity
import kidstravel.shared.geo.City

object CityModule {

  case class Props(cityId: Long, router: RouterCtl[Loc], proxy: ModelProxy[Pot[City]])

  class Backend($: BackendScope[Props, Unit]) {
    def mounted(props: Props) =
      Callback.when(props.proxy().isEmpty)(props.proxy.dispatch(GetCity(props.cityId)))

    def render(props: Props) = {
      val pot = props.proxy()
      <.div(
        pot.renderPending(_ > 10, _ => <.p("Loading …")),
        pot.renderFailed(_ => <.p("Could not load city.")),
        pot.renderReady(city =>
          <.div(
            <.h1(city.name),
            <.div(
              props.router.link(NewPoiLoc)("New point of interest")(
                ^.`class` := "btn"
              )
            )
          )
        )
      )
    }
  }

  val component = ReactComponentB[Props]("City")
    .renderBackend[Backend]
    .componentDidMount(scope => scope.backend.mounted(scope.props))
    .build

  def apply(cityId: Long, router: RouterCtl[Loc], proxy: ModelProxy[Pot[City]]) =
    component(Props(cityId, router, proxy))
} 
开发者ID:devkat,项目名称:kidstravel,代码行数:49,代码来源:CityModule.scala

示例9: SvgProvider

//设置package包名称以及导入依赖的类
package scaffvis.client.components.common

import scaffvis.client.store.Store
import scaffvis.client.store.actions.MoleculesActions.LoadMoleculeSvg
import scaffvis.client.store.actions.ScaffoldsActions.LoadScaffoldSvg
import scaffvis.client.store.model.{Molecules, Scaffolds}
import diode.Action
import diode.data.Pot
import japgolly.scalajs.react.Callback

import scala.collection.mutable

class SvgProvider(source: Map[Int, Pot[String]], loadMissingAction: Seq[Int] => Action) {

  val missingSvgs = mutable.Set.empty[Int]

  def getSvg(id: Int): Option[String] = {
    val svg = source.get(id).flatMap(_.toOption)
    if(svg.isEmpty)
      missingSvgs += id
    svg
  }

  private def loadSelectedMissingSvgCallback(selector: mutable.Set[Int] => TraversableOnce[Int]) = {
    if(missingSvgs.isEmpty)
      Callback.empty
    else {
      val ids = selector(missingSvgs).toVector
      missingSvgs.clear()
      Store.dispatchCB(loadMissingAction(ids))
    }
  }

  
  def loadMissingSvgCallback(limit: Int): Callback = loadSelectedMissingSvgCallback(_.iterator.take(limit))

}

object SvgProvider {

  def apply(source: Molecules) =
    new SvgProvider(source.svg, loadMissingAction = LoadMoleculeSvg.apply)

  def apply(source: Scaffolds) =
    new SvgProvider(source.svg, loadMissingAction = LoadScaffoldSvg.apply)

} 
开发者ID:velkoborsky,项目名称:scaffvis,代码行数:48,代码来源:SvgProvider.scala


注:本文中的japgolly.scalajs.react.Callback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。