diff --git a/src/React.js b/src/React.js index 2f73d8c..0565c73 100644 --- a/src/React.js +++ b/src/React.js @@ -53,6 +53,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 4ecb357..4beade6 100644 --- a/src/React.purs +++ b/src/React.purs @@ -47,6 +47,7 @@ module React , readState , writeState + , writeStateWithCallback , transformState , handle @@ -281,6 +282,9 @@ foreign import getChildren :: forall props state eff. ReactThis props state -> E -- | Write the component state. foreign import writeState :: forall props state access eff. ReactThis props state -> 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 -> Eff (state :: ReactState (read :: Read | access) | eff) state