I have 1 mutation observer which is used as directive,
Mutation.ts:
const element = this.elementRef.nativeElement;
this.changes = new MutationObserver((mutations: MutationRecord[]) => {
mutations.forEach((mutation: MutationRecord) => this.domChange.emit(mutation));
}
);
this.changes.observe(element, {
childList: true,
subtree: true
});
component HTML :
<child-component (mutation)="mutate($event)"></child-component>
component TS:
mutate(event) {
if(searchKey) {
const elements = this.elem.nativeElement.querySelectorAll(`.${'highlight'}`);
const instance = new Mark(elements);
instance.mark(searchKey, options);
}
}
This child component loads nearly 500 records, dom change emits so many times that my mutate(event) function is not able to handle all at once. Need to understand if there is a way that I can highlight for each request without my app freezing