25 lines
706 B
JavaScript
25 lines
706 B
JavaScript
|
const notify = (node) => !node.isLayoutDirty && node.willUpdate(false);
|
||
|
function nodeGroup() {
|
||
|
const nodes = new Set();
|
||
|
const subscriptions = new WeakMap();
|
||
|
const dirtyAll = () => nodes.forEach(notify);
|
||
|
return {
|
||
|
add: (node) => {
|
||
|
nodes.add(node);
|
||
|
subscriptions.set(node, node.addEventListener("willUpdate", dirtyAll));
|
||
|
},
|
||
|
remove: (node) => {
|
||
|
nodes.delete(node);
|
||
|
const unsubscribe = subscriptions.get(node);
|
||
|
if (unsubscribe) {
|
||
|
unsubscribe();
|
||
|
subscriptions.delete(node);
|
||
|
}
|
||
|
dirtyAll();
|
||
|
},
|
||
|
dirty: dirtyAll,
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export { nodeGroup };
|