Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 9c698f0

Browse files
committed
optimized tag method
1 parent 434c1f0 commit 9c698f0

File tree

3 files changed

+50
-63
lines changed

3 files changed

+50
-63
lines changed

examples/react/develop/multieditor-ts/src/core/signUpEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const signUpEditor = createMultieditor<InitialDataInterface>({
117117
},
118118
},
119119
fixedProperties: ['id'],
120-
reValidateMode: 'onChange',
120+
reValidateMode: 'onBlur',
121121
});
122122

123123
// For better debugging

packages/logger/src/logger.ts

Lines changed: 47 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ export class Logger {
1818
} = {};
1919

2020
/**
21+
* Handy Class for handling console.logs
22+
*
2123
* @public
22-
* Logger - Handy Class for handling console.logs
24+
* @param config - Configuration object
2325
*/
2426
constructor(config: LoggerConfig = {}) {
2527
let _config = typeof config === 'function' ? config(this) : config;
@@ -39,26 +41,17 @@ export class Logger {
3941
canUseCustomStyles: _config.canUseCustomStyles as any,
4042
level: _config.level as any,
4143
};
42-
this.addDefaultLoggerCategories();
43-
}
4444

45-
/**
46-
* @public
47-
* Adds Conditions to Logs
48-
*/
49-
public get if() {
50-
return {
51-
tag: (tags: string[]) => this.tag(tags),
52-
};
45+
this.addDefaultLoggerCategories();
5346
}
5447

5548
/**
49+
* Log level the Logger can work with.
50+
*
5651
* @public
57-
* Default Levels of Logger
5852
*/
5953
static get level() {
6054
return {
61-
TRACE: 1,
6255
DEBUG: 2,
6356
LOG: 5,
6457
TABLE: 5,
@@ -69,12 +62,21 @@ export class Logger {
6962
};
7063
}
7164

72-
//=========================================================================================================
73-
// Add Default Logger Categories
74-
//=========================================================================================================
7565
/**
66+
* Adds Conditions to Logs
67+
*
68+
* @public
69+
*/
70+
public get if() {
71+
return {
72+
tag: (tags: string[]) => this.tag(tags),
73+
};
74+
}
75+
76+
/**
77+
* Assigns the default Logger categories to the Logger.
78+
*
7679
* @internal
77-
* Adds Default Logger Categories
7880
*/
7981
private addDefaultLoggerCategories() {
8082
this.createLoggerCategory({
@@ -109,51 +111,35 @@ export class Logger {
109111
prefix: 'Error',
110112
level: Logger.level.ERROR,
111113
});
112-
this.createLoggerCategory({
113-
key: 'trace',
114-
prefix: 'Trace',
115-
level: Logger.level.TRACE,
116-
});
117114
this.createLoggerCategory({
118115
key: 'table',
119116
level: Logger.level.TABLE,
120117
});
121118
}
122119

123-
//=========================================================================================================
124-
// Tag
125-
//=========================================================================================================
126120
/**
127-
* @internal
128121
* Only executes following 'command' if all given tags are included in allowedTags
122+
*
123+
* @internal
129124
* @param tags - Tags
130125
*/
131-
private tag(tags: string[]) {
132-
if (includesArray(this.allowedTags, tags)) {
133-
return {
134-
log: (...data: any[]) => this.log(...data),
135-
debug: (...data: any[]) => this.debug(...data),
136-
info: (...data: any[]) => this.info(...data),
137-
success: (...data: any[]) => this.success(...data),
138-
warn: (...data: any[]) => this.warn(...data),
139-
error: (...data: any[]) => this.error(...data),
140-
trace: (...data: any[]) => this.trace(...data),
141-
table: (...data: any[]) => this.table(...data),
142-
};
126+
private tag(tags: string[]): TagMethodReturnInterface {
127+
const defaultLoggerCategories = Object.keys(
128+
Logger.level
129+
).map((loggerCategory) => loggerCategory.toLowerCase());
130+
const includesTag = includesArray(this.allowedTags, tags);
131+
132+
// Build object representing taggable log methods
133+
const finalObject: TagMethodReturnInterface = {} as any;
134+
for (const loggerCategory of defaultLoggerCategories) {
135+
finalObject[loggerCategory] = includesTag
136+
? this[loggerCategory]
137+
: () => {
138+
/* do nothing */
139+
};
143140
}
144-
const doNothing = () => {
145-
/* do nothing */
146-
};
147-
return {
148-
log: doNothing,
149-
debug: doNothing,
150-
info: doNothing,
151-
success: doNothing,
152-
warn: doNothing,
153-
error: doNothing,
154-
trace: doNothing,
155-
table: doNothing,
156-
};
141+
142+
return finalObject;
157143
}
158144

159145
public log(...data: any[]) {
@@ -196,14 +182,6 @@ export class Logger {
196182
);
197183
}
198184

199-
public trace(...data: any[]) {
200-
this.invokeConsole(
201-
data,
202-
'trace',
203-
typeof console.trace !== 'undefined' ? 'trace' : 'log'
204-
);
205-
}
206-
207185
public table(...data: any[]) {
208186
this.invokeConsole(
209187
data,
@@ -460,7 +438,6 @@ export type ConsoleLogType =
460438
| 'log'
461439
| 'warn'
462440
| 'error'
463-
| 'trace'
464441
| 'table'
465442
| 'info'
466443
| 'debug';
@@ -478,3 +455,13 @@ export interface LoggerWatcherConfigInterface {
478455
callback: LoggerWatcherCallback;
479456
level?: number;
480457
}
458+
459+
export interface TagMethodReturnInterface {
460+
log: (...data: any) => void;
461+
debug: (...data: any) => void;
462+
info: (...data: any) => void;
463+
success: (...data: any) => void;
464+
warn: (...data: any) => void;
465+
error: (...data: any) => void;
466+
table: (...data: any) => void;
467+
}

packages/logger/src/shared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ let sharedLogger = new Logger(defaultSharedLoggerConfig);
1313
export { sharedLogger };
1414

1515
/**
16-
* Assigns the specified configuration object to the shared Agile Logger.
16+
* Assigns the specified Logger as the shared Logger.
1717
*
18-
* @param logger - Configuration object
18+
* @param logger - Logger to become the new shared Logger.
1919
*/
2020
export function assignSharedLogger(logger: Logger): void {
2121
sharedLogger = logger;

0 commit comments

Comments
 (0)