forked from mystiq/hydrogen-web
Add void return types as well
This commit is contained in:
parent
5efa27c2a3
commit
2d8b719ab0
2 changed files with 17 additions and 16 deletions
|
@ -51,18 +51,18 @@ export class IDBLogger extends BaseLogger {
|
||||||
this._flushInterval = this._platform.clock.createInterval(() => this._tryFlush(), flushInterval);
|
this._flushInterval = this._platform.clock.createInterval(() => this._tryFlush(), flushInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose(): void {
|
||||||
window.removeEventListener("pagehide", this, false);
|
window.removeEventListener("pagehide", this, false);
|
||||||
this._flushInterval.dispose();
|
this._flushInterval.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEvent(evt: Event) {
|
handleEvent(evt: Event): void {
|
||||||
if (evt.type === "pagehide") {
|
if (evt.type === "pagehide") {
|
||||||
this._finishAllAndFlush();
|
this._finishAllAndFlush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _tryFlush() {
|
async _tryFlush(): Promise<void> {
|
||||||
const db = await this._openDB();
|
const db = await this._openDB();
|
||||||
try {
|
try {
|
||||||
const txn = db.transaction(["logs"], "readwrite");
|
const txn = db.transaction(["logs"], "readwrite");
|
||||||
|
@ -92,7 +92,7 @@ export class IDBLogger extends BaseLogger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_finishAllAndFlush() {
|
_finishAllAndFlush(): void {
|
||||||
this._finishOpenItems();
|
this._finishOpenItems();
|
||||||
this.log({l: "pagehide, closing logs", t: "navigation"});
|
this.log({l: "pagehide, closing logs", t: "navigation"});
|
||||||
this._persistQueuedItems(this._queuedItems);
|
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);
|
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);
|
const serializedItem = logItem.serialize(filter, undefined, forced);
|
||||||
this._queuedItems.push({
|
this._queuedItems.push({
|
||||||
json: JSON.stringify(serializedItem)
|
json: JSON.stringify(serializedItem)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_persistQueuedItems(items: QueuedItem[]) {
|
_persistQueuedItems(items: QueuedItem[]): void {
|
||||||
try {
|
try {
|
||||||
window.localStorage.setItem(`${this._name}_queuedItems`, JSON.stringify(items));
|
window.localStorage.setItem(`${this._name}_queuedItems`, JSON.stringify(items));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -146,7 +146,7 @@ export class IDBLogger extends BaseLogger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _removeItems(items: QueuedItem[]) {
|
async _removeItems(items: QueuedItem[]): Promise<void> {
|
||||||
const db = await this._openDB();
|
const db = await this._openDB();
|
||||||
try {
|
try {
|
||||||
const txn = db.transaction(["logs"], "readwrite");
|
const txn = db.transaction(["logs"], "readwrite");
|
||||||
|
@ -186,7 +186,7 @@ class IDBLogExport {
|
||||||
/**
|
/**
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
removeFromStore() {
|
removeFromStore(): Promise<void> {
|
||||||
return this._logger._removeItems(this._items);
|
return this._logger._removeItems(this._items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,18 +75,18 @@ export class LogItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** start a new detached root log item and log a reference to it from this item */
|
/** 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));
|
this.refDetached(this.runDetached(labelOrValues, callback, logLevel, filterCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** logs a reference to a different log item, usually obtained from runDetached.
|
/** logs a reference to a different log item, usually obtained from runDetached.
|
||||||
This is useful if the referenced operation can't be awaited. */
|
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();
|
logItem.ensureRefId();
|
||||||
this.log({ref: logItem._values.refId as number}, logLevel);
|
this.log({ref: logItem._values.refId as number}, logLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureRefId() {
|
ensureRefId(): void {
|
||||||
if (!this._values.refId) {
|
if (!this._values.refId) {
|
||||||
this.set("refId", this._logger._createRefId());
|
this.set("refId", this._logger._createRefId());
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ export class LogItem {
|
||||||
/**
|
/**
|
||||||
* Creates a new child item and runs it in `callback`.
|
* 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);
|
const item = this.child(labelOrValues, logLevel, filterCreator);
|
||||||
return item.run(callback);
|
return item.run(callback);
|
||||||
}
|
}
|
||||||
|
@ -136,12 +136,12 @@ export class LogItem {
|
||||||
*
|
*
|
||||||
* Hence, the child item is not returned.
|
* 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);
|
const item = this.child(labelOrValues, logLevel, null);
|
||||||
item.end = item.start;
|
item.end = item.start;
|
||||||
}
|
}
|
||||||
|
|
||||||
set(key: string | object, value: unknown) {
|
set(key: string | object, value: unknown): void {
|
||||||
if(typeof key === "object") {
|
if(typeof key === "object") {
|
||||||
const values = key;
|
const values = key;
|
||||||
Object.assign(this._values, values);
|
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 {
|
serialize(filter: LogFilter, parentStartTime: number | null = null, forced: boolean): ISerializedItem | null {
|
||||||
if (this._filterCreator) {
|
if (this._filterCreator) {
|
||||||
try {
|
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.
|
* 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
|
* @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.end === null) {
|
||||||
if (this._children !== null) {
|
if (this._children !== null) {
|
||||||
for(const c of this._children) {
|
for(const c of this._children) {
|
||||||
|
@ -281,7 +282,7 @@ export class LogItem {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
get logger() {
|
get logger(): BaseLogger {
|
||||||
return this._logger;
|
return this._logger;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue