Skip to content

Commit

Permalink
New module: extras
Browse files Browse the repository at this point in the history
  • Loading branch information
japgolly committed Dec 8, 2014
1 parent 6bf9744 commit 80f826b
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 47 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.7.0 (unreleased)

* Removed deprecated methods marked for removal in 0.7.0.
* Moved `.experiment` into a new module "extras".

## 0.6.1 (unreleased)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package japgolly.scalajs.react.experiment
package japgolly.scalajs.react.extras

import scalaz.~>
import scalaz.effect.IO
import japgolly.scalajs.react.{ReactComponentB, ComponentScopeM}
import japgolly.scalajs.react.ScalazReact._

/**
* NOTE: This may be renamed / relocated / removed in future.
Expand All @@ -10,9 +13,20 @@ trait Listenable [A] {
}

object Listenable {

def install[P, S, B <: OnUnmount, A](f: P => Listenable[A], g: ComponentScopeM[P, S, B] => A => Unit) =
OnUnmount.install compose ((_: ReactComponentB[P, S, B])
.componentDidMount(s => s.backend onUnmountF f(s.props).register(g(s))))

def installIO[P, S, B <: OnUnmount, A](f: P => Listenable[A], g: (ComponentScopeM[P, S, B], A) => IO[Unit]) =
install[P, S, B, A](f, t => a => g(t, a).unsafePerformIO())

def installS[P, S, B <: OnUnmount, M[_], A](f: P => Listenable[A], g: A => ReactST[M, S, Unit])(implicit M: M ~> IO) =
installIO[P, S, B, A](f, (t, a) => t.runState(g(a)))

def installF[P, S, B <: OnUnmount, M[_], A](f: P => Listenable[A], g: A => ReactST[M, S, Unit])(implicit M: M ~> IO, F: ChangeFilter[S]) =
installIO[P, S, B, A](f, (t, a) => t.runStateF(g(a)))

}

trait Broadcaster[A] extends Listenable[A] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package japgolly.scalajs.react.experiment
package japgolly.scalajs.react.extras

import japgolly.scalajs.react.ReactComponentB
import org.scalajs.dom.console
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package japgolly.scalajs.react.experiment
package japgolly.scalajs.react.extras

import japgolly.scalajs.react.ReactComponentB

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package japgolly.scalajs.react.experiment
package japgolly.scalajs.react.extras

import scala.scalajs.js
import org.scalajs.dom.window
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package ghpages
import scala.scalajs.js
import org.scalajs.dom.window
import japgolly.scalajs.react._, vdom.ReactVDom._, all._, ScalazReact._
import japgolly.scalajs.react.experiment._
import japgolly.scalajs.react.extras._

object ExperimentExamples {
object ExtrasExamples {

/**
* This is the typical React timer example, modified to use OnUnmount.
Expand Down
16 changes: 11 additions & 5 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ object ScalajsReact extends Build {

// ==============================================================================================
lazy val root = Project("root", file("."))
.aggregate(core, test, scalaz70, scalaz71, ghpages)
.aggregate(core, test, scalaz70, scalaz71, extras, ghpages)
.configure(commonSettings, preventPublication, addCommandAliases(
"t" -> "; test:compile ; test/fastOptStage::test",
"tt" -> ";+test:compile ;+test/fastOptStage::test",
Expand All @@ -105,7 +105,7 @@ object ScalajsReact extends Build {

lazy val test = project
.configure(commonSettings, publicationSettings, utestSettings)
.dependsOn(core, scalaz71)
.dependsOn(core, scalaz71, extras)
.settings(
name := "test",
scalacOptions += "-language:reflectiveCalls")
Expand All @@ -125,11 +125,17 @@ object ScalajsReact extends Build {
lazy val scalaz71 = scalazModule("scalaz-7.1", "7.1.0-4")

// ==============================================================================================
lazy val ghpages = Project("gh-pages", file("gh-pages"))
lazy val extras = project
.configure(commonSettings, publicationSettings)
.dependsOn(core, scalaz71)
.settings(
name := "extras")

// ==============================================================================================
lazy val ghpages = Project("gh-pages", file("gh-pages"))
.dependsOn(core, scalaz71, extras)
.configure(commonSettings, useReact(), preventPublication)
.settings(
emitSourceMaps := false,
artifactPath in (Compile, fullOptJS) := file("gh-pages/res/ghpages.js"))

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,21 +259,4 @@ object ScalazReact {
// Seriously, Scala, get your shit together.
@inline final implicit def moarScalaHandHolding[P,S](b: BackendScope[P,S]): SzRExt_CompStateAccessOps[ComponentScope_SS, S] = (b: ComponentScope_SS[S])
@inline final implicit def moarScalaHandHolding[P,S,B](b: ComponentScopeU[P,S,B]): SzRExt_CompStateAccessOps[ComponentScope_SS, S] = (b: ComponentScope_SS[S])

// ===================================================================================================================
// Experiment supplement

import experiment._

implicit final class SzRExt_Listenable(val a: Listenable.type) extends AnyVal {

def installIO[P, S, B <: OnUnmount, A](f: P => Listenable[A], g: (ComponentScopeM[P, S, B], A) => IO[Unit]) =
Listenable.install[P, S, B, A](f, t => a => g(t, a).unsafePerformIO())

def installS[P, S, B <: OnUnmount, M[+_], A](f: P => Listenable[A], g: A => ReactST[M, S, Unit])(implicit M: M ~> IO) =
installIO[P, S, B, A](f, (t, a) => t.runState(g(a)))

def installF[P, S, B <: OnUnmount, M[+_], A](f: P => Listenable[A], g: A => ReactST[M, S, Unit])(implicit M: M ~> IO, F: ChangeFilter[S]) =
installIO[P, S, B, A](f, (t, a) => t.runStateF(g(a)))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,4 @@ object ScalazReact {
// Seriously, Scala, get your shit together.
@inline final implicit def moarScalaHandHolding[P,S](b: BackendScope[P,S]): SzRExt_CompStateAccessOps[ComponentScope_SS, S] = (b: ComponentScope_SS[S])
@inline final implicit def moarScalaHandHolding[P,S,B](b: ComponentScopeU[P,S,B]): SzRExt_CompStateAccessOps[ComponentScope_SS, S] = (b: ComponentScope_SS[S])

// ===================================================================================================================
// Experiment supplement

import experiment._

implicit final class SzRExt_Listenable(val a: Listenable.type) extends AnyVal {

def installIO[P, S, B <: OnUnmount, A](f: P => Listenable[A], g: (ComponentScopeM[P, S, B], A) => IO[Unit]) =
Listenable.install[P, S, B, A](f, t => a => g(t, a).unsafePerformIO())

def installS[P, S, B <: OnUnmount, M[_], A](f: P => Listenable[A], g: A => ReactST[M, S, Unit])(implicit M: M ~> IO) =
installIO[P, S, B, A](f, (t, a) => t.runState(g(a)))

def installF[P, S, B <: OnUnmount, M[_], A](f: P => Listenable[A], g: A => ReactST[M, S, Unit])(implicit M: M ~> IO, F: ChangeFilter[S]) =
installIO[P, S, B, A](f, (t, a) => t.runStateF(g(a)))
}
}
}

0 comments on commit 80f826b

Please sign in to comment.