Skip to content

Commit 6105412

Browse files
committed
resolving the spacing problem
1 parent 52686fc commit 6105412

File tree

3 files changed

+43
-23
lines changed

3 files changed

+43
-23
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export abstract class EventEmitter {
4848
/**
4949
* To be called by derived classes to trigger events.
5050
*/
51-
protected trigger(eventType: string, ...varArgs: unknown[]) {
51+
protected trigger(eventType: string, ...varArgs: unknown[]): void {
5252
if (Array.isArray(this.listeners_[eventType])) {
5353
// Clone the list, since callbacks could add/remove listeners.
5454
const listeners = [...this.listeners_[eventType]];
@@ -59,7 +59,11 @@ export abstract class EventEmitter {
5959
}
6060
}
6161

62-
on(eventType: string, callback: (a: unknown) => void, context: unknown) {
62+
on(
63+
eventType: string,
64+
callback: (a: unknown) => void,
65+
context: unknown
66+
): void {
6367
this.validateEventType_(eventType);
6468
this.listeners_[eventType] = this.listeners_[eventType] || [];
6569
this.listeners_[eventType].push({ callback, context });
@@ -71,7 +75,11 @@ export abstract class EventEmitter {
7175
}
7276
}
7377

74-
off(eventType: string, callback: (a: unknown) => void, context: unknown) {
78+
off(
79+
eventType: string,
80+
callback: (a: unknown) => void,
81+
context: unknown
82+
): void {
7583
this.validateEventType_(eventType);
7684
const listeners = this.listeners_[eventType] || [];
7785
for (let i = 0; i < listeners.length; i++) {
@@ -85,7 +93,7 @@ export abstract class EventEmitter {
8593
}
8694
}
8795

88-
private validateEventType_(eventType: string) {
96+
private validateEventType_(eventType: string): void {
8997
assert(
9098
this.allowedEvents_.find(et => {
9199
return et === eventType;

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ export class RealtimeHandler {
4141
private readonly logger: Logger
4242
) {
4343
void this.setRetriesRemaining();
44-
VisibilityMonitor.getInstance().on('visible', this.onVisibilityChange, this);
44+
void VisibilityMonitor.getInstance().on(
45+
'visible',
46+
this.onVisibilityChange,
47+
this
48+
);
4549
}
4650

4751
private observers: Set<ConfigUpdateObserver> =
@@ -106,8 +110,8 @@ export class RealtimeHandler {
106110
*/
107111
private closeRealtimeHttpConnection(): void {
108112
if (this.controller && !this.isInBackground) {
109-
this.controller.abort();
110-
this.controller = undefined;
113+
this.controller.abort();
114+
this.controller = undefined;
111115
}
112116

113117
if (this.reader) {
@@ -269,11 +273,11 @@ export class RealtimeHandler {
269273
// this as a success, even if we haven't read a 200 response code yet.
270274
this.resetRetryCount();
271275
} else {
272-
//there might have been a transient error so the client will retry the connection.
273-
this.logger.error(
274-
'Exception connecting to real-time RC backend. Retrying the connection...:',
275-
error
276-
);
276+
//there might have been a transient error so the client will retry the connection.
277+
this.logger.debug(
278+
'Exception connecting to real-time RC backend. Retrying the connection...:',
279+
error
280+
);
277281
}
278282
} finally {
279283
// Close HTTP connection and associated streams.
@@ -315,9 +319,14 @@ export class RealtimeHandler {
315319
const isNotDisabled = !this.isRealtimeDisabled;
316320
const isNoConnectionActive = !this.isConnectionActive;
317321
const inForeground = !this.isInBackground;
318-
return hasActiveListeners && isNotDisabled && isNoConnectionActive && inForeground;
322+
return (
323+
hasActiveListeners &&
324+
isNotDisabled &&
325+
isNoConnectionActive &&
326+
inForeground
327+
);
319328
}
320-
329+
321330
private async makeRealtimeHttpConnection(delayMillis: number): Promise<void> {
322331
if (!this.canEstablishStreamConnection()) {
323332
return;
@@ -328,7 +337,10 @@ export class RealtimeHandler {
328337
await this.beginRealtimeHttpStream();
329338
}, delayMillis);
330339
} else if (!this.isInBackground) {
331-
const error = ERROR_FACTORY.create(ErrorCode.CONFIG_UPDATE_STREAM_ERROR, { originalErrorMessage: 'Unable to connect to the server. Check your connection and try again.' });
340+
const error = ERROR_FACTORY.create(ErrorCode.CONFIG_UPDATE_STREAM_ERROR, {
341+
originalErrorMessage:
342+
'Unable to connect to the server. Check your connection and try again.'
343+
});
332344
this.propagateError(error);
333345
}
334346
}
@@ -358,12 +370,12 @@ export class RealtimeHandler {
358370
}
359371
}
360372

361-
private async onVisibilityChange(visible: unknown) {
373+
private async onVisibilityChange(visible: unknown): Promise<void> {
362374
this.isInBackground = !visible;
363375
if (!visible && this.controller) {
364376
this.controller.abort();
365377
this.controller = undefined;
366-
} else if(visible) {
378+
} else if (visible) {
367379
await this.beginRealtime();
368380
}
369381
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ declare const document: Document;
2525
export class VisibilityMonitor extends EventEmitter {
2626
private visible_: boolean;
2727

28-
static getInstance() {
28+
static getInstance(): VisibilityMonitor {
2929
return new VisibilityMonitor();
3030
}
3131

@@ -41,15 +41,15 @@ export class VisibilityMonitor extends EventEmitter {
4141
// Opera 12.10 and Firefox 18 and later support
4242
visibilityChange = 'visibilitychange';
4343
hidden = 'hidden';
44-
} //@ts-ignore
44+
} // @ts-ignore
4545
else if (typeof document['mozHidden'] !== 'undefined') {
4646
visibilityChange = 'mozvisibilitychange';
4747
hidden = 'mozHidden';
48-
} //@ts-ignore
48+
} // @ts-ignore
4949
else if (typeof document['msHidden'] !== 'undefined') {
5050
visibilityChange = 'msvisibilitychange';
5151
hidden = 'msHidden';
52-
} //@ts-ignore
52+
} // @ts-ignore
5353
else if (typeof document['webkitHidden'] !== 'undefined') {
5454
visibilityChange = 'webkitvisibilitychange';
5555
hidden = 'webkitHidden';
@@ -62,12 +62,12 @@ export class VisibilityMonitor extends EventEmitter {
6262
// reconnects
6363
this.visible_ = true;
6464

65-
//@ts-ignore
65+
// @ts-ignore
6666
if (visibilityChange) {
6767
document.addEventListener(
6868
visibilityChange,
6969
() => {
70-
//@ts-ignore
70+
// @ts-ignore
7171
const visible = !document[hidden];
7272
if (visible !== this.visible_) {
7373
this.visible_ = visible;

0 commit comments

Comments
 (0)