Skip to content

Commit 84c451c

Browse files
committed
fix event listener add/remove by using same reference to bound function
1 parent 1ae72ed commit 84c451c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class StaticServer {
5454

5555
this.started = false;
5656
this._origin = undefined;
57+
this._handleAppStateChangeFn = this._handleAppStateChange.bind(this);
5758
}
5859

5960
start() {
@@ -65,7 +66,7 @@ class StaticServer {
6566
this.running = true;
6667

6768
if (!this.keepAlive && (Platform.OS === 'android')) {
68-
AppState.addEventListener('change', this._handleAppStateChange.bind(this));
69+
AppState.addEventListener('change', this._handleAppStateChangeFn);
6970
}
7071

7172
return FPStaticServer.start(this.port, this.root, this.localOnly, this.keepAlive)
@@ -85,7 +86,7 @@ class StaticServer {
8586
this.stop();
8687
this.started = false;
8788
this._origin = undefined;
88-
AppState.removeEventListener('change', this._handleAppStateChange.bind(this));
89+
AppState.removeEventListener('change', this._handleAppStateChangeFn);
8990
}
9091

9192
_handleAppStateChange(appState) {

0 commit comments

Comments
 (0)