Skip to content

Force update #103

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 4 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -122,6 +122,20 @@ function createClass(spec) {
}
exports.createClass = createClass;

function forceUpdateImpl(this_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is no longer used, right?

Copy link
Author

Choose a reason for hiding this comment

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

Indeed.

Copy link
Author

Choose a reason for hiding this comment

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

I just forgot to push all changes.

this_.forceUpdate();
return {};
};
exports.forceUpdateImpl = forceUpdateImpl

function forceUpdateCbImpl(this_, cb) {
this_.forceUpdate(function() {
return cb();
});
return {};
};
exports.forceUpdateCbImpl = forceUpdateCbImpl;

function handle(f) {
return function(e){
return f(e)();
Expand Down
24 changes: 24 additions & 0 deletions src/React.purs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ module React
, writeStateWithCallback
, transformState

, forceUpdate
, forceUpdateCb

, handle
, preventDefault
, stopPropagation
Expand All @@ -65,7 +68,9 @@ module React
) where

import Prelude

import Control.Monad.Eff (kind Effect, Eff)
import Control.Monad.Eff.Uncurried (EffFn1, EffFn2, runEffFn1, runEffFn2)
import Unsafe.Coerce (unsafeCoerce)

-- | Name of a tag.
Expand Down Expand Up @@ -335,6 +340,25 @@ createClassStateless' k =
createClassStateless \props ->
k props (childrenToArray (unsafeCoerce props).children)

foreign import forceUpdateImpl :: forall eff props state.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this one can be implemented in terms of the other using pure unit?

EffFn1 eff (ReactThis props state) Unit

-- | Force render of a react component.
forceUpdate :: forall eff props state.
ReactThis props state -> Eff eff Unit
forceUpdate this = runEffFn1 forceUpdateImpl this

foreign import forceUpdateCbImpl :: forall eff e props state.
EffFn2 eff
(ReactThis props state)
(Eff e Unit)
Unit

-- | Force render and then run an Eff computation.
forceUpdateCb :: forall eff props state.
ReactThis props state -> Eff eff Unit -> Eff eff Unit
forceUpdateCb this m = runEffFn2 forceUpdateCbImpl this m

-- | Create an event handler.
foreign import handle :: forall eff ev props state result.
(ev -> EventHandlerContext eff props state result) -> EventHandler ev
Expand Down