|
1 | 1 | import { LogObject, LogObjectType, LogLevel } from './LogObject';
|
2 | 2 |
|
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'; |
24 | 4 |
|
25 |
| - window['BlazorExtensions']['Logging']['BrowserConsoleLogger']['Log'] = function (logObjectValue) { |
| 5 | +interface IBrowserConsoleLogger { |
| 6 | + Log(logObjectValue: string): void; |
| 7 | +} |
26 | 8 |
|
| 9 | +class BrowserConsoleLogger implements IBrowserConsoleLogger { |
| 10 | + Log(logObjectValue: string): void { |
27 | 11 | const logObject = JSON.parse(logObjectValue);
|
28 | 12 | var logMethod = console.log;
|
29 | 13 |
|
@@ -56,4 +40,25 @@ function initialize() {
|
56 | 40 | }
|
57 | 41 | }
|
58 | 42 |
|
| 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 | + |
59 | 64 | initialize();
|
0 commit comments