Skip to content

Commit

Permalink
Add ReactComponentB.configureSpec
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit f5c4d20
Merge: e94bcf8 db95d22
Author: chandu0101 <chandu.csu2010@gmail.com>
Date:   Mon Jun 15 17:13:24 2015 +0530

    Merge branch 'unsfasespec' of https://github.com/chandu0101/scalajs-react into unsfasespec

commit e94bcf8
Author: chandu0101 <chandu.csu2010@gmail.com>
Date:   Sat Jun 13 13:39:05 2015 +0530

    add configureSpec to ReactComponentB

    add unsafeSpec to ReactComponentB

    add configureSpec tp ReactComponentB

commit db95d22
Author: chandu0101 <chandu.csu2010@gmail.com>
Date:   Mon Jun 15 16:32:11 2015 +0530

    add configureSpec tp ReactComponentB

commit a1a3d41
Author: chandu0101 <chandu.csu2010@gmail.com>
Date:   Sat Jun 13 13:39:05 2015 +0530

    add unsafeSpec to ReactComponentB

commit 096859e
Author: chandu0101 <chandu.csu2010@gmail.com>
Date:   Sat Jun 13 13:33:20 2015 +0530

    add unsafeSpec to ReactComponentB
  • Loading branch information
japgolly committed Jun 16, 2015
1 parent bc0cff4 commit 5a76e38
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ object ReactComponentB {

// ===================================================================================================================
private[react] case class LifeCycle[P,S,B,N <: TopNode](
configureSpec : UndefOr[ReactComponentSpec[P, S, B, N] => Unit],
getDefaultProps : UndefOr[() => P],
componentWillMount : UndefOr[ComponentScopeU[P, S, B] => Unit],
componentDidMount : UndefOr[ComponentScopeM[P, S, B, N] => Unit],
Expand All @@ -86,7 +87,7 @@ object ReactComponentB {
shouldComponentUpdate : UndefOr[(ComponentScopeM[P, S, B, N], P, S) => Boolean])

private[react] def emptyLifeCycle[P,S,B,N <: TopNode] =
LifeCycle[P,S,B,N](undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined)
LifeCycle[P,S,B,N](undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined)
}

import ReactComponentB.LifeCycle
Expand All @@ -109,6 +110,9 @@ final class ReactComponentB[P,S,B,N <: TopNode](val name: String,
@inline private implicit def lcmod(a: LifeCycle[P, S, B, N]): ReactComponentB[P, S, B, N] =
copy(lc = a)

def configureSpec(modify: ReactComponentSpec[P, S, B, N] => Unit): ReactComponentB[P, S, B, N] =
lc.copy(configureSpec = modify)

def configure(fs: (ReactComponentB[P, S, B, N] => ReactComponentB[P, S, B, N])*): ReactComponentB[P, S, B, N] =
fs.foldLeft(this)((a,f) => f(a))

Expand Down Expand Up @@ -189,7 +193,6 @@ final class ReactComponentB[P,S,B,N <: TopNode](val name: String,
lc.getDefaultProps.foreach(f => spec.updateDynamic("getDefaultProps")(f: Function))
lc.componentWillUnmount.foreach(f => spec.updateDynamic("componentWillUnmount")(f: ThisFunction))
lc.componentDidMount.foreach(f => spec.updateDynamic("componentDidMount")(f: ThisFunction))

setFnPS(lc.componentWillUpdate, "componentWillUpdate")
setFnPS(lc.componentDidUpdate, "componentDidUpdate")
setFnPS(lc.shouldComponentUpdate, "shouldComponentUpdate")
Expand All @@ -204,6 +207,7 @@ final class ReactComponentB[P,S,B,N <: TopNode](val name: String,
spec.updateDynamic("mixins")(mixins)
}

lc.configureSpec.foreach(_(spec.asInstanceOf[ReactComponentSpec[P, S, B, N]]))
spec.asInstanceOf[ReactComponentSpec[P, S, B, N]]
}

Expand Down

0 comments on commit 5a76e38

Please sign in to comment.