format js code with eslint

This commit is contained in:
Kesha Antonov
2021-12-05 21:27:10 +03:00
parent 2ededc9694
commit d157726679
10 changed files with 4404 additions and 2164 deletions
+51 -56
View File
@@ -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)
}
}