Skip to content

Add writeState with callback #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 @@ -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

Expand Down