Skip to content

Commit

Permalink
Merge pull request #99 from hawkup/fix-background-timeout
Browse files Browse the repository at this point in the history
Fixed cannot call static method and setTimeout not call from class
  • Loading branch information
ocetnik authored Aug 20, 2018
2 parents f7394c1 + 01709fa commit bdbf544
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = {
"extends": "airbnb"
"extends": "airbnb",
"rules": {
"class-methods-use-this": ["error", { "exceptMethods": ["start", "stop"] }]
}
};
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class BackgroundTimer {
}

// Original API
static start(delay = 0) {
start(delay = 0) {
return RNBackgroundTimer.start(delay);
}

static stop() {
stop() {
return RNBackgroundTimer.stop();
}

static runBackgroundTimer(callback, delay) {
runBackgroundTimer(callback, delay) {
const EventEmitter = Platform.select({
ios: () => NativeAppEventEmitter,
android: () => DeviceEventEmitter,
Expand All @@ -49,21 +49,21 @@ class BackgroundTimer {
});
}

static backgroundClockMethod(callback, delay) {
this.backgroundTimer = setTimeout(() => {
backgroundClockMethod(callback, delay) {
this.backgroundTimer = this.setTimeout(() => {
callback();
this.backgroundClockMethod(callback, delay);
},
delay);
}

static stopBackgroundTimer() {
stopBackgroundTimer() {
this.stop();
clearTimeout(this.backgroundTimer);
}

// New API, allowing for multiple timers
static setTimeout(callback, timeout) {
setTimeout(callback, timeout) {
this.uniqueId += 1;
const timeoutId = this.uniqueId;
this.callbacks[timeoutId] = {
Expand All @@ -75,14 +75,14 @@ class BackgroundTimer {
return timeoutId;
}

static clearTimeout(timeoutId) {
clearTimeout(timeoutId) {
if (this.callbacks[timeoutId]) {
delete this.callbacks[timeoutId];
// RNBackgroundTimer.clearTimeout(timeoutId);
}
}

static setInterval(callback, timeout) {
setInterval(callback, timeout) {
this.uniqueId += 1;
const intervalId = this.uniqueId;
this.callbacks[intervalId] = {
Expand All @@ -94,7 +94,7 @@ class BackgroundTimer {
return intervalId;
}

static clearInterval(intervalId) {
clearInterval(intervalId) {
if (this.callbacks[intervalId]) {
delete this.callbacks[intervalId];
// RNBackgroundTimer.clearTimeout(intervalId);
Expand Down

0 comments on commit bdbf544

Please sign in to comment.