Annotate method arguments

This commit is contained in:
RMidhunSuresh 2021-11-09 20:57:47 +05:30
parent 7893a121c0
commit 8cbc81b8bb

View file

@ -21,6 +21,10 @@ import {Platform} from "../platform/web/Platform.js";
// todo: move this to LogItem?
type LabelOrValues = string | {l: string; [key: string]: unknown};
type LogCallback = (item: LogItem) => Promise<unknown> | undefined;
// todo: this should be an enum
type LogLevel = number | null;
type FilterCreator = ((filter: LogFilter, item: LogItem) => LogFilter) | null;
export abstract class BaseLogger {
protected _openItems: Set<LogItem> = new Set();
@ -37,7 +41,7 @@ export abstract class BaseLogger {
}
/** if item is a log item, wrap the callback in a child of it, otherwise start a new root log item. */
wrapOrRun(item, labelOrValues: LabelOrValues, callback, logLevel = null, filterCreator = null) {
wrapOrRun(item: LogItem, labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevel = null, filterCreator: FilterCreator = null) {
if (item) {
return item.wrap(labelOrValues, callback, logLevel, filterCreator);
} else {
@ -50,27 +54,27 @@ export abstract class BaseLogger {
Useful to pair with LogItem.refDetached.
@return {LogItem} the log item added, useful to pass to LogItem.refDetached */
runDetached(labelOrValues: LabelOrValues, callback, logLevel = null, filterCreator = null) {
runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevel = null, filterCreator: FilterCreator = null) {
if (logLevel === null) {
logLevel = LogLevel.Info;
}
const item = new LogItem(labelOrValues, logLevel, null, this);
this._run(item, callback, logLevel, filterCreator, false /* don't throw, nobody is awaiting */);
this._run(item, callback, logLevel!, filterCreator, false /* don't throw, nobody is awaiting */);
return item;
}
/** run a callback wrapped in a log operation.
Errors and duration are transparently logged, also for async operations.
Whatever the callback returns is returned here. */
run(labelOrValues: LabelOrValues, callback, logLevel = null, filterCreator = null) {
run(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevel = null, filterCreator: FilterCreator = null) {
if (logLevel === null) {
logLevel = LogLevel.Info;
}
const item = new LogItem(labelOrValues, logLevel, null, this);
return this._run(item, callback, logLevel, filterCreator, true);
return this._run(item, callback, logLevel!, filterCreator, true);
}
_run(item, callback, logLevel, filterCreator, shouldThrow) {
_run(item: LogItem, callback: LogCallback, logLevel: number, filterCreator: FilterCreator, shouldThrow: boolean) {
this._openItems.add(item);
const finishItem = () => {