Last active
March 17, 2018 01:11
-
-
Save bfleischhacker/76ceb06299f14d282aad9704f3991176 to your computer and use it in GitHub Desktop.
Using a JS Higher-Order-Component (https://github.com/viktorbergehall/lcHOC) with scala-react-interface (sri)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sri.core.{ComponentConstructor, ReactClass} | |
import scala.scalajs.js | |
import scala.scalajs.js.ConstructorTag | |
object LcHoc { | |
def apply[T <: ReactClass {type PropsType; type StateType}](params: js.UndefOr[LcHocParams] = js.undefined) | |
(implicit tag: ConstructorTag[T]): ComponentConstructor { | |
type ComponentType = T | |
type PropsType = T#PropsType | |
type StateType = T#StateType | |
} = LcHocJs(tag.constructor, params).asInstanceOf[ | |
ComponentConstructor { | |
type ComponentType = T | |
type PropsType = T#PropsType | |
type StateType = T#StateType | |
}] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sri.core.ReactClass | |
import scala.scalajs.js | |
import scala.scalajs.js.UndefOr | |
import scala.scalajs.js.annotation.{JSImport, ScalaJSDefined} | |
@ScalaJSDefined | |
trait LcHocParams extends js.Object { | |
val log: js.UndefOr[Log] = js.undefined | |
val flash: js.UndefOr[Boolean] = js.undefined | |
} | |
object LcHocParams { | |
@ScalaJSDefined | |
trait Log extends js.Object { | |
val use: js.UndefOr[Boolean] = js.undefined | |
val expanded: js.UndefOr[Boolean] = js.undefined | |
val renderCount: js.UndefOr[Boolean] = js.undefined | |
val state: js.UndefOr[Boolean] = js.undefined | |
val props: js.UndefOr[Boolean] = js.undefined | |
val timings: js.UndefOr[Boolean] = js.undefined | |
} | |
} | |
@js.native | |
@JSImport("lc-hoc", JSImport.Default) | |
object LcHocJs extends js.Function2[js.Dynamic, js.UndefOr[LcHocParams], ReactClass] { | |
override def apply(constructor: js.Dynamic, params: UndefOr[LcHocParams]): ReactClass = js.native | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sri.core.{ComponentP, CreateElement} | |
object Usage { | |
class MyComponent extends ComponentP[MyComponent.Props] | |
object MyComponent { | |
case class Props() | |
} | |
CreateElementJS[MySriComponent](LcHoc[MyComponent](), props= MyComponent.Props()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment