2020-08-04 15:30:24 +00:00
|
|
|
import { addRootNode, listRootNodes } from '@iconify/iconify/lib/modules/root';
|
2021-09-27 15:53:31 +00:00
|
|
|
import { stopObserving } from '@iconify/iconify/lib/modules/observer';
|
2020-08-04 15:30:24 +00:00
|
|
|
import { ObservedNode } from '@iconify/iconify/lib/modules/observed-node';
|
|
|
|
|
2020-04-28 09:47:35 +00:00
|
|
|
let counter = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create node for test
|
|
|
|
*/
|
|
|
|
export function getNode(prefix = 'test') {
|
|
|
|
const id = prefix + '-' + Date.now() + '-' + counter++;
|
|
|
|
|
|
|
|
const node = document.createElement('div');
|
|
|
|
node.setAttribute('id', id);
|
|
|
|
|
|
|
|
document.getElementById('debug').appendChild(node);
|
|
|
|
return node;
|
|
|
|
}
|
2020-08-04 15:30:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set root node, remove old nodes
|
|
|
|
*/
|
|
|
|
export function setRoot(node: HTMLElement): ObservedNode {
|
|
|
|
listRootNodes().forEach((node) => {
|
|
|
|
if (typeof node.node !== 'function') {
|
2021-09-27 15:53:31 +00:00
|
|
|
stopObserving(node.node);
|
2020-08-04 15:30:24 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return addRootNode(node);
|
|
|
|
}
|