diff --git a/src/React.js b/src/React.js index baac747..9a7188e 100644 --- a/src/React.js +++ b/src/React.js @@ -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; diff --git a/src/React.purs b/src/React.purs index fefa7dd..14b7b43 100644 --- a/src/React.purs +++ b/src/React.purs @@ -47,6 +47,7 @@ module React , readState , writeState + , writeStateWithCallback , transformState , handle @@ -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 ->