Skip to content

Commit 213f3d5

Browse files
committed
chore: logger class and some docu
1 parent 4a6b9d5 commit 213f3d5

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ import {componentLoader} from "@packages/Application/FormatD.ComponentLoader/Res
5555
componentLoader.addDefaultImport('Vendor.Website:MyComponent', () => import('../private/Fusion/MyComponent'));
5656
//...
5757
componentLoader.initialize()
58+
```
59+
60+
The optional callback can be used to initialize custom js not managed by the component manager
61+
```typescript
62+
componentLoader.initialize(async (domSection, reason) => {
63+
if (document.querySelector('body')) {
64+
// add stuff here
65+
}
66+
});
5867
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export default class Logger {
2+
3+
protected scope: string
4+
protected enabled: boolean
5+
protected filterScopes: string[]
6+
7+
constructor(scope) {
8+
this.scope = scope;
9+
this.enabled = window.__ComponentLoaderComponentRegistry.context.isDevelopment;
10+
this.filterScopes = []; // NO filter active
11+
//this.filterScopes = ['ModalEnabled']; // display only ModalEnabled Scope
12+
}
13+
14+
/**
15+
* Logs all provided arguments if enabled
16+
*/
17+
log(...args) {
18+
if (this.enabled && (this.filterScopes.length === 0 || this.filterScopes.indexOf(this.scope) !== -1)) {
19+
console.log(this.scope + ':', ...args);
20+
}
21+
}
22+
23+
/**
24+
* Logs all provided arguments
25+
*/
26+
error(...args) {
27+
console.error(this.scope + ':', ...args);
28+
}
29+
30+
}

0 commit comments

Comments
 (0)