fix(tracker): check node scrolls only on start

This commit is contained in:
Alex Kaminskii 2022-06-29 11:10:52 +02:00
parent f78da27562
commit cea704e1ee
3 changed files with 8 additions and 8 deletions

View file

@ -1,4 +1,4 @@
type NodeCallback = (node: Node) => void;
type NodeCallback = (node: Node, isStart: boolean) => void;
type ElementListener = [string, EventListener];
export default class Nodes {
@ -57,8 +57,8 @@ export default class Nodes {
}
return id;
}
callNodeCallbacks(node: Node): void {
this.nodeCallbacks.forEach((cb) => cb(node));
callNodeCallbacks(node: Node, start: boolean): void {
this.nodeCallbacks.forEach((cb) => cb(node, start));
}
getID(node: Node): number | undefined {
return (node as any)[this.node_id];

View file

@ -333,12 +333,12 @@ export default abstract class Observer {
}
return (this.commited[id] = this._commitNode(id, node));
}
private commitNodes(): void {
private commitNodes(isStart: boolean = false): void {
let node;
this.recents.forEach((type, id) => {
this.commitNode(id);
if (type === RecentsType.New && (node = this.app.nodes.getNode(id))) {
this.app.nodes.callNodeCallbacks(node);
this.app.nodes.callNodeCallbacks(node, isStart)
}
})
this.clear();
@ -356,7 +356,7 @@ export default abstract class Observer {
});
this.bindTree(nodeToBind);
beforeCommit(this.app.nodes.getID(node))
this.commitNodes();
this.commitNodes(true)
}
disconnect(): void {

View file

@ -35,8 +35,8 @@ export default function (app: App): void {
nodeScroll.clear();
});
app.nodes.attachNodeCallback(node => {
if (isElementNode(node) && node.scrollLeft + node.scrollTop > 0) {
app.nodes.attachNodeCallback((node, isStart) => {
if (isStart && isElementNode(node) && node.scrollLeft + node.scrollTop > 0) {
nodeScroll.set(node, [node.scrollLeft, node.scrollTop]);
}
})