File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,14 @@ function createClass(spec) {
122122}
123123exports . createClass = createClass ;
124124
125+ function forceUpdateCbImpl ( this_ , cb ) {
126+ this_ . forceUpdate ( function ( ) {
127+ return cb ( ) ;
128+ } ) ;
129+ return { } ;
130+ } ;
131+ exports . forceUpdateCbImpl = forceUpdateCbImpl ;
132+
125133function handle ( f ) {
126134 return function ( e ) {
127135 return f ( e ) ( ) ;
Original file line number Diff line number Diff line change @@ -50,6 +50,9 @@ module React
5050 , writeStateWithCallback
5151 , transformState
5252
53+ , forceUpdate
54+ , forceUpdateCb
55+
5356 , handle
5457 , preventDefault
5558 , stopPropagation
@@ -65,7 +68,9 @@ module React
6568 ) where
6669
6770import Prelude
71+
6872import Control.Monad.Eff (kind Effect , Eff )
73+ import Control.Monad.Eff.Uncurried (EffFn2 , runEffFn2 )
6974import Unsafe.Coerce (unsafeCoerce )
7075
7176-- | Name of a tag.
@@ -335,6 +340,22 @@ createClassStateless' k =
335340 createClassStateless \props ->
336341 k props (childrenToArray (unsafeCoerce props).children)
337342
343+ -- | Force render of a react component.
344+ forceUpdate :: forall eff props state .
345+ ReactThis props state -> Eff eff Unit
346+ forceUpdate this = forceUpdateCb this (pure unit)
347+
348+ foreign import forceUpdateCbImpl :: forall eff e props state .
349+ EffFn2 eff
350+ (ReactThis props state )
351+ (Eff e Unit )
352+ Unit
353+
354+ -- | Force render and then run an Eff computation.
355+ forceUpdateCb :: forall eff props state .
356+ ReactThis props state -> Eff eff Unit -> Eff eff Unit
357+ forceUpdateCb this m = runEffFn2 forceUpdateCbImpl this m
358+
338359-- | Create an event handler.
339360foreign import handle :: forall eff ev props state result .
340361 (ev -> EventHandlerContext eff props state result ) -> EventHandler ev
You can’t perform that action at this time.
0 commit comments