Skip to content

Commit a14d2c1

Browse files
committed
Cleaning up TS and improve load time
1 parent 7eb41aa commit a14d2c1

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

src/Blazor.Extensions.Logging.JS/src/Initialize.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
11
import { LogObject, LogObjectType, LogLevel } from './LogObject';
22

3-
function initialize() {
4-
"use strict";
5-
6-
if (typeof window !== 'undefined' && !window['BlazorExtensions']) {
7-
// When the library is loaded in a browser via a <script> element, make the
8-
// following APIs available in global scope for invocation from JS
9-
window['BlazorExtensions'] = {
10-
Logging: {
11-
BrowserConsoleLogger: {
12-
}
13-
}
14-
};
15-
} else {
16-
window['BlazorExtensions'] = {
17-
...window['BlazorExtensions'],
18-
Logging: {
19-
BrowserConsoleLogger: {
20-
}
21-
}
22-
};
23-
}
3+
const blazorExtensions = 'BlazorExtensions';
244

25-
window['BlazorExtensions']['Logging']['BrowserConsoleLogger']['Log'] = function (logObjectValue) {
5+
interface IBrowserConsoleLogger {
6+
Log(logObjectValue: string): void;
7+
}
268

9+
class BrowserConsoleLogger implements IBrowserConsoleLogger {
10+
Log(logObjectValue: string): void {
2711
const logObject = JSON.parse(logObjectValue);
2812
var logMethod = console.log;
2913

@@ -56,4 +40,25 @@ function initialize() {
5640
}
5741
}
5842

43+
function initialize() {
44+
"use strict";
45+
46+
if (typeof window !== 'undefined' && !window[blazorExtensions]) {
47+
// When the library is loaded in a browser via a <script> element, make the
48+
// following APIs available in global scope for invocation from JS
49+
window[blazorExtensions] = {
50+
Logging: {
51+
BrowserConsoleLogger: new BrowserConsoleLogger()
52+
}
53+
};
54+
} else {
55+
window[blazorExtensions] = {
56+
...window['BlazorExtensions'],
57+
Logging: {
58+
BrowserConsoleLogger: new BrowserConsoleLogger()
59+
}
60+
};
61+
}
62+
}
63+
5964
initialize();

0 commit comments

Comments
 (0)