Skip to content

Commit 93aba56

Browse files
committed
Add writeState with callback
1 parent 376f256 commit 93aba56

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/React.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ function writeState(this_) {
5353
}
5454
exports.writeState = writeState;
5555

56+
function writeStateWithCallback(this_, cb) {
57+
return function(state){
58+
return function(cb){
59+
return function() {
60+
this_.setState({
61+
state: state
62+
}, cb);
63+
return state;
64+
};
65+
};
66+
};
67+
}
68+
exports.writeStateWithCallback = writeStateWithCallback;
69+
5670
function readState(this_) {
5771
return function(){
5872
return this_.state.state;

src/React.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module React
4747

4848
, readState
4949
, writeState
50+
, writeStateWithCallback
5051
, transformState
5152

5253
, handle
@@ -281,6 +282,9 @@ foreign import getChildren :: forall props state eff. ReactThis props state -> E
281282
-- | Write the component state.
282283
foreign import writeState :: forall props state access eff. ReactThis props state -> state -> Eff (state :: ReactState (write :: Write | access) | eff) state
283284

285+
-- | Write the component state with a callback.
286+
foreign import writeStateWithCallback :: forall props state access eff. ReactThis props state -> state -> Eff (state :: ReactState (write :: Write | access) | eff) Unit -> Eff (state :: ReactState (write :: Write | access) | eff) state
287+
284288
-- | Read the component state.
285289
foreign import readState :: forall props state access eff. ReactThis props state -> Eff (state :: ReactState (read :: Read | access) | eff) state
286290

0 commit comments

Comments
 (0)