Skip to content

Commit 4002ed9

Browse files
committed
minor changes
1 parent c16eadd commit 4002ed9

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

packages/remote-config/src/client/eventEmitter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { assert } from '@firebase/util';
1919

20+
// TODO: Consolidate the Visibility monitoring API code into a shared utility function in firebase/util to be used by both packages/database and packages/remote-config.
2021
/**
2122
* Base class to be used if you want to emit events. Call the constructor with
2223
* the set of allowed event names.
@@ -65,6 +66,7 @@ export abstract class EventEmitter {
6566

6667
const eventData = this.getInitialEvent(eventType);
6768
if (eventData) {
69+
//@ts-ignore
6870
callback.apply(context, eventData);
6971
}
7072
}
@@ -92,4 +94,3 @@ export abstract class EventEmitter {
9294
);
9395
}
9496
}
95-

packages/remote-config/src/client/realtime_handler.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -323,23 +323,13 @@ export class RealtimeHandler {
323323
await this.beginRealtime();
324324
}
325325

326-
private abortRealtimeConnection(): void {
327-
if (this.controller) {
328-
this.controller.abort();
329-
this.controller = undefined;
330-
this.isConnectionActive = false;
331-
}
332-
}
333-
334-
private onVisibilityChange(visible: unknown) {
335-
const wasInBackground = this.isInBackground;
326+
private async onVisibilityChange(visible: unknown) {
336327
this.isInBackground = !visible;
337-
if (wasInBackground !== this.isInBackground) {
338-
if (this.isInBackground) {
339-
this.abortRealtimeConnection();
340-
} else {
341-
this.beginRealtime();
342-
}
328+
if (!visible && this.controller) {
329+
this.controller.abort();
330+
this.controller = undefined;
331+
} else if(visible) {
332+
await this.beginRealtime();
343333
}
344334
}
345335
}

packages/remote-config/src/client/visibility_monitor.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { EventEmitter } from './eventEmitter';
2121

2222
declare const document: Document;
2323

24+
// TODO: Consolidate the Visibility monitoring API code into a shared utility function in firebase/util to be used by both packages/database and packages/remote-config.
2425
export class VisibilityMonitor extends EventEmitter {
2526
private visible_: boolean;
2627

@@ -40,13 +41,16 @@ export class VisibilityMonitor extends EventEmitter {
4041
// Opera 12.10 and Firefox 18 and later support
4142
visibilityChange = 'visibilitychange';
4243
hidden = 'hidden';
43-
} else if (typeof document['mozHidden'] !== 'undefined') {
44+
} //@ts-ignore
45+
else if (typeof document['mozHidden'] !== 'undefined') {
4446
visibilityChange = 'mozvisibilitychange';
4547
hidden = 'mozHidden';
46-
} else if (typeof document['msHidden'] !== 'undefined') {
48+
} //@ts-ignore
49+
else if (typeof document['msHidden'] !== 'undefined') {
4750
visibilityChange = 'msvisibilitychange';
4851
hidden = 'msHidden';
49-
} else if (typeof document['webkitHidden'] !== 'undefined') {
52+
} //@ts-ignore
53+
else if (typeof document['webkitHidden'] !== 'undefined') {
5054
visibilityChange = 'webkitvisibilitychange';
5155
hidden = 'webkitHidden';
5256
}
@@ -58,10 +62,12 @@ export class VisibilityMonitor extends EventEmitter {
5862
// reconnects
5963
this.visible_ = true;
6064

65+
//@ts-ignore
6166
if (visibilityChange) {
6267
document.addEventListener(
6368
visibilityChange,
6469
() => {
70+
//@ts-ignore
6571
const visible = !document[hidden];
6672
if (visible !== this.visible_) {
6773
this.visible_ = visible;
@@ -78,4 +84,3 @@ export class VisibilityMonitor extends EventEmitter {
7884
return [this.visible_];
7985
}
8086
}
81-

packages/remote-config/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"extends": "../../config/tsconfig.base.json",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"resolveJsonModule": true,
6-
"strict": false
5+
"resolveJsonModule": true
76
},
87
"exclude": ["dist/**/*"]
98
}

0 commit comments

Comments
 (0)