mirror of
https://github.com/zoriya/react-native-background-downloader.git
synced 2026-06-09 20:25:39 +00:00
format js code with eslint
This commit is contained in:
+51
-56
@@ -1,10 +1,9 @@
|
||||
import { NativeModules } from 'react-native';
|
||||
const { RNBackgroundDownloader } = NativeModules;
|
||||
import { NativeModules } from 'react-native'
|
||||
const { RNBackgroundDownloader } = NativeModules
|
||||
|
||||
function validateHandler(handler) {
|
||||
if (!(typeof handler === 'function')) {
|
||||
throw new TypeError(`[RNBackgroundDownloader] expected argument to be a function, got: ${typeof handler}`);
|
||||
}
|
||||
function validateHandler (handler) {
|
||||
if (!(typeof handler === 'function'))
|
||||
throw new TypeError(`[RNBackgroundDownloader] expected argument to be a function, got: ${typeof handler}`)
|
||||
}
|
||||
export default class DownloadTask {
|
||||
state = 'PENDING'
|
||||
@@ -13,89 +12,85 @@ export default class DownloadTask {
|
||||
totalBytes = 0
|
||||
|
||||
constructor (taskInfo, originalTask) {
|
||||
if (typeof taskInfo === 'string') {
|
||||
this.id = taskInfo;
|
||||
} else {
|
||||
this.id = taskInfo.id;
|
||||
this.percent = taskInfo.percent;
|
||||
this.bytesWritten = taskInfo.bytesWritten;
|
||||
this.totalBytes = taskInfo.totalBytes;
|
||||
}
|
||||
if (typeof taskInfo === 'string') {
|
||||
this.id = taskInfo
|
||||
} else {
|
||||
this.id = taskInfo.id
|
||||
this.percent = taskInfo.percent
|
||||
this.bytesWritten = taskInfo.bytesWritten
|
||||
this.totalBytes = taskInfo.totalBytes
|
||||
}
|
||||
|
||||
if (originalTask) {
|
||||
this._beginHandler = originalTask._beginHandler
|
||||
this._progressHandler = originalTask._progressHandler
|
||||
this._doneHandler = originalTask._doneHandler
|
||||
this._errorHandler = originalTask._errorHandler
|
||||
}
|
||||
if (originalTask) {
|
||||
this._beginHandler = originalTask._beginHandler
|
||||
this._progressHandler = originalTask._progressHandler
|
||||
this._doneHandler = originalTask._doneHandler
|
||||
this._errorHandler = originalTask._errorHandler
|
||||
}
|
||||
}
|
||||
|
||||
begin (handler) {
|
||||
validateHandler(handler);
|
||||
this._beginHandler = handler;
|
||||
return this;
|
||||
validateHandler(handler)
|
||||
this._beginHandler = handler
|
||||
return this
|
||||
}
|
||||
|
||||
progress (handler) {
|
||||
validateHandler(handler);
|
||||
this._progressHandler = handler;
|
||||
return this;
|
||||
validateHandler(handler)
|
||||
this._progressHandler = handler
|
||||
return this
|
||||
}
|
||||
|
||||
done (handler) {
|
||||
validateHandler(handler);
|
||||
this._doneHandler = handler;
|
||||
return this;
|
||||
validateHandler(handler)
|
||||
this._doneHandler = handler
|
||||
return this
|
||||
}
|
||||
|
||||
error (handler) {
|
||||
validateHandler(handler);
|
||||
this._errorHandler = handler;
|
||||
return this;
|
||||
validateHandler(handler)
|
||||
this._errorHandler = handler
|
||||
return this
|
||||
}
|
||||
|
||||
_onBegin ({ expectedBytes, headers }) {
|
||||
this.state = 'DOWNLOADING';
|
||||
if (this._beginHandler) {
|
||||
this._beginHandler({ expectedBytes, headers });
|
||||
}
|
||||
this.state = 'DOWNLOADING'
|
||||
if (this._beginHandler)
|
||||
this._beginHandler({ expectedBytes, headers })
|
||||
}
|
||||
|
||||
_onProgress (percent, bytesWritten, totalBytes) {
|
||||
this.percent = percent;
|
||||
this.bytesWritten = bytesWritten;
|
||||
this.totalBytes = totalBytes;
|
||||
if (this._progressHandler) {
|
||||
this._progressHandler(percent, bytesWritten, totalBytes);
|
||||
}
|
||||
this.percent = percent
|
||||
this.bytesWritten = bytesWritten
|
||||
this.totalBytes = totalBytes
|
||||
if (this._progressHandler)
|
||||
this._progressHandler(percent, bytesWritten, totalBytes)
|
||||
}
|
||||
|
||||
_onDone ({ location }) {
|
||||
this.state = 'DONE';
|
||||
if (this._doneHandler) {
|
||||
this._doneHandler({ location });
|
||||
}
|
||||
this.state = 'DONE'
|
||||
if (this._doneHandler)
|
||||
this._doneHandler({ location })
|
||||
}
|
||||
|
||||
_onError (error, errorCode) {
|
||||
this.state = 'FAILED';
|
||||
if (this._errorHandler) {
|
||||
this._errorHandler(error, errorCode);
|
||||
}
|
||||
this.state = 'FAILED'
|
||||
if (this._errorHandler)
|
||||
this._errorHandler(error, errorCode)
|
||||
}
|
||||
|
||||
pause () {
|
||||
this.state = 'PAUSED';
|
||||
RNBackgroundDownloader.pauseTask(this.id);
|
||||
this.state = 'PAUSED'
|
||||
RNBackgroundDownloader.pauseTask(this.id)
|
||||
}
|
||||
|
||||
resume () {
|
||||
this.state = 'DOWNLOADING';
|
||||
RNBackgroundDownloader.resumeTask(this.id);
|
||||
this.state = 'DOWNLOADING'
|
||||
RNBackgroundDownloader.resumeTask(this.id)
|
||||
}
|
||||
|
||||
stop () {
|
||||
this.state = 'STOPPED';
|
||||
RNBackgroundDownloader.stopTask(this.id);
|
||||
this.state = 'STOPPED'
|
||||
RNBackgroundDownloader.stopTask(this.id)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user