Skip to content

Commit 43e391a

Browse files
committed
Upgrade to purescript 0.12, purescript-react 6.0.0
* Have to use createElementUnsafe, createLeafElementUnsafe due to purescript-contrib/purescript-react#151 * Change createNoChild to use createLeafElementUnsafe * Change from Eff eff to Effect * Fix imports * Change unsafe components to require record props
1 parent 17d6b1d commit 43e391a

24 files changed

+294
-298
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ place to go for help. This will be acheived by:
2727
lagging behind or the component does not yet have a safe version, it's still possible to use
2828
the library without too much hassle.
2929

30-
- Stay event framework agnostic. This is acheived by using `EffFnX` to model the event callbacks.
30+
- Stay event framework agnostic. This is acheived by using `EffectFnX` to model the event callbacks.
3131
There will be additional libraries for your favourite action library - e.g. `purescript-reactnative-thermite`
3232
I have also made a very small and simple library for dispatching react actions [purescript-dispatcher-react](http://github.com/doolse/purescript-dispatcher-react).
3333

@@ -168,7 +168,7 @@ Replace the contents of `src/Main.purs` with
168168
module Main where
169169
170170
import Prelude
171-
import Control.Monad.Eff (Eff)
171+
import Effect (Eff)
172172
import React (ReactClass, ReactElement, Render, createClass, getProps, spec)
173173
import ReactNative.API (REGISTER, registerComponent)
174174
import ReactNative.Components.Text (text_)

src/ReactNative/API/API.purs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
module ReactNative.API (
2-
alert, ALERT
2+
alert
33
, keyboardDismiss
4-
, registerComponent, REGISTER
4+
, registerComponent
55
) where
66

7-
import Control.Monad.Eff (kind Effect, Eff)
7+
import Effect (Effect)
88
import Data.Function.Uncurried (Fn4, runFn4)
99
import Data.Maybe (Maybe)
1010
import Data.Nullable (Nullable, toNullable)
1111
import Data.Unit (Unit)
1212
import React (ReactClass)
1313

14-
foreign import data ALERT :: Effect
14+
foreign import alertImpl :: forall b o. Fn4 String (Nullable String) b o (Effect Unit)
1515

16-
foreign import alertImpl :: forall e b o. Fn4 String (Nullable String) b o (Eff (alert::ALERT|e) Unit)
17-
18-
19-
alert :: forall e. String -> Maybe String -> Eff (alert::ALERT|e) Unit
16+
alert :: String -> Maybe String -> Effect Unit
2017
alert s ms = runFn4 alertImpl s (toNullable ms) [] {}
2118

22-
foreign import keyboardDismiss :: forall eff. Eff eff Unit
19+
foreign import keyboardDismiss :: Effect Unit
2320

24-
foreign import data REGISTER :: Effect
25-
foreign import registerComponent :: forall e props. String -> ReactClass props -> Eff (register::REGISTER|e) Unit
21+
foreign import registerComponent :: forall props. String -> ReactClass props -> Effect Unit

src/ReactNative/Android/API.purs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module ReactNative.Android.API where
22

33
import Prelude
4-
import Control.Monad.Eff (Eff)
5-
import Control.Monad.Eff.Uncurried (EffFn1, EffFn2, runEffFn2)
4+
import Effect (Effect)
5+
import Effect.Uncurried (EffectFn1, EffectFn2, runEffectFn2)
66

7-
foreign import backAndroidAddListener :: forall eff. EffFn2 eff String (EffFn1 eff Unit Boolean) Unit
8-
foreign import exitApp :: forall eff. Int -> Eff eff Unit
7+
foreign import backAndroidAddListener :: EffectFn2 String (EffectFn1 Unit Boolean) Unit
8+
foreign import exitApp :: Int -> Effect Unit
99

10-
addBackEventCallback :: forall eff. EffFn1 eff Unit Boolean -> Eff eff Unit
11-
addBackEventCallback = runEffFn2 backAndroidAddListener "hardwareBackPress"
10+
addBackEventCallback :: EffectFn1 Unit Boolean -> Effect Unit
11+
addBackEventCallback = runEffectFn2 backAndroidAddListener "hardwareBackPress"

src/ReactNative/Android/Components.purs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module ReactNative.Android.Components (
1313
) where
1414

1515
import Prelude
16-
import Control.Monad.Eff (Eff)
16+
import Effect (Effect)
1717
import Data.Maybe (Maybe(..))
1818
import ReactNative.Optional (class Optional)
1919
import React (ReactElement, ReactThis)
@@ -25,11 +25,11 @@ import ReactNative.PropTypes.Color (Color)
2525
import ReactNative.Unsafe.ApplyProps (unsafeApplyProps)
2626
import ReactNative.Unsafe.Components (drawerLayoutAndroidU, toolbarAndroidU)
2727

28-
type ToolbarAndroidPropO eff = ViewPropsEx eff (
28+
type ToolbarAndroidPropO = ViewPropsEx (
2929
actions :: Array ToolbarAction
3030
, navIcon :: ImageSource
31-
, onIconClicked :: UnitEventHandler eff
32-
, onActionSelected :: EventHandler eff Int
31+
, onIconClicked :: UnitEventHandler
32+
, onActionSelected :: EventHandler Int
3333
, title :: String
3434
, titleColor :: Color
3535
, contentInsetEnd :: Int
@@ -42,8 +42,8 @@ type ToolbarAndroidPropO eff = ViewPropsEx eff (
4242
) () ()
4343

4444
-- | Create a [ToolbarAndroid](https://facebook.github.io/react-native/docs/toolbarandroid.html) component
45-
toolbarAndroid' :: forall eff o
46-
. Optional o (ToolbarAndroidPropO eff)
45+
toolbarAndroid' :: forall o
46+
. Optional o ToolbarAndroidPropO
4747
=> {|o} -> Array ReactElement -> ReactElement
4848
toolbarAndroid' = toolbarAndroidU <<< unsafeApplyProps
4949

@@ -108,27 +108,27 @@ type DrawerLayoutProps o = {
108108
| o
109109
}
110110

111-
type DrawerLayoutPropsO eff = (
111+
type DrawerLayoutPropsO = (
112112
ref :: RefType DrawerLayoutRef
113113
, drawerBackgroundColor :: Color
114114
, drawerLockMode :: DrawerLockMode
115115
, keyboardDismissMode :: DrawerKeyboardDismissMode
116-
, onDrawerClose :: EventHandler eff Unit
117-
, onDrawerOpen :: EventHandler eff Unit
118-
, onDrawerSlide :: EventHandler eff Unit
119-
, onDrawerStateChanged :: EventHandler eff Unit
116+
, onDrawerClose :: EventHandler Unit
117+
, onDrawerOpen :: EventHandler Unit
118+
, onDrawerSlide :: EventHandler Unit
119+
, onDrawerStateChanged :: EventHandler Unit
120120
, statusBarBackgroundColor :: Color
121121
)
122122

123123
newtype DrawerLayoutRef = DrawerLayoutRef (forall p s. ReactThis p s)
124124

125125
-- | Create a [DrawerLayoutAndroid](https://facebook.github.io/react-native/docs/drawerlayoutandroid.html) component
126-
drawerLayoutAndroid' :: forall eff o
127-
. Optional o (DrawerLayoutPropsO eff)
126+
drawerLayoutAndroid' :: forall o
127+
. Optional o DrawerLayoutPropsO
128128
=> DrawerLayoutProps o
129129
-> Array ReactElement
130130
-> ReactElement
131131
drawerLayoutAndroid' = drawerLayoutAndroidU <<< unsafeApplyProps
132132

133-
foreign import openDrawer :: forall eff. DrawerLayoutRef -> Eff eff Unit
134-
foreign import closeDrawer :: forall eff. DrawerLayoutRef -> Eff eff Unit
133+
foreign import openDrawer :: DrawerLayoutRef -> Effect Unit
134+
foreign import closeDrawer :: DrawerLayoutRef -> Effect Unit

src/ReactNative/Components/ActivityIndicator.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type ActivityIndicatorProps r = {
2020
| r
2121
}
2222

23-
type ActivityIndicatorPropsO eff = ViewPropsEx eff (
23+
type ActivityIndicatorPropsO = ViewPropsEx (
2424
color :: Color
2525
, size :: ActivityIndicatorSize
2626
) () (
@@ -32,8 +32,8 @@ activityIndicator :: Boolean -> ReactElement
3232
activityIndicator animating = activityIndicatorU {animating}
3333

3434
-- | Create an ActivityIndicator with props and the `animating` flag
35-
activityIndicator' :: forall eff o
36-
. Optional o (ActivityIndicatorPropsO eff)
35+
activityIndicator' :: forall o
36+
. Optional o ActivityIndicatorPropsO
3737
=> ActivityIndicatorProps o -> ReactElement
3838
activityIndicator' = activityIndicatorU <<< unsafeApplyProps
3939

src/ReactNative/Components/Button.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ import ReactNative.Unsafe.ApplyProps (unsafeApplyProps)
1111
import ReactNative.Unsafe.Components (buttonU)
1212
import Prelude
1313

14-
type ButtonPropsO eff = (
14+
type ButtonPropsO = (
1515
accessibilityLabel :: String
1616
, color :: Color
1717
, disabled :: Boolean
18-
, onPress :: EventHandler eff TouchEvent
18+
, onPress :: EventHandler TouchEvent
1919
, title :: String
2020
)
2121

2222
-- | Create a button with the given `title` and `onPress` handler
23-
button :: forall eff. String -> EventHandler eff TouchEvent -> ReactElement
23+
button :: String -> EventHandler TouchEvent -> ReactElement
2424
button title onPress = buttonU {title, onPress}
2525

2626
-- | Create a button with the given `title`
2727
button_ :: String -> ReactElement
2828
button_ title = buttonU {title}
2929

3030
-- | Create a button with the given props and `title`
31-
button' :: forall o eff. Optional o (ButtonPropsO eff) => {|o} -> ReactElement
31+
button' :: forall o. Optional o ButtonPropsO => {|o} -> ReactElement
3232
button' = buttonU <<< unsafeApplyProps

src/ReactNative/Components/Image.purs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ type ImageProps r = {
1919
| r
2020
}
2121

22-
type ImagePropsO eff = BaseProps (
22+
type ImagePropsO = BaseProps (
2323
style :: Styles
24-
, onError :: UnitEventHandler eff
25-
, onLayout :: EventHandler eff LayoutEvent
26-
, onLoad :: UnitEventHandler eff
27-
, onLoadEnd :: UnitEventHandler eff
28-
, onLoadStart :: UnitEventHandler eff
24+
, onError :: UnitEventHandler
25+
, onLayout :: EventHandler LayoutEvent
26+
, onLoad :: UnitEventHandler
27+
, onLoadEnd :: UnitEventHandler
28+
, onLoadStart :: UnitEventHandler
2929
, resizeMode :: ResizeMode
3030
, android :: {
3131
resizeMethod :: ResizeMethod
@@ -36,8 +36,8 @@ type ImagePropsO eff = BaseProps (
3636
, blurRadius :: Number
3737
, capInsets :: {top::Number, left::Number, bottom::Number, right::Number}
3838
, defaultSource :: ImageSource
39-
, onPartialLoad :: UnitEventHandler eff
40-
, onProgress :: EventHandler eff ImageProgressEvent
39+
, onPartialLoad :: UnitEventHandler
40+
, onProgress :: EventHandler ImageProgressEvent
4141
}
4242
)
4343

@@ -50,8 +50,8 @@ backgroundImage style source = imageU {style, source}
5050
-- | Create a background image with props and source
5151
-- |
5252
-- | Background images are simply normal images with children overalayed ontop
53-
backgroundImage' :: forall eff o
54-
. Optional o (ImagePropsO eff)
53+
backgroundImage' :: forall o
54+
. Optional o ImagePropsO
5555
=> ImageProps o -> Array ReactElement -> ReactElement
5656
backgroundImage' = imageU <<< unsafeApplyProps
5757

@@ -64,8 +64,8 @@ image :: Styles -> ImageSource -> ReactElement
6464
image style source = imageU {style, source} []
6565

6666
-- | Create an Image with props and source
67-
image' :: forall eff o
68-
. Optional o (ImagePropsO eff)
67+
image' :: forall o
68+
. Optional o ImagePropsO
6969
=> ImageProps o -> ReactElement
7070
image' p = imageU (unsafeApplyProps p) []
7171

src/ReactNative/Components/ListView.purs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ module ReactNative.Components.ListView (
1313
) where
1414

1515
import Prelude
16-
import Control.Monad.Eff.Uncurried (EffFn2)
16+
import Effect.Uncurried (EffectFn2)
1717
import Data.Function.Uncurried (Fn2, Fn3, Fn4, mkFn2, mkFn4, runFn3, runFn4)
1818
import Data.Maybe (Maybe(..))
1919
import Data.Nullable (Nullable, toNullable)
20+
import Foreign.Object (Object)
2021
import ReactNative.Optional (class Optional)
21-
import Data.StrMap (StrMap)
2222
import React (ReactElement)
2323
import ReactNative.Components.ScrollView (ScrollViewPropsEx)
2424
import ReactNative.Events (EventHandler, EventHandler2, ScrollEvent)
@@ -37,11 +37,11 @@ type ListViewProps a section blob r = {
3737
| r
3838
}
3939

40-
type ListViewPropsO section eff = ScrollViewPropsEx eff (
40+
type ListViewPropsO section = ScrollViewPropsEx (
4141
enableEmptySections :: Boolean
4242
, initialListSize :: Int
43-
, onChangeVisibleRows :: EventHandler2 eff RowMap RowMap
44-
, onEndReached :: EventHandler eff (Nullable ScrollEvent)
43+
, onChangeVisibleRows :: EventHandler2 RowMap RowMap
44+
, onEndReached :: EventHandler (Nullable ScrollEvent)
4545
, onEndReachedThreshold :: Int
4646
, pageSize :: Int
4747
, renderFooter :: Unit -> ReactElement
@@ -57,8 +57,8 @@ listView :: forall blob a section. ListViewDataSource' blob a section -> (a -> R
5757
listView dataSource rf = listViewU {dataSource,renderRow:rowRenderer rf,enableEmptySections:true}
5858

5959
-- | Create a list view with props, a data source and a row renderer
60-
listView' :: forall o blob a section eff
61-
. Optional o (ListViewPropsO section eff)
60+
listView' :: forall o blob a section
61+
. Optional o (ListViewPropsO section)
6262
=> ListViewProps a section blob o
6363
-> ReactElement
6464
listView' = listViewU <<< unsafeApplyProps
@@ -97,8 +97,8 @@ class DataSourceRowCloneable blob a | blob -> a
9797
class DataSourceSectionCloneable blob a section | blob -> a, blob -> section
9898

9999
instance arrayRowCloneable :: DataSourceRowCloneable (Array a) a
100-
instance strMapMapCloneable :: DataSourceSectionCloneable (StrMap (StrMap a)) a (StrMap a)
101-
instance strMapArrayCloneable :: DataSourceSectionCloneable (StrMap (Array a)) a (Array a)
100+
instance strMapMapCloneable :: DataSourceSectionCloneable (Object (Object a)) a (Object a)
101+
instance strMapArrayCloneable :: DataSourceSectionCloneable (Object (Array a)) a (Array a)
102102
instance arrayArrayCloneable :: DataSourceSectionCloneable (Array (Array a)) a (Array a)
103103

104104
cloneWithRowsAndSections :: forall blob a section. DataSourceSectionCloneable blob a section => ListViewDataSource' blob a section -> blob -> ListViewDataSource' blob a section
@@ -135,7 +135,7 @@ foreign import data SectionRenderer :: Type -> Type
135135
rowRenderer :: forall a. (a -> ReactElement) -> RowRenderer a
136136
rowRenderer = unsafeCoerce
137137

138-
rowRenderer' :: forall a eff. (a -> SectionId -> RowId -> EffFn2 eff SectionId RowId Unit -> ReactElement) -> RowRenderer a
138+
rowRenderer' :: forall a. (a -> SectionId -> RowId -> EffectFn2 SectionId RowId Unit -> ReactElement) -> RowRenderer a
139139
rowRenderer' = unsafeCoerce <<< mkFn4
140140

141141
sectionRenderer :: forall section. (section -> ReactElement) -> SectionRenderer section
@@ -144,4 +144,4 @@ sectionRenderer = unsafeCoerce
144144
sectionRenderer' :: forall section. (section -> SectionId -> ReactElement) -> SectionRenderer section
145145
sectionRenderer' = unsafeCoerce <<< mkFn2
146146

147-
type RowMap = StrMap (StrMap Boolean)
147+
type RowMap = Object (Object Boolean)

src/ReactNative/Components/Modal.purs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,37 @@ orientationType = {
3737
, landscape: Orientation "landscape"
3838
}
3939

40-
type OnRequestClose eff = UnitEventHandler eff
40+
type OnRequestClose = UnitEventHandler
4141

42-
type ModalPropsO a eff = (
42+
type ModalPropsO a = (
4343
animationType :: AnimationType
44-
, onShow :: UnitEventHandler eff
44+
, onShow :: UnitEventHandler
4545
, transparent :: Boolean
4646
, visible :: Boolean
4747
, android :: {
4848
hardwareAccelerated :: Boolean
49-
, onRequestClose :: OnRequestClose eff
49+
, onRequestClose :: OnRequestClose
5050
}
5151
, ios :: {
52-
onOrientationChange :: EventHandler eff Orientation
52+
onOrientationChange :: EventHandler Orientation
5353
, supportedOrientations :: Array Orientation
5454
}
5555
)
5656

57-
modal' :: forall a eff o
58-
. Optional o (ModalPropsO a eff)
57+
modal' :: forall a o
58+
. Optional o (ModalPropsO a)
5959
=> {|o} -> Array ReactElement -> ReactElement
6060
modal' = modalU <<< unsafeApplyProps
6161

6262
-- On request is required *for android*. Least nasty solution is to require it, and provide a default for iOS
6363
-- https://github.com/facebook/react-native/commit/ce81f8b35af8d273072583d369594d4f5fd6d696
64-
modal_ :: forall eff. OnRequestClose eff -> Array ReactElement -> ReactElement
64+
modal_ :: OnRequestClose -> Array ReactElement -> ReactElement
6565
modal_ orc = modalU {onRequestClose: orc}
6666

6767
modalIOS_ :: Array ReactElement -> ReactElement
6868
modalIOS_ = modalU {}
6969

70-
modal :: forall eff. Boolean -> AnimationType -> OnRequestClose eff -> Array ReactElement -> ReactElement
70+
modal :: Boolean -> AnimationType -> OnRequestClose -> Array ReactElement -> ReactElement
7171
modal v at orc = modalU {visible: v, animationType: at, onRequestClose: orc}
7272

7373
modalIOS :: Boolean -> AnimationType -> Array ReactElement -> ReactElement

0 commit comments

Comments
 (0)