@@ -5,6 +5,7 @@ import japgolly.scalajs.react.internal._
55import japgolly .scalajs .react .vdom .VdomNode
66import japgolly .scalajs .react .{Children , CtorType , PropsChildren , facade }
77import scala .scalajs .js
8+ import japgolly .scalajs .react .Reusability
89
910object ScalaFn {
1011
@@ -23,6 +24,11 @@ object ScalaFn {
2324 .mapUnmounted(_.mapUnmountedProps(_.unbox))
2425 }
2526
27+ @ inline def withHooks [P ] =
28+ HookComponentBuilder .apply[P ]
29+
30+ // ===================================================================================================================
31+
2632 def apply [P ](render : P => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .None ]): Component [P , s.CT ] =
2733 create[P , Children .None , s.CT ](b => render(b.unbox))(s)
2834
@@ -32,6 +38,17 @@ object ScalaFn {
3238 def justChildren (render : PropsChildren => VdomNode ): Component [Unit , CtorType .Children ] =
3339 create(b => render(PropsChildren (b.children)))
3440
35- @ inline def withHooks [P ] =
36- HookComponentBuilder .apply[P ]
41+ // ===================================================================================================================
42+
43+ def withReuse [P ](render : P => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .None ], r : Reusability [P ]): Component [P , s.CT ] =
44+ withHooks[P ].renderWithReuse(render)(s, r)
45+
46+ def withReuseBy [P , A ](reusableInputs : P => A )(render : A => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .None ], r : Reusability [A ]): Component [P , s.CT ] =
47+ withHooks[P ].renderWithReuseBy(reusableInputs)(render)(s, r)
48+
49+ def withChildrenAndReuse [P ](render : (P , PropsChildren ) => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .Varargs ], rp : Reusability [P ], rc : Reusability [PropsChildren ]): Component [P , s.CT ] =
50+ withHooks[P ].withPropsChildren.renderWithReuse(i => render(i.props, i.propsChildren))
51+
52+ def withChildrenAndReuse [P , A ](reusableInputs : (P , PropsChildren ) => A )(render : A => VdomNode )(implicit s : CtorType .Summoner [Box [P ], Children .Varargs ], r : Reusability [A ]): Component [P , s.CT ] =
53+ withHooks[P ].withPropsChildren.renderWithReuseBy(i => reusableInputs(i.props, i.propsChildren))(render)
3754}
0 commit comments