Skip to content

Fix transformState to use current state #62

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
Feb 29, 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
11 changes: 11 additions & 0 deletions src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ function readState(this_) {
}
exports.readState = readState;

function transformState(this_){
return function(update){
return function(){
this_.setState(function(old, props){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this form is actually getting the state?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, modifying, I see.

return {state: update(old.state)};
});
};
};
}
exports.transformState = transformState;

function createClass(spec) {
var result = {
displayName: spec.displayName,
Expand Down
5 changes: 1 addition & 4 deletions src/React.purs
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,7 @@ foreign import writeState :: forall props state access eff. ReactThis props stat
foreign import readState :: forall props state access eff. ReactThis props state -> Eff (state :: ReactState (read :: Read | access) | eff) state

-- | Transform the component state by applying a function.
transformState :: forall props state eff. ReactThis props state -> (state -> state) -> Eff (state :: ReactState ReadWrite | eff) state
transformState ctx f = do
state <- readState ctx
writeState ctx $ f state
foreign import transformState :: forall props state eff. ReactThis props state -> (state -> state) -> Eff (state :: ReactState ReadWrite | eff) Unit

-- | Create a React class from a specification.
foreign import createClass :: forall props state eff. ReactSpec props state eff -> ReactClass props
Expand Down