Skip to content
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