Skip to content

Commit

Permalink
Merge pull request #80 from pkamenarsky/master
Browse files Browse the repository at this point in the history
Add writeState with callback
  • Loading branch information
paf31 authored Jun 12, 2016
2 parents 326dbb6 + 93aba56 commit 7de839d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ function writeState(this_) {
}
exports.writeState = writeState;

function writeStateWithCallback(this_, cb) {
return function(state){
return function(cb){
return function() {
this_.setState({
state: state
}, cb);
return state;
};
};
};
}
exports.writeStateWithCallback = writeStateWithCallback;

function readState(this_) {
return function(){
return this_.state.state;
Expand Down
4 changes: 4 additions & 0 deletions src/React.purs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module React

, readState
, writeState
, writeStateWithCallback
, transformState

, handle
Expand Down Expand Up @@ -302,6 +303,9 @@ foreign import writeState :: forall props state access eff.
state ->
Eff (state :: ReactState (write :: Write | access) | eff) state

-- | Write the component state with a callback.
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

-- | Read the component state.
foreign import readState :: forall props state access eff.
ReactThis props state ->
Expand Down

0 comments on commit 7de839d

Please sign in to comment.