Skip to content

Commit 2b83541

Browse files
authored
Remove unnecessary Unsafe.Coerce usage (#276)
* Remove toDragEvent implementation * Bump parcel, react versions
1 parent ed4b2c6 commit 2b83541

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"license": "MIT",
33
"devDependencies": {
4-
"parcel": "^1.12.4",
4+
"parcel-bundler": "^1.12.5",
55
"purescript": "^0.13.8",
66
"spago": "^0.16.0"
77
},
88
"dependencies": {
99
"ace-builds": "^1.4.11",
1010
"big-integer": "^1.6.48",
11-
"react": "^16.13.1",
12-
"react-dom": "^16.13.1",
11+
"react": "^16.14.0",
12+
"react-dom": "^16.14.0",
1313
"xhr2": "^0.2.0"
1414
}
1515
}

recipes/DragAndDropReactHooks/src/Main.purs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ import Effect (Effect)
88
import Effect.Exception as Exception
99
import React.Basic.DOM as R
1010
import React.Basic.DOM.Events as DOM.Events
11-
import React.Basic.Events (SyntheticEvent)
1211
import React.Basic.Events as Events
1312
import React.Basic.Hooks (Component, (/\))
1413
import React.Basic.Hooks as React
15-
import Unsafe.Coerce as Coerce
1614
import Web.File.File as File
1715
import Web.File.FileList as FileList
1816
import Web.HTML as HTML
1917
import Web.HTML.Event.DataTransfer as DataTransfer
20-
import Web.HTML.Event.DragEvent (DragEvent)
2118
import Web.HTML.Event.DragEvent as DragEvent
2219
import Web.HTML.HTMLDocument as HTMLDocument
2320
import Web.HTML.HTMLElement as HTMLElement
@@ -71,10 +68,10 @@ mkApp = do
7168
Events.handler DOM.Events.preventDefault \_ -> do
7269
setHover true
7370
, onDrop:
74-
Events.handler DOM.Events.preventDefault \e -> do
71+
Events.handler (DOM.Events.preventDefault >>> DOM.Events.nativeEvent) \e -> do
7572
setHover false
7673
let
77-
maybeFileList = DataTransfer.files (DragEvent.dataTransfer (toDragEvent e))
74+
maybeFileList = DataTransfer.files =<< DragEvent.dataTransfer <$> DragEvent.fromEvent e
7875
Foldable.for_ (FileList.items <$> maybeFileList) (setFiles <<< (<>))
7976
, children:
8077
[ R.button
@@ -109,16 +106,3 @@ mkApp = do
109106
}
110107
]
111108
}
112-
113-
-- | We happen to know that we're dealing with a `DragEvent` where we're using this, but
114-
-- | not every `SyntheticEvent` can be converted to a `DragEvent`, so this is a partial
115-
-- | function. A proper implementation of this would probably be typed
116-
-- |
117-
-- | ```purs
118-
-- | toDragEvent :: SyntheticEvent -> Maybe DragEvent
119-
-- | ```
120-
-- |
121-
-- | and could use `Web.Internal.FFI.unsafeReadProtoTagged` to inspect the constructor
122-
-- | of the event and verify that it is indeed a `DragEvent`.
123-
toDragEvent :: SyntheticEvent -> DragEvent
124-
toDragEvent = Coerce.unsafeCoerce

0 commit comments

Comments
 (0)