<commit_before><!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="boot.html">
<link rel="import" href="utils.html">
<link rel="import" href="array-splice.html">
<script>
(function() {

  function isSlot(node) {
    return (node.localName === 'slot');
  }

  function getEffectiveNodes(node) {
    if (isSlot(node)) {
      return node.assignedNodes({flatten: true});
    } else {
      return Array.from(node.childNodes).map(node => {
        if (isSlot(node)) {
          return node.assignedNodes({flatten: true});
        } else {
          return [node];
        }
      }).reduce((a, b) => a.concat(b), []);
    }
  }

  let effectiveNodesObserverPromise = Promise.resolve();

  class EffectiveNodesObserver {

    constructor(target, callback) {
      /** @type {MutationObserver} */
      this.shadyChildrenObserver = null;
      /** @type {MutationObserver} */
      this.nativeChildrenObserver = null;
      this.connected = false;
      this.target = target;
      this.callback = callback;
      this.effectiveNodes = [];
      this.observer = null;
      this.scheduled = false;
      this._boundSchedule = () => {
        this.schedule();
      }
      this.connect();
      this.schedule();
    }

    connect() {
      if (isSlot(this.target)) {
        this.listenSlots([this.target]);
      } else {
        this.listenSlots(this.target.children);
        if (window.ShadyDOM) {
          this.shadyChildrenObserver =
            ShadyDOM.observeChildren(this.target, (mutations) => {
              this.processMutations(mutations);
            });
        } else {
          this.nativeChildrenObserver =
            new MutationObserver((mutations) => {
              this.processMutations(mutations);
            });
          this.nativeChildrenObserver.observe(this.target, {childList: true});
        }
      }
      this.connected = true;
    }

    disconnect() {
      if (isSlot(this.target)) {
        this.unlistenSlots([this.target]);
      } else {
        this.unlistenSlots(this.target.children);
        if (window.ShadyDOM && this.shadyChildrenObserver) {
          ShadyDOM.unobserveChildren(this.shadyChildrenObserver);
          this.shadyChildrenObserver = null;
        } else if (this.nativeChildrenObserver) {
          this.nativeChildrenObserver.disconnect();
          this.nativeChildrenObserver = null;
        }
      }
      this.connected = false;
    }

    schedule() {
      if (!this.scheduled) {
        this.scheduled = true;
        effectiveNodesObserverPromise.then(() => {
          this.flush();
        });
      }
    }

    processMutations(mutations) {
      this.processSlotMutations(mutations);
      this.flush();
    }

    processSlotMutations(mutations) {
      if (mutations) {
        for (let i=0; i < mutations.length; i++) {
          let mutation = mutations[i];
          if (mutation.addedNodes) {
            this.listenSlots(mutation.addedNodes);
          }
          if (mutation.removedNodes) {
            this.unlistenSlots(mutation.removedNodes);
          }
        }
      }
    }

    flush() {
      if (!this.connected) {
        return;
      }
      if (window.ShadyDOM) {
        ShadyDOM.flush();<commit_msg>Avoid use of promise for observeNodes debouncing (avoid Safari bug).<commit_after><!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="boot.html">
<link rel="import" href="utils.html">
<link rel="import" href="array-splice.html">
<link rel="import" href="async.html">
<script>
(function() {

  function isSlot(node) {
    return (node.localName === 'slot');
  }

  function getEffectiveNodes(node) {
    if (isSlot(node)) {
      return node.assignedNodes({flatten: true});
    } else {
      return Array.from(node.childNodes).map(node => {
        if (isSlot(node)) {
          return node.assignedNodes({flatten: true});
        } else {
          return [node];
        }
      }).reduce((a, b) => a.concat(b), []);
    }
  }

  class EffectiveNodesObserver {

    constructor(target, callback) {
      /** @type {MutationObserver} */
      this.shadyChildrenObserver = null;
      /** @type {MutationObserver} */
      this.nativeChildrenObserver = null;
      this.connected = false;
      this.target = target;
      this.callback = callback;
      this.effectiveNodes = [];
      this.observer = null;
      this.scheduled = false;
      this._boundSchedule = () => {
        this.schedule();
      }
      this.connect();
      this.schedule();
    }

    connect() {
      if (isSlot(this.target)) {
        this.listenSlots([this.target]);
      } else {
        this.listenSlots(this.target.children);
        if (window.ShadyDOM) {
          this.shadyChildrenObserver =
            ShadyDOM.observeChildren(this.target, (mutations) => {
              this.processMutations(mutations);
            });
        } else {
          this.nativeChildrenObserver =
            new MutationObserver((mutations) => {
              this.processMutations(mutations);
            });
          this.nativeChildrenObserver.observe(this.target, {childList: true});
        }
      }
      this.connected = true;
    }

    disconnect() {
      if (isSlot(this.target)) {
        this.unlistenSlots([this.target]);
      } else {
        this.unlistenSlots(this.target.children);
        if (window.ShadyDOM && this.shadyChildrenObserver) {
          ShadyDOM.unobserveChildren(this.shadyChildrenObserver);
          this.shadyChildrenObserver = null;
        } else if (this.nativeChildrenObserver) {
          this.nativeChildrenObserver.disconnect();
          this.nativeChildrenObserver = null;
        }
      }
      this.connected = false;
    }

    schedule() {
      if (!this.scheduled) {
        this.scheduled = true;
        Polymer.Async.run(() => this.flush());
      }
    }

    processMutations(mutations) {
      this.processSlotMutations(mutations);
      this.flush();
    }

    processSlotMutations(mutations) {
      if (mutations) {
        for (let i=0; i < mutations.length; i++) {
          let mutation = mutations[i];
          if (mutation.addedNodes) {
            this.listenSlots(mutation.addedNodes);
          }
          if (mutation.removedNodes) {
            this.unlistenSlots(mutation.removedNodes);
          }
        }
      }
    }

    flush() {
      if (!this.connected) {
        return;
      }
      if (window.ShadyDOM) {
        ShadyDOM.flush();
{'fraction_non_alphanumeric': 0.1262030635759794, 'fraction_numerical': 0.0013555645926528399, 'mean_word_length': 2.2761989342806395, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 26, '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': '6170929', 'n_tokens_mistral': 2156, 'n_tokens_neox': 2099, 'n_words': 432}