@@ -4,7 +4,7 @@ import japgolly.scalajs.react.component.ScalaFn
4
4
import japgolly .scalajs .react .component .ScalaFn .Component
5
5
import japgolly .scalajs .react .internal .Box
6
6
import japgolly .scalajs .react .vdom .VdomNode
7
- import japgolly .scalajs .react .{Children , CtorType , PropsChildren }
7
+ import japgolly .scalajs .react .{Children , CtorType , PropsChildren , Reusability }
8
8
9
9
object HookComponentBuilder {
10
10
@@ -16,7 +16,7 @@ object HookComponentBuilder {
16
16
17
17
object ComponentP {
18
18
19
- final class First [P ](init : P => Unit ) extends Api .Primary [ P , FirstStep [P ]] {
19
+ final class First [P ](init : P => Unit ) extends Api .PrimaryWithRender [ P , Children . None , P , FirstStep [P ]] {
20
20
21
21
override protected def self (f : P => Any )(implicit step : Step ): step.Self =
22
22
step.self(init, f)
@@ -27,25 +27,33 @@ object HookComponentBuilder {
27
27
def withPropsChildren : ComponentPC .First [P ] =
28
28
new ComponentPC .First (ctx => init(ctx.props))
29
29
30
- def render (f : P => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .None ]): Component [P , s.CT ] =
30
+ override def render (f : P => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .None ]): Component [P , s.CT ] =
31
31
ScalaFn (f)
32
+
33
+ override def renderWithReuseBy [A ](reusableInputs : P => A )(f : A => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .None ], r : Reusability [A ]): Component [P , s.CT ] =
34
+ customBy(p => CustomHook .shouldComponentUpdate(f).apply(() => reusableInputs(p)))
35
+ .render((_ : HookCtx .P1 [P , VdomNode ]).hook1)
32
36
}
33
37
34
38
type RenderFn [- P , + Ctx ] = (Ctx => VdomNode ) => P => VdomNode
35
39
36
- final class Subsequent [P , Ctx , CtxFn [_]](renderFn : RenderFn [P , Ctx ]) extends Api .Secondary [ Ctx , CtxFn , SubsequentStep [P , Ctx , CtxFn ]] {
40
+ final class Subsequent [P , Ctx , CtxFn [_]](renderFn : RenderFn [P , Ctx ]) extends Api .SecondaryWithRender [ P , Children . None , Ctx , CtxFn , SubsequentStep [P , Ctx , CtxFn ]] {
37
41
38
42
override protected def self (f : Ctx => Any )(implicit step : Step ): step.Self =
39
43
step.self(renderFn, f)
40
44
41
45
override protected def next [H ](f : Ctx => H )(implicit step : Step ): step.Next [H ] =
42
46
step.next[H ](renderFn, f)
43
47
44
- def render (f : Ctx => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .None ]): Component [P , s.CT ] =
48
+ override def render (f : Ctx => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .None ]): Component [P , s.CT ] =
45
49
ScalaFn (renderFn(f))
46
50
47
- def render (f : CtxFn [VdomNode ])(implicit step : Step , s : CtorType .Summoner [Box [P ], Children .None ]): Component [P , s.CT ] =
48
- render(step.squash(f)(_))
51
+ override def renderWithReuseBy [A ](reusableInputs : Ctx => A )(f : A => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .None ], r : Reusability [A ]): Component [P , s.CT ] = {
52
+ val hook = CustomHook .shouldComponentUpdate(f)
53
+ ScalaFn (renderFn { ctx =>
54
+ hook.unsafeInit(() => reusableInputs(ctx))
55
+ })
56
+ }
49
57
}
50
58
51
59
object Subsequent extends ComponentP_SubsequentDsl
@@ -99,36 +107,45 @@ object HookComponentBuilder {
99
107
100
108
object ComponentPC {
101
109
102
- final class First [P ](init : HookCtx .PC0 [P ] => Unit ) extends Api .Primary [HookCtx .PC0 [P ], FirstStep [P ]] {
110
+ final class First [P ](init : HookCtx .PC0 [P ] => Unit ) extends Api .PrimaryWithRender [P , Children .Varargs , HookCtx .PC0 [P ], FirstStep [P ]] {
111
+ type Ctx = HookCtx .PC0 [P ]
103
112
104
- override protected def self (f : HookCtx . PC0 [ P ] => Any )(implicit step : Step ): step.Self =
113
+ override protected def self (f : Ctx => Any )(implicit step : Step ): step.Self =
105
114
step.self(init, f)
106
115
107
- override protected def next [H ](f : HookCtx . PC0 [ P ] => H )(implicit step : Step ): step.Next [H ] =
116
+ override protected def next [H ](f : Ctx => H )(implicit step : Step ): step.Next [H ] =
108
117
step.next(init, f)
109
118
110
- def render (f : HookCtx . PC0 [ P ] => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .Varargs ]): Component [P , s.CT ] =
119
+ override def render (f : Ctx => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .Varargs ]): Component [P , s.CT ] =
111
120
ScalaFn .withChildren((p : P , pc : PropsChildren ) => f(HookCtx .withChildren(p, pc)))
112
121
113
122
def render (f : (P , PropsChildren ) => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .Varargs ]): Component [P , s.CT ] =
114
123
ScalaFn .withChildren(f)
124
+
125
+ override def renderWithReuseBy [A ](reusableInputs : Ctx => A )(f : A => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .Varargs ], r : Reusability [A ]): Component [P , s.CT ] =
126
+ customBy(ctx => CustomHook .shouldComponentUpdate(f).apply(() => reusableInputs(ctx)))
127
+ .render((_ : HookCtx .PC1 [P , VdomNode ]).hook1)
115
128
}
116
129
117
130
type RenderFn [- P , + Ctx ] = (Ctx => VdomNode ) => (P , PropsChildren ) => VdomNode
118
131
119
- final class Subsequent [P , Ctx , CtxFn [_]](renderFn : RenderFn [P , Ctx ]) extends Api .Secondary [ Ctx , CtxFn , SubsequentStep [P , Ctx , CtxFn ]] {
132
+ final class Subsequent [P , Ctx , CtxFn [_]](renderFn : RenderFn [P , Ctx ]) extends Api .SecondaryWithRender [ P , Children . Varargs , Ctx , CtxFn , SubsequentStep [P , Ctx , CtxFn ]] {
120
133
121
134
override protected def self (f : Ctx => Any )(implicit step : Step ): step.Self =
122
135
step.self(renderFn, f)
123
136
124
137
override protected def next [H ](f : Ctx => H )(implicit step : Step ): step.Next [H ] =
125
138
step.next[H ](renderFn, f)
126
139
127
- def render (f : Ctx => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .Varargs ]): Component [P , s.CT ] =
140
+ override def render (f : Ctx => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .Varargs ]): Component [P , s.CT ] =
128
141
ScalaFn .withChildren(renderFn(f))
129
142
130
- def render (f : CtxFn [VdomNode ])(implicit step : Step , s : CtorType .Summoner [Box [P ], Children .Varargs ]): Component [P , s.CT ] =
131
- render(step.squash(f)(_))
143
+ override def renderWithReuseBy [A ](reusableInputs : Ctx => A )(f : A => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .Varargs ], r : Reusability [A ]): Component [P , s.CT ] = {
144
+ val hook = CustomHook .shouldComponentUpdate(f)
145
+ ScalaFn .withChildren(renderFn { ctx =>
146
+ hook.unsafeInit(() => reusableInputs(ctx))
147
+ })
148
+ }
132
149
}
133
150
134
151
object Subsequent extends ComponentPC_SubsequentDsl
0 commit comments