Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit f7b786d

Browse files
authored
Merge pull request #67 from purescript-contrib/nullable-datatransfer-files
Handle cases where DataTransfer has a null +files+ slot
2 parents 26f7e54 + 34f83d9 commit f7b786d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/DOM/HTML/Event/DragEvent/DataTransfer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
exports.files = function (dataTransfer) {
3+
exports.filesNullable = function (dataTransfer) {
44
return dataTransfer.files;
55
};
66

src/DOM/HTML/Event/DragEvent/DataTransfer.purs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
module DOM.HTML.Event.DragEvent.DataTransfer
22
( DataTransfer
33
, files
4+
, filesNullable
45
, types
56
) where
67

8+
import Prelude
79
import DOM.File.Types (FileList)
10+
import Data.Maybe (Maybe)
11+
import Data.Nullable (Nullable, toMaybe)
812

913
foreign import data DataTransfer :: *
1014

1115
-- | Contains a list of all the local files available on the data transfer.
1216
-- | Empty if the drag operation doesn't involve dragging files.
13-
foreign import files :: DataTransfer -> FileList
17+
-- |
18+
-- | It's possible that a drag operation may have null files, instead of an
19+
-- | empty file list. In these cases Nothing is returned.
20+
files :: DataTransfer -> Maybe FileList
21+
files = toMaybe <$> filesNullable
22+
23+
foreign import filesNullable :: DataTransfer -> Nullable FileList
1424

1525
-- | Returns an array of data formats used in the drag operation.
1626
-- | If the drag operation included no data, then the array is empty.

0 commit comments

Comments
 (0)