From 93aba568f0b53de6a3818d51c97df30bbeb3a8cc Mon Sep 17 00:00:00 2001
From: Philip Kamenarsky
Date: Fri, 10 Jun 2016 13:42:41 +0300
Subject: [PATCH] Add writeState with callback
---
src/React.js | 14 ++++++++++++++
src/React.purs | 4 ++++
2 files changed, 18 insertions(+)
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