Skip to content

Commit

Permalink
keep track of children in LISSFather
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-migdal committed Feb 26, 2025
1 parent 167b4d0 commit d12e4c4
Showing 1 changed file with 41 additions and 20 deletions.
61 changes: 41 additions & 20 deletions V3/src/LISSClasses/LISSFather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,58 @@ import LISSUpdate from "./LISSUpdate";

export const WAITING_UPGRADE = Symbol();

const obsChildren = new MutationObserver( (records: MutationRecord[]) => {

for(let i = 0; i < records.length; ++i) {
const {addedNodes, removedNodes} = records[i];
const target: LISSFather = records[i].target as any;

for(let j = 0; j < addedNodes.length; ++j) {
const node = addedNodes[j]
function observe( target: LISSFather, callback: (records: MutationRecord[]) => void ) {
new MutationObserver(callback).observe(target, {childList: true});
}

// extends LISSSignal (?) Properties merger (?)
export default class LISSFather extends LISSUpdate {

protected LISSChildren = new Array<LISSChild>();

constructor() {
super();

observe(this, (records: MutationRecord[]) => {

this.updateChildrenList();

for(let i = 0; i < records.length; ++i) {
this.processAddedNodes (records[i].addedNodes);
this.processRemovedNodes(records[i].removedNodes);
}
});

this.updateChildrenList();
this.processAddedNodes(this.childNodes);
}

protected processAddedNodes(nodes: NodeList) {

for(let j = 0; j < nodes.length; ++j) {
const node = nodes[j]
if( node instanceof LISSChild )
(target as any).onAttach( node );
this.onAttach( node );
else
(node as any)[WAITING_UPGRADE] = true;
}
}

protected processRemovedNodes(nodes: NodeList) {

for(let j = 0; j < removedNodes.length; ++j) {
const node = removedNodes[j]
for(let j = 0; j < nodes.length; ++j) {
const node = nodes[j]
if( node instanceof LISSChild )
(target as any).onDetach( node );
this.onDetach( node );
else
(node as any)[WAITING_UPGRADE] = false;
}
}
});

// extends LISSSignal (?) Properties merger (?)
export default class LISSFather extends LISSUpdate {

constructor() {
super();

obsChildren.observe(this, {childList: true});
protected updateChildrenList() {
this.LISSChildren = [ ...this.children ].filter( (e) => {
return e instanceof LISSChild
})
}

protected onDetach(child: LISSChild) {
Expand Down

0 comments on commit d12e4c4

Please sign in to comment.