Skip to content

Commit 8e7c3a7

Browse files
committed
Upgrade purescript-react to v8.0.0. Use the new ref api. (Fixed #26).
1 parent e4a160a commit 8e7c3a7

File tree

4 files changed

+12
-67
lines changed

4 files changed

+12
-67
lines changed

lib/src/Concur/React/Props.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,3 @@ exports.resetTargetValue = function(s) {
99
};
1010

1111
exports.emptyProp_ = {}
12-
13-
exports.createRef = function() {
14-
return (function() {
15-
var x;
16-
return [
17-
function(cur) {
18-
x=cur;
19-
},
20-
function() {
21-
return x;
22-
}
23-
];
24-
})();
25-
};
26-
27-
exports.refSetter = function(ref) {
28-
return function(cur) {
29-
return function() {
30-
return ref[0](cur);
31-
}
32-
};
33-
};
34-
35-
exports.refGetter_ = function(ref) {
36-
return function() {
37-
return ref[1]();
38-
};
39-
};

lib/src/Concur/React/Props.purs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import Prelude
55
import Concur.Core.Props (Props(..), filterProp)
66
import Data.Array (concatMap, intercalate)
77
import Data.Maybe (Maybe, maybe)
8-
import Data.Nullable (Nullable, toMaybe)
98
import Effect (Effect)
109
import Effect.Uncurried (mkEffectFn1)
11-
import React (ReactRef)
10+
import React.Ref as Ref
1211
import React.DOM.Props as P
1312
import React.SyntheticEvent
1413
( SyntheticAnimationEvent
@@ -50,37 +49,6 @@ unsafeMkProp ::
5049
ReactProps b
5150
unsafeMkProp s v = PrimProp (P.unsafeMkProps s v)
5251

53-
foreign import data RRef :: Type -> Type
54-
55-
foreign import createRef :: forall a. Effect (RRef a)
56-
57-
foreign import refSetter :: forall a. RRef a -> a -> Effect Unit
58-
59-
foreign import refGetter_ :: forall a. RRef a -> Effect (Nullable a)
60-
61-
-- | `refGetter` will collapse nullable values
62-
-- | So it will never return a `Just null`, only either `Nothing`, or `Just (notNull a)`
63-
-- | So with `Nullable a`, it is easier, without loss of generality, to use `refNullableGetter`
64-
refGetter ::
65-
forall a.
66-
RRef a ->
67-
Effect (Maybe a)
68-
refGetter rf = toMaybe <$> refGetter_ rf
69-
70-
refNullableGetter :: forall a. RRef (Nullable a) -> Effect (Maybe a)
71-
refNullableGetter rf = (unsafeCoerce <<< toMaybe) <$> refGetter_ rf
72-
73-
-- | Use `refProp` to convert a `Handler` to a static prop
74-
-- | The value returned by the handler is stored in the RRef passed
75-
refProp ::
76-
forall a b.
77-
RRef a ->
78-
ReactProps a ->
79-
ReactProps b
80-
refProp rref (PrimProp p) = PrimProp p
81-
82-
refProp rref (Handler f) = PrimProp (f (refSetter rref))
83-
8452
-- | Shortcut for the common case of a list of classes
8553
classList ::
8654
forall a.
@@ -986,8 +954,8 @@ onScrollCapture = Handler P.onScrollCapture
986954
onWheelCapture :: ReactProps SyntheticWheelEvent
987955
onWheelCapture = Handler P.onWheelCapture
988956

989-
ref :: ReactProps (Nullable ReactRef)
990-
ref = Handler P.ref
957+
ref :: forall a. Ref.RefHandler Ref.NativeNode -> ReactProps a
958+
ref = PrimProp <<< P.ref
991959

992960
suppressContentEditableWarning :: forall a. Boolean -> ReactProps a
993961
suppressContentEditableWarning = PrimProp <<< P.suppressContentEditableWarning

lib/src/Concur/React/Widgets.purs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Concur.React.Props (ReactProps)
99
import Concur.React.Props as P
1010
import Data.Maybe (Maybe(..))
1111
import Effect.Class (liftEffect)
12+
import React.Ref as Ref
1213
import Unsafe.Coerce (unsafeCoerce)
1314

1415
-- | A Text input that returns its contents on enter
@@ -33,17 +34,17 @@ textInputWithButton ::
3334
(forall a. Array (ReactProps a)) ->
3435
Widget HTML String
3536
textInputWithButton val buttonlabel inpProps buttonProps = do
36-
ref <- liftEffect P.createRef
37+
ref <- liftEffect Ref.createNodeRef
3738
D.div'
3839
[ D.input $ inpProps <>
3940
[ P.unsafeTargetValue <$> P.onKeyEnter
4041
, P.defaultValue val
41-
, P.refProp ref P.ref
42+
, P.ref (Ref.fromRef ref)
4243
]
4344
, D.text " "
4445
, do
4546
_ <- D.button (buttonProps <> [P.onClick]) [D.text buttonlabel]
46-
mInput <- liftEffect $ P.refNullableGetter ref
47+
mInput <- liftEffect (Ref.getCurrentRef ref)
4748
case mInput of
4849
Nothing -> pure val
4950
Just inp -> pure (unsafeCoerce inp).value

packages.dhall

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ let mkPackage =
114114
let upstream =
115115
https://github.com/purescript/package-sets/releases/download/psc-0.13.3-20190818/packages.dhall sha256:c95c4a8b8033a48a350106b759179f68a695c7ea2208228c522866fd43814dc8
116116

117-
let overrides = { concur-react = ./lib/spago.dhall as Location }
117+
let overrides =
118+
{ concur-react = ./lib/spago.dhall as Location
119+
, react =
120+
upstream.react // { version = "v8.0.0" }
121+
}
118122

119123
let additions = {=}
120124

0 commit comments

Comments
 (0)