Skip to content

Commit 09dbbcc

Browse files
committed
eslint code
1 parent be8d6de commit 09dbbcc

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
22

3-
var Battery = require('./libs/battery.js');
3+
const Battery = require('./libs/battery.js');
44

55
module.exports = Battery;

libs/battery.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@
2323
* This class contains information about the current battery status.
2424
* @constructor
2525
*/
26-
var exec = require('@remobile/react-native-cordova').exec;
26+
const exec = require('@remobile/react-native-cordova').exec;
27+
const { NativeEventEmitter, DeviceEventEmitter, Platform, NativeModules } = require('react-native');
28+
const EventEmitter = Platform.OS === 'android' ? DeviceEventEmitter : new NativeEventEmitter(NativeModules.FileTransfer);
2729

28-
var STATUS_CRITICAL = 5;
29-
var STATUS_LOW = 20;
30-
var subscription = null;
30+
const STATUS_CRITICAL = 5;
31+
const STATUS_LOW = 20;
32+
let subscription = null;
3133

32-
exports.register = function(options) {
33-
var _level = null;
34-
var _isPlugged = null;
35-
const {onBatteryStatus, onBatteryLow, onBatteryCritical} = options;
36-
if (onBatteryStatus||onBatteryLow||onBatteryCritical) {
37-
subscription = EventEmitter.addListener('BATTERY_STATUS_EVENT', (info)=>{
34+
exports.register = function (options) {
35+
let _level = null;
36+
let _isPlugged = null;
37+
const { onBatteryStatus, onBatteryLow, onBatteryCritical } = options;
38+
if (onBatteryStatus || onBatteryLow || onBatteryCritical) {
39+
subscription = EventEmitter.addListener('BATTERY_STATUS_EVENT', (info) => {
3840
if (info) {
3941
if (_level !== info.level || _isPlugged !== info.isPlugged) {
40-
41-
if(info.level === null && _level !== null) {
42+
if (info.level === null && _level !== null) {
4243
return; // special case where callback is called because we stopped listening to the native side.
4344
}
4445

@@ -51,8 +52,7 @@ exports.register = function(options) {
5152
if (_level > STATUS_CRITICAL && info.level <= STATUS_CRITICAL) {
5253
// Fire critical battery event
5354
onBatteryCritical && onBatteryCritical(info);
54-
}
55-
else if (_level > STATUS_LOW && info.level <= STATUS_LOW) {
55+
} else if (_level > STATUS_LOW && info.level <= STATUS_LOW) {
5656
// Fire low battery event
5757
onBatteryCritical && onBatteryCritical(info);
5858
}
@@ -63,10 +63,10 @@ exports.register = function(options) {
6363
}
6464
});
6565
}
66-
exec(null, null, "BatteryStatus", "start", []);
66+
exec(null, null, 'BatteryStatus', 'start', []);
6767
};
6868

69-
exports.unregister = function(opt) {
69+
exports.unregister = function (opt) {
7070
subscription && subscription.remove();
71-
exec(null, null, "BatteryStatus", "stop", []);
71+
exec(null, null, 'BatteryStatus', 'stop', []);
7272
};

0 commit comments

Comments
 (0)