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


Scala ReactConnector类代码示例

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


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

示例1: AppCircuit

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

import diode.ActionResult.{ModelUpdate, ModelUpdateSilent}
import diode._
import diode.data.{Empty, Ready}
import diode.react.ReactConnector
import upickle.default._

import scala.scalajs.js
import scala.scalajs.js.JSON
import scalafiddle.client.AppRouter.Home
import scalafiddle.shared._

object AppCircuit extends Circuit[AppModel] with ReactConnector[AppModel] {
  // load from global config
  def fiddleData = read[FiddleData](JSON.stringify(js.Dynamic.global.ScalaFiddleData))

  override protected def initialModel =
    AppModel(Home,
             None,
             fiddleData,
             ScalaFiddleHelp(ScalaFiddleConfig.helpURL),
             LoginData(Empty, Empty))

  override protected def actionHandler = composeHandlers(
    new FiddleHandler(zoomRW(_.fiddleData)((m, v) => m.copy(fiddleData = v)),
                      zoomRW(_.fiddleId)((m, v) => m.copy(fiddleId = v))),
    new CompilerHandler(zoomRW(_.outputData)((m, v) => m.copy(outputData = v))),
    new LoginHandler(zoomRW(_.loginData)((m, v) => m.copy(loginData = v))),
    navigationHandler
  )

  override def handleFatal(action: Any, e: Throwable): Unit = {
    println(s"Error handling action: $action")
    println(e.toString)
  }

  override def handleError(e: String): Unit = {
    println(s"Error in circuit: $e")
  }

  val navigationHandler: (AppModel, Any) => Option[ActionResult[AppModel]] = (model, action) =>
    action match {
      case NavigateTo(page) =>
        Some(ModelUpdate(model.copy(navLocation = page)))
      case NavigateSilentTo(page) =>
        Some(ModelUpdateSilent(model.copy(navLocation = page)))
      case _ =>
        None
  }
} 
开发者ID:scalafiddle,项目名称:scalafiddle-editor,代码行数:52,代码来源:AppCircuit.scala

示例2: ConcreteAppCircuit

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

import client.handlers.{AjaxHandlersComponent, CounterHandlerComponent}
import client.model._
import diode._
import diode.react.ReactConnector
import org.scalajs.dom

trait AppCircuitComponent {
  val appCircuit: AppCircuit

  trait AppCircuit extends Circuit[RootModel] with ReactConnector[RootModel]
}

trait ConcreteAppCircuitWired extends AppCircuitComponent {
  this: CounterHandlerComponent with AjaxHandlersComponent with InitialModelComponent =>

  override lazy val appCircuit       = new ConcreteAppCircuit
  private lazy val initialModelProxy = initialModel

  class ConcreteAppCircuit extends AppCircuit {

    val logActions = false

    class LoggingProcessor[M <: AnyRef] extends ActionProcessor[M] {
      def process(dispatch: Dispatcher, action: Any, next: Any => ActionResult[M], currentModel: M): ActionResult[M] = {
        dom.console.log(s"dispatching ${action.toString.take(80)}")
        next(action)
      }
    }

    if (logActions) {
      addProcessor(new LoggingProcessor[RootModel])
    }

    override def handleError(msg: String): Unit = {
      dom.console.error(s"handle error called with message $msg")
      super.handleError(msg)
    }

    override def handleFatal(action: Any, e: Throwable): Unit = {
      dom.console.error(
        s"handle fatal called with ${action.toString.take(80)} $e"
      )
      super.handleFatal(action, e)
    }

    override def actionHandler: HandlerFunction =
      foldHandlers(
        composeHandlers(
          counterHandlers.actionHandler,
          ajaxHandlers.actionHandler
        ),
        ajaxHandlers.eventHandler
      )

    override def initialModel: RootModel = initialModelProxy
  }

} 
开发者ID:igeolise,项目名称:single-page-app-skeleton,代码行数:61,代码来源:AppCircuitComponent.scala

示例3: RootModel

//设置package包名称以及导入依赖的类
package com.omis.client.services

import com.omis.User
import com.omis.client.RootModels.{EmployeeRootModel, EmployeesRootModel, UserRootModel}
import com.omis.client.handlers.{EmployeeHandler, EmployeesHandler, UserHandler}
import diode.Circuit
import diode.data.{Empty, Pot}
import diode.react.ReactConnector

case class RootModel(user: UserRootModel, emps: Pot[EmployeesRootModel], emp: Pot[EmployeeRootModel])

object OmisCircuit extends Circuit[RootModel] with ReactConnector[RootModel] {
  // initial application model
  override protected def initialModel = RootModel(
    UserRootModel(User(java.util.UUID.randomUUID(), "", "")), Pot.empty, Pot.empty
  )

  // combine all handlers into one
  override protected val actionHandler = composeHandlers(
    new UserHandler(zoomRW(_.user)((m, v) => m.copy(user = v))),
    new EmployeesHandler(zoomRW(_.emps)((m, v) => m.copy(emps = v))),
    new EmployeeHandler(zoomRW(_.emp)((m, v) => m.copy(emp = v)))
  )
} 
开发者ID:iriddhi,项目名称:mis,代码行数:25,代码来源:OmisCircuit.scala

示例4: SaavCircuit

//设置package包名称以及导入依赖的类
package ch.fhnw.ima.saav.circuit

import ch.fhnw.ima.saav.model.app._
import diode._
import diode.react.ReactConnector

class SaavCircuit extends Circuit[SaavModel] with ReactConnector[SaavModel] {

  override protected def initialModel = SaavModel()

  private val analysisImportHandler =
    new AnalysisImportHandler(zoomRW(AnalysisImportHandler.modelGet)(AnalysisImportHandler.modelSet))

  private val colorHandler =
    new ColorHandler(zoomRW(ColorHandler.modelGet)(ColorHandler.modelSet))

  private val entitySelectionHandler =
    new EntitySelectionHandler(zoomRW(EntitySelectionHandler.modelGet)(EntitySelectionHandler.modelSet))

  private val subCriteriaSelectionHandler =
    new SubCriteriaSelectionHandler(zoomRW(SubCriteriaSelectionHandler.modelGet)(SubCriteriaSelectionHandler.modelSet))

  private val expertConfigHandler =
    new ExpertConfigHandler(zoomRW(ExpertConfigHandler.modelGet)(ExpertConfigHandler.modelSet))

  private val chartLayoutHandler =
    new ChartLayoutHandler(zoomRW(ChartLayoutHandler.modelGet)(ChartLayoutHandler.modelSet))

  private val pdfExportHandler =
    new PdfExportHandler(zoomRW(PdfExportHandler.modelGet)(PdfExportHandler.modelSet))

  override protected val actionHandler: HandlerFunction =
    composeHandlers(
      analysisImportHandler,
      colorHandler,
      entitySelectionHandler,
      subCriteriaSelectionHandler,
      expertConfigHandler,
      chartLayoutHandler,
      pdfExportHandler
    )

  override def handleError(msg: String): Unit = {
    val name = getClass.getSimpleName
    println(s"[$name] Error: $msg")
  }

} 
开发者ID:fhnw-saav,项目名称:saav,代码行数:49,代码来源:SaavCircuit.scala

示例5: AppCircuit

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

import diode._
import diode.react.ReactConnector
import weatherApp.models.{GithubUser, WeatherForecastResponse, WeatherResponse}

object AppCircuit extends Circuit[AppModel] with ReactConnector[AppModel] {
  def initialModel = AppModel(
    AppState(
      weatherSuggestions = List.empty[WeatherResponse],
      forecast = None: Option[WeatherForecastResponse],
      selectedWeather = None: Option[WeatherResponse],
      isLoading = false,
      user = None : Option[GithubUser]
    )
  )

  override val actionHandler = composeHandlers(
    new WeatherPageHandler(zoomTo(_.state)),
    new AppHandler(zoomTo(_.state))
  )
}

class WeatherPageHandler[M](modelRW: ModelRW[M, AppState]) extends ActionHandler(modelRW) {
  override def handle = {
    case GetWeatherSuggestions(weatherSuggestions) => updated(value.copy(weatherSuggestions = weatherSuggestions))
    case GetWeatherForecast(forecast) => updated(value.copy(forecast = forecast))
    case ClearForecast() => updated(value.copy(forecast = None))
    case SelectWeather(weather) => updated(value.copy(selectedWeather = weather))
  }
}

class AppHandler[M](modelRW: ModelRW[M, AppState]) extends ActionHandler(modelRW) {
  override def handle = {
    case SetLoadingState() => updated(value.copy(isLoading = true))
    case ClearLoadingState() => updated(value.copy(isLoading = false))
    case GetUserInfo(user) => updated(value.copy(user = user))
  }
} 
开发者ID:malaman,项目名称:scala-weather-app,代码行数:40,代码来源:AppCircuit.scala

示例6: AppCircuit

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

import diode._
import diode.react.ReactConnector
import net.devkat.pegasus.actions._
import net.devkat.pegasus.model._


object AppCircuit extends Circuit[RootModel] with ReactConnector[RootModel] {
  def initialModel = RootModel(
    Flow(Vector(Section(children = Vector(Paragraph(children = Vector(Character(ch = 'a'))))))),
    None
  )

  override val actionHandler = composeHandlers(
    new FlowHandler(zoomRW(_.flow)((m, v) => m.copy(flow = v))),
    new SelectionHandler(zoomRW(_.selection)((m, v) => m.copy(selection = v)))
  )
} 
开发者ID:devkat,项目名称:pegasus,代码行数:20,代码来源:AppCircuit.scala

示例7: DashboardModel

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

import autowire._
import diode._
import diode.data._
import diode.react.ReactConnector
import kidstravel.shared.Api
import boopickle.Default._
import diode.ActionResult.{ModelUpdate, ModelUpdateEffect}
import kidstravel.shared.geo.{City, CityLabel}
import kidstravel.shared.poi.Poi

case class DashboardModel(
  cityCandidates: Pot[Seq[CityLabel]],
  topCities: Pot[Seq[(City, Pot[FlickrImage])]]
)

// The base model of our application
case class RootModel(
  dashboard: DashboardModel,
  city: Pot[City],
  pois: PotMap[Long, Poi]
)

// Application circuit
object KidsTravelCircuit extends Circuit[RootModel] with ReactConnector[RootModel] {

  // initial application model
  override protected def initialModel =
    RootModel(DashboardModel(Empty, Empty), Empty, PotMap(new PoiFetch(this)))

  // combine all handlers into one
  override protected val actionHandler = composeHandlers(
    new PoiHandler(zoomRW(_.pois)((m, v) => m.copy(pois = v))),
    new CitySearchHandler(
      zoomRW(_.dashboard)((m, v) => m.copy(dashboard = v)).
      zoomRW(_.cityCandidates)((m, v) => m.copy(cityCandidates = v))),
    new TopCitiesHandler(
      zoomRW(_.dashboard)((m, v) => m.copy(dashboard = v)).
      zoomRW(_.topCities)((m, v) => m.copy(topCities = v))),
    new CityHandler(zoomRW(_.city)((m, v) => m.copy(city = v)))
  )
} 
开发者ID:devkat,项目名称:kidstravel,代码行数:44,代码来源:KidsTravelCircuit.scala


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