<commit_before>import Attributor from '../../attributor/attributor';
import AttributorStore from '../../attributor/store';
import { Blot, Parent, Formattable } from './blot';
import ContainerBlot from './container';
import ShadowBlot from './shadow';
import * as Registry from '../../registry';


abstract class FormatBlot extends ContainerBlot implements Formattable {
  protected attributes: AttributorStore;

  static formats(domNode): { [index: string]: any } {
    let formats = {};
    if ((<any>Registry.query(this.scope)).blotName !== this.blotName) {
      formats[this.blotName] = Array.isArray(this.tagName) ? domNode.tagName.toLowerCase() : true;
    }
    return formats;
  }

  attach(): void {
    super.attach();
    this.attributes = new AttributorStore(this.domNode);
  }

  format(name: string, value: any): void {
    let format = Registry.query(name);
    if (format instanceof Attributor) {
      this.attributes.attribute(format, value);
    } else if (value) {
      if (format != null && (name !== this.statics.blotName || this.formats()[name] !== value)) {
        this.replaceWith(name, value);
      }
    } else if (name === this.statics.blotName) {
      this.replaceWith(Registry.create(this.statics.scope));
    }
  }

  formats(): { [index: string]: any } {
    return (<any>Object).assign({}, this.attributes.values(), this.statics.formats(this.domNode));
  }

  replaceWith(name: string | Blot, value?: any): Blot {
    let replacement = <FormatBlot>super.replaceWith(name, value);
    this.attributes.copy(replacement);
    return replacement;
  }

  update(mutations: MutationRecord[]): void {
    super.update(mutations);
    if (mutations.some((mutation) => {
      return mutation.target === this.domNode && mutation.type === 'attributes';
    })) {
      this.attributes.build();<commit_msg>android does not like Object.assign<commit_after>import Attributor from '../../attributor/attributor';
import AttributorStore from '../../attributor/store';
import { Blot, Parent, Formattable } from './blot';
import ContainerBlot from './container';
import ShadowBlot from './shadow';
import * as Registry from '../../registry';


abstract class FormatBlot extends ContainerBlot implements Formattable {
  protected attributes: AttributorStore;

  static formats(domNode): { [index: string]: any } {
    let formats = {};
    if ((<any>Registry.query(this.scope)).blotName !== this.blotName) {
      formats[this.blotName] = Array.isArray(this.tagName) ? domNode.tagName.toLowerCase() : true;
    }
    return formats;
  }

  attach(): void {
    super.attach();
    this.attributes = new AttributorStore(this.domNode);
  }

  format(name: string, value: any): void {
    let format = Registry.query(name);
    if (format instanceof Attributor) {
      this.attributes.attribute(format, value);
    } else if (value) {
      if (format != null && (name !== this.statics.blotName || this.formats()[name] !== value)) {
        this.replaceWith(name, value);
      }
    } else if (name === this.statics.blotName) {
      this.replaceWith(Registry.create(this.statics.scope));
    }
  }

  formats(): { [index: string]: any } {
    let attributes = this.attributes.values();
    let formats = this.statics.formats(this.domNode);
    Object.keys(formats).forEach(function(key) {
      attributes[key] = formats[key];
    });
    return attributes;
  }

  replaceWith(name: string | Blot, value?: any): Blot {
    let replacement = <FormatBlot>super.replaceWith(name, value);
    this.attributes.copy(replacement);
    return replacement;
  }

  update(mutations: MutationRecord[]): void {
    super.update(mutations);
    if (mutations.some((mutation) => {
      return mutation.target === this.domNode && mutation.type === 'attributes';
    })) {
      this.attributes.build();
{'fraction_non_alphanumeric': 0.1558066211245402, 'fraction_numerical': 0.0, 'mean_word_length': 3.5812274368231045, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, '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': '5973495', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1130, 'n_words': 256}