<commit_before>import Blot from './abstract/blot';
import ContainerBlot from './container';
import LinkedList from '../collection/linked-list';
import ParentBlot from './abstract/parent';
import * as Registry from '../registry';


class ParchmentBlot extends ContainerBlot {
  static blotName = 'parchment';
  static tagName = 'DIV';

  children: LinkedList<ContainerBlot>;
  observer: MutationObserver;

  constructor(node: Node) {
    super(node);
    this.observer = new MutationObserver((mutations: MutationRecord[]) => {
      this.update(mutations);
    });
    this.observer.observe(this.domNode, {
      attributes: true,
      characterData: true,
      childList: true,
      subtree: true
    });
  }

  update(mutations: MutationRecord);
  update(mutations?: MutationRecord[]);
  update(mutations: any) {
    if (mutations instanceof MutationRecord) {
      return super.update(mutations);
    } else if (mutations == null) {
      mutations = this.observer.takeRecords();
    }
    mutations.forEach((mutation: MutationRecord) => {
      let blot = Blot.findBlot(mutation.target, true);
      if (blot != null) {
        blot.update(mutation);
      }
    });
    this.observer.takeRecords();  // Prevent changes from rebuilds
  }
}


export default ParchmentBlot;<commit_msg>disable observer for internal changes<commit_after>import Blot from './abstract/blot';
import ContainerBlot from './container';
import LinkedList from '../collection/linked-list';
import ParentBlot from './abstract/parent';
import * as Registry from '../registry';


const OBSERVER_CONFIG = {
  attributes: true,
  characterData: true,
  childList: true,
  subtree: true
};

class ParchmentBlot extends ContainerBlot {
  static blotName = 'parchment';
  static tagName = 'DIV';

  children: LinkedList<ContainerBlot>;
  observer: MutationObserver;
  dirty: boolean;

  constructor(node: Node) {
    super(node);
    this.observer = new MutationObserver((mutations: MutationRecord[]) => {
      this.update(mutations);
    });
    this.observer.observe(this.domNode, OBSERVER_CONFIG);
    this.dirty = false;
  }

  deleteAt(index: number, length: number) {
    this.dirty = true;
    this.observer.disconnect();
    super.deleteAt(index, length);
    this.observer.observe(this.domNode, OBSERVER_CONFIG);
  }

  format(name: string, value: any) {
    this.dirty = true;
    this.observer.disconnect();
    super.format(name, value);
    this.observer.observe(this.domNode, OBSERVER_CONFIG);
  }

  formatAt(index: number, length: number, name: string, value: any) {
    this.dirty = true;
    this.observer.disconnect();
    super.formatAt(index, length, name, value);
    this.observer.observe(this.domNode, OBSERVER_CONFIG);
  }

  insertAt(index: number, value: string, def?: any) {
    this.dirty = true;
    this.observer.disconnect();
    super.insertAt(index, value, def);
    this.observer.observe(this.domNode, OBSERVER_CONFIG);
  }

  update(mutations: MutationRecord);
  update(mutations?: MutationRecord[]);
  update(mutations: any) {
    if (mutations instanceof MutationRecord) {
      return super.update(mutations);
    } else if (mutations == null) {
      mutations = this.observer.takeRecords();
    }
    this.observer.disconnect();
    mutations.forEach((mutation: MutationRecord) => {
      let blot = Blot.findBlot(mutation.target, true);
      if (blot != null) {
        blot.update(mutation);
      }
    });
    this.observer.observe(this.domNode, OBSERVER_CONFIG);
    this.dirty = false;
  }
}


export default ParchmentBlot;
{'fraction_non_alphanumeric': 0.13068021450747955, 'fraction_numerical': 0.0, 'mean_word_length': 3.6387434554973823, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1165268', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1093, 'n_words': 239}