All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scalajs.nodejs.drama.StateDrivenActor.scala Maven / Gradle / Ivy

The newest version!
package org.scalajs.nodejs.drama

import org.scalajs.nodejs.drama.StateDrivenActor.ReplyScope

import scala.scalajs.js
import scala.scalajs.js.annotation.ScalaJSDefined

/**
  * State-driven Actor
  * @author [email protected]
  */
@ScalaJSDefined
class StateDrivenActor[T](initialState: T) extends js.Object {
  private var state = initialState

  def get: js.ThisFunction0[ReplyScope[T], Unit] = (scope: ReplyScope[T]) => scope.reply(state)

  def set: js.Function = (newState: T) => state = newState

}

/**
  * State-driven Actor Companion
  * @author [email protected]
  */
object StateDrivenActor {

  @js.native
  trait ReplyScope[T] extends js.Object {
    var reply: js.Function1[T, Unit] = js.native
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy