-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeafComponent.js
More file actions
32 lines (27 loc) · 884 Bytes
/
LeafComponent.js
File metadata and controls
32 lines (27 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import AbstractComponent from './AbstractComponent.js';
import elementReferencesProvider from './utils/elementReferencesProvider.js';
export default class LeafComponent extends AbstractComponent {
constructor(dataSource, useShadowDom = true) {
super(dataSource, elementReferencesProvider, renderer, renderingRootProvider);
this._LeafComponent = {
uiRoot: useShadowDom ? this.attachShadow({mode: 'open'}) : this,
lastUi: null,
};
}
}
function renderer(component, uiRootProvider, ui) {
if (ui === component._LeafComponent.lastUi) {
return;
}
const uiRoot = uiRootProvider(component);
if (typeof ui === 'string') {
uiRoot.innerHTML = ui;
} else {
uiRoot.innerHTML = '';
uiRoot.appendChild(ui);
}
component._LeafComponent.lastUi = ui;
}
function renderingRootProvider(component) {
return component._LeafComponent.uiRoot;
}