Skip to content

Commit 7de839d

Browse files
authored
Merge pull request #80 from pkamenarsky/master
Add writeState with callback
2 parents 326dbb6 + 93aba56 commit 7de839d

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
@@ -51,6 +51,20 @@ function writeState(this_) {
5151
}
5252
exports.writeState = writeState;
5353

54+
function writeStateWithCallback(this_, cb) {
55+
return function(state){
56+
return function(cb){
57+
return function() {
58+
this_.setState({
59+
state: state
60+
}, cb);
61+
return state;
62+
};
63+
};
64+
};
65+
}
66+
exports.writeStateWithCallback = writeStateWithCallback;
67+
5468
function readState(this_) {
5569
return function(){
5670
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
@@ -302,6 +303,9 @@ foreign import writeState :: forall props state access eff.
302303
state ->
303304
Eff (state :: ReactState (write :: Write | access) | eff) state
304305

306+
-- | Write the component state with a callback.
307+
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
308+
305309
-- | Read the component state.
306310
foreign import readState :: forall props state access eff.
307311
ReactThis props state ->

0 commit comments

Comments
 (0)