Skip to content

Commit

Permalink
fix: remove redundant dataTransfer null check
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland Groza committed Apr 30, 2022
1 parent 41b8c3d commit 76a4033
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/file-selector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ it('should return an empty array if the passed arg is not what we expect', async
expect(files).toHaveLength(0);
});

it('should return an empty array if drag event', async () => {
const files = await fromEvent({});
expect(files).toHaveLength(0);
});

it('should return the evt {target} {files} if the passed event is an input evt', async () => {
const name = 'test.json';
const mockFile = createFile(name, {ping: true}, {
Expand Down
10 changes: 3 additions & 7 deletions src/file-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const FILES_TO_IGNORE = [
* @param evt
*/
export async function fromEvent(evt: Event | any): Promise<(FileWithPath | DataTransferItem)[]> {
if (isObject<DragEvent>(evt) && isDataTransfer(evt)) {
if (isObject<DragEvent>(evt) && isDataTransfer(evt.dataTransfer)) {
return getDataTransferFiles(evt.dataTransfer, evt.type);
} else if (isChangeEvt(evt)) {
return getInputFiles(evt);
Expand All @@ -30,7 +30,7 @@ export async function fromEvent(evt: Event | any): Promise<(FileWithPath | DataT
}

function isDataTransfer(value: any): value is DataTransfer {
return isObject(value.dataTransfer);
return isObject(value);
}

function isChangeEvt(value: any): value is Event {
Expand All @@ -52,11 +52,7 @@ async function getFsHandleFiles(handles: any[]) {
}


async function getDataTransferFiles(dt: DataTransfer | null, type: string) {
if (dt === null) {
return [];
}

async function getDataTransferFiles(dt: DataTransfer, type: string) {
// IE11 does not support dataTransfer.items
// See https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/items#Browser_compatibility
if (dt.items) {
Expand Down

0 comments on commit 76a4033

Please sign in to comment.