<commit_before>import Ember from 'ember';
import appendRange from '../utils/dom/append-range';

const {
  computed,
  run
  } = Ember;

export default Ember.Object.extend({
  _isSustainFactory: true,

  name: '',
  model: null,
  parent: null,
  copy: false,
  expires: null,

  range: null,
  component: null,
  componentName: computed('name', function() {
    return `sustainables/${this.get('name')}`;
  }),

  _hasRenderedOnce: false,
  render() {
    if (!this.range) {
      this.range = {
        firstNode: this.component.element.firstChild,
        lastNode: this.component.element.lastChild
      };
    }

    if (this.parent) {
      appendRange(this.parent, this.range.firstNode, this.range.lastNode);
    }
  },

  _nullMove: null,
  move(to) {

    if (!this.component) {
      this.parent = to.parent;
      if (this._hasRenderedOnce) {
        delete to.parent;
        this.setProperties(to);
      }
      return;
    }

    if (to.parent === null) {
      to.parent = this.component.element;
      this._nullMove = run.next(this, this.move, to);
      return;
    }

    run.cancel(this._nullMove);
    if (this._previousCopy) {
      let parent = this._previousParent;
      let clone = this._previousClone;

      appendRange(to.parent, this.range.firstNode, this.range.lastNode);
      appendRange(parent, clone.firstChild, clone.lastChild);
      this._previousCopy = false;
      this._previousClone = null;
      this._previousParent = null;
    } else {
      appendRange(to.parent, this.range.firstNode, this.range.lastNode);
    }<commit_msg>clarifying code comments for SustainModel<commit_after>import Ember from 'ember';
import appendRange from '../utils/dom/append-range';

const {
  computed,
  run
  } = Ember;

export default Ember.Object.extend({
  _isSustainFactory: true,

  // params exposed via the `{{sustain}}` helper
  name: '',
  model: null,
  copy: false,
  expires: null,

  // the element where the content should currently be rendered
  parent: null,

  // the content
  range: null,

  // reference to the sustain-container component where the content
  // was initially rendered
  component: null,

  // TODO this probably needs to fallback to just `name` if
  //   ember version is < 2.3
  componentName: computed('name', function() {
    return `sustainables/${this.get('name')}`;
  }),

  _hasRenderedOnce: false,

  // sets the range and moves the content into position
  // only called once
  render() {
    if (!this.range) {
      this.range = {
        firstNode: this.component.element.firstChild,
        lastNode: this.component.element.lastChild
      };
    }

    if (this.parent) {
      appendRange(this.parent, this.range.firstNode, this.range.lastNode);
    }
  },

  // when tearing down, we schedule a "null move" if the destination is
  // unknown. This lets us cancel it if a destination becomes known.
  _nullMove: null,

  // called each time the location of parent has changed
  move(to) {

    if (!this.component) {
      this.parent = to.parent;
      if (this._hasRenderedOnce) {
        delete to.parent;
        this.setProperties(to);
      }
      return;
    }

    if (to.parent === null) {
      to.parent = this.component.element;
      this._nullMove = run.next(this, this.move, to);
      return;
    }

    run.cancel(this._nullMove);
    if (this._previousCopy) {
      let parent = this._previousParent;
      let clone = this._previousClone;

      appendRange(to.parent, this.range.firstNode, this.range.lastNode);
      appendRange(parent, clone.firstChild, clone.lastChild);
      this._previousCopy = false;
      this._previousClone = null;
      this._previousParent = null;
    } else {
      appendRange(to.parent, this.range.firstNode, this.range.lastNode);
    }
{'fraction_non_alphanumeric': 0.12264401380408814, 'fraction_numerical': 0.0005309264666843643, 'mean_word_length': 2.6977428851815506, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '1416186', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1164, 'n_words': 286}