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) {
122
122
}
123
123
exports . createClass = createClass ;
124
124
125
+ function forceUpdateCbImpl ( this_ , cb ) {
126
+ this_ . forceUpdate ( function ( ) {
127
+ return cb ( ) ;
128
+ } ) ;
129
+ return { } ;
130
+ } ;
131
+ exports . forceUpdateCbImpl = forceUpdateCbImpl ;
132
+
125
133
function handle ( f ) {
126
134
return function ( e ) {
127
135
return f ( e ) ( ) ;
Original file line number Diff line number Diff line change @@ -50,6 +50,9 @@ module React
50
50
, writeStateWithCallback
51
51
, transformState
52
52
53
+ , forceUpdate
54
+ , forceUpdateCb
55
+
53
56
, handle
54
57
, preventDefault
55
58
, stopPropagation
@@ -65,7 +68,9 @@ module React
65
68
) where
66
69
67
70
import Prelude
71
+
68
72
import Control.Monad.Eff (kind Effect , Eff )
73
+ import Control.Monad.Eff.Uncurried (EffFn2 , runEffFn2 )
69
74
import Unsafe.Coerce (unsafeCoerce )
70
75
71
76
-- | Name of a tag.
@@ -335,6 +340,22 @@ createClassStateless' k =
335
340
createClassStateless \props ->
336
341
k props (childrenToArray (unsafeCoerce props).children)
337
342
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
+
338
359
-- | Create an event handler.
339
360
foreign import handle :: forall eff ev props state result .
340
361
(ev -> EventHandlerContext eff props state result ) -> EventHandler ev
You can’t perform that action at this time.
0 commit comments