mirror of
https://github.com/zoriya/react-native-background-downloader.git
synced 2026-08-16 02:44:29 +00:00
some chages
This commit is contained in:
@@ -41,7 +41,7 @@ test('begin event', () => {
|
||||
});
|
||||
NativeEventEmitter.listeners.downloadBegin({
|
||||
id: 'testBegin',
|
||||
expctedBytes: 9001
|
||||
expectedBytes: 9001
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -159,17 +159,17 @@ test('wrong handler type', () => {
|
||||
|
||||
expect(() => {
|
||||
dt.begin('not function');
|
||||
}).toThrow('handler must be a function');
|
||||
}).toThrow();
|
||||
|
||||
expect(() => {
|
||||
dt.progress(7);
|
||||
}).toThrow('handler must be a function');
|
||||
}).toThrow();
|
||||
|
||||
expect(() => {
|
||||
dt.done({iamnota: 'function'});
|
||||
}).toThrow('handler must be a function');
|
||||
}).toThrow();
|
||||
|
||||
expect(() => {
|
||||
dt.error('not function');
|
||||
}).toThrow('handler must be a function');
|
||||
}).toThrow();
|
||||
});
|
||||
@@ -53,6 +53,7 @@ export function checkForExistingDownloads() {
|
||||
if (taskInfo.bytesWritten === taskInfo.totalBytes) {
|
||||
task.state = 'DONE';
|
||||
} else {
|
||||
// IOS completed the download but it was not done.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-12
@@ -1,6 +1,11 @@
|
||||
import { NativeModules } from 'react-native';
|
||||
const { RNBackgroundDownload } = NativeModules;
|
||||
|
||||
function validateHandler(handler) {
|
||||
if (!(typeof handler === 'function')) {
|
||||
throw new TypeError(`[RNBackgroundDownload] expected argument to be a function, got: ${typeof handler}`);
|
||||
}
|
||||
}
|
||||
export default class DownloadTask {
|
||||
state = 'PENDING'
|
||||
percent = 0
|
||||
@@ -19,33 +24,25 @@ export default class DownloadTask {
|
||||
}
|
||||
|
||||
begin(handler) {
|
||||
if (!(typeof handler === 'function')) {
|
||||
throw new TypeError('handler must be a function');
|
||||
}
|
||||
validateHandler(handler);
|
||||
this._beginHandler = handler;
|
||||
return this;
|
||||
}
|
||||
|
||||
progress(handler) {
|
||||
if (!(typeof handler === 'function')) {
|
||||
throw new TypeError('handler must be a function');
|
||||
}
|
||||
validateHandler(handler);
|
||||
this._progressHandler = handler;
|
||||
return this;
|
||||
}
|
||||
|
||||
done(handler) {
|
||||
if (!(typeof handler === 'function')) {
|
||||
throw new TypeError('handler must be a function');
|
||||
}
|
||||
validateHandler(handler);
|
||||
this._doneHandler = handler;
|
||||
return this;
|
||||
}
|
||||
|
||||
error(handler) {
|
||||
if (!(typeof handler === 'function')) {
|
||||
throw new TypeError('handler must be a function');
|
||||
}
|
||||
validateHandler(handler);
|
||||
this._errorHandler = handler;
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user