From 2d8b719ab0a5be648e5d29e6e228b4a538f9f64b Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Sun, 14 Nov 2021 15:55:42 +0530 Subject: [PATCH] Add void return types as well --- src/logging/IDBLogger.ts | 16 ++++++++-------- src/logging/LogItem.ts | 17 +++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/logging/IDBLogger.ts b/src/logging/IDBLogger.ts index 2ef5b551..4f6301ce 100644 --- a/src/logging/IDBLogger.ts +++ b/src/logging/IDBLogger.ts @@ -51,18 +51,18 @@ export class IDBLogger extends BaseLogger { this._flushInterval = this._platform.clock.createInterval(() => this._tryFlush(), flushInterval); } - dispose() { + dispose(): void { window.removeEventListener("pagehide", this, false); this._flushInterval.dispose(); } - handleEvent(evt: Event) { + handleEvent(evt: Event): void { if (evt.type === "pagehide") { this._finishAllAndFlush(); } } - async _tryFlush() { + async _tryFlush(): Promise { const db = await this._openDB(); try { const txn = db.transaction(["logs"], "readwrite"); @@ -92,7 +92,7 @@ export class IDBLogger extends BaseLogger { } } - _finishAllAndFlush() { + _finishAllAndFlush(): void { this._finishOpenItems(); this.log({l: "pagehide, closing logs", t: "navigation"}); this._persistQueuedItems(this._queuedItems); @@ -116,14 +116,14 @@ export class IDBLogger extends BaseLogger { return openDatabase(this._name, db => db.createObjectStore("logs", {keyPath: "id", autoIncrement: true}), 1); } - _persistItem(logItem: LogItem, filter: LogFilter, forced: boolean) { + _persistItem(logItem: LogItem, filter: LogFilter, forced: boolean): void { const serializedItem = logItem.serialize(filter, undefined, forced); this._queuedItems.push({ json: JSON.stringify(serializedItem) }); } - _persistQueuedItems(items: QueuedItem[]) { + _persistQueuedItems(items: QueuedItem[]): void { try { window.localStorage.setItem(`${this._name}_queuedItems`, JSON.stringify(items)); } catch (e) { @@ -146,7 +146,7 @@ export class IDBLogger extends BaseLogger { } } - async _removeItems(items: QueuedItem[]) { + async _removeItems(items: QueuedItem[]): Promise { const db = await this._openDB(); try { const txn = db.transaction(["logs"], "readwrite"); @@ -186,7 +186,7 @@ class IDBLogExport { /** * @return {Promise} */ - removeFromStore() { + removeFromStore(): Promise { return this._logger._removeItems(this._items); } diff --git a/src/logging/LogItem.ts b/src/logging/LogItem.ts index 2909a84e..716a3e73 100644 --- a/src/logging/LogItem.ts +++ b/src/logging/LogItem.ts @@ -75,18 +75,18 @@ export class LogItem { } /** start a new detached root log item and log a reference to it from this item */ - wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull, filterCreator: FilterCreator) { + wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull, filterCreator: FilterCreator): void { this.refDetached(this.runDetached(labelOrValues, callback, logLevel, filterCreator)); } /** logs a reference to a different log item, usually obtained from runDetached. This is useful if the referenced operation can't be awaited. */ - refDetached(logItem: LogItem, logLevel: LogLevelOrNull = null) { + refDetached(logItem: LogItem, logLevel: LogLevelOrNull = null): void { logItem.ensureRefId(); this.log({ref: logItem._values.refId as number}, logLevel); } - ensureRefId() { + ensureRefId(): void { if (!this._values.refId) { this.set("refId", this._logger._createRefId()); } @@ -95,7 +95,7 @@ export class LogItem { /** * Creates a new child item and runs it in `callback`. */ - wrap(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull = null, filterCreator: FilterCreator = null) { + wrap(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevelOrNull = null, filterCreator: FilterCreator = null): unknown { const item = this.child(labelOrValues, logLevel, filterCreator); return item.run(callback); } @@ -136,12 +136,12 @@ export class LogItem { * * Hence, the child item is not returned. */ - log(labelOrValues: LabelOrValues, logLevel: LogLevelOrNull = null) { + log(labelOrValues: LabelOrValues, logLevel: LogLevelOrNull = null): void { const item = this.child(labelOrValues, logLevel, null); item.end = item.start; } - set(key: string | object, value: unknown) { + set(key: string | object, value: unknown): void { if(typeof key === "object") { const values = key; Object.assign(this._values, values); @@ -150,6 +150,7 @@ export class LogItem { } } + // todo: null or undefined here? serialize(filter: LogFilter, parentStartTime: number | null = null, forced: boolean): ISerializedItem | null { if (this._filterCreator) { try { @@ -243,7 +244,7 @@ export class LogItem { * finished the item, recording the end time. After finishing, an item can't be modified anymore as it will be persisted. * @internal shouldn't typically be called by hand. allows to force finish if a promise is still running when closing the app */ - finish() { + finish(): void { if (this.end === null) { if (this._children !== null) { for(const c of this._children) { @@ -281,7 +282,7 @@ export class LogItem { return item; } - get logger() { + get logger(): BaseLogger { return this._logger; } }