<commit_before>import Ember from 'ember'
const {
  Component,
  deprecate,
  on,
  run: {
    debounce,
    scheduleOnce
  },
  typeOf
} = Ember
import PropTypeMixin, {PropTypes} from 'ember-prop-types'

const debouncePeriod = 150

export default Component.extend(PropTypeMixin, {

  // == Component properties ==================================================

  classNames: ['frost-scroll'],

  // == State properties ======================================================

  propTypes: {
    hook: PropTypes.string
  },

  // == Events ================================================================

  /* eslint-disable complexity */
  initializeScroll: on('didInsertElement', function () {
    scheduleOnce('afterRender', this, () => {
      window.Ps.initialize(this.$()[0])
    })

    if (typeOf(this.onScrollUp) === 'function') {
      this.$().on('ps-scroll-up', () => {
        debounce(this, this.onScrollUp, debouncePeriod, true)
      })
    }

    if (typeOf(this.onScrollDown) === 'function') {
      this.$().on('ps-scroll-down', () => {
        debounce(this, this.onScrollDown, debouncePeriod, true)
      })
    }

    if (typeOf(this.onScrollYStart) === 'function') {
      this.$().on('ps-y-reach-start', () => {
        debounce(this, this.onScrollYStart, debouncePeriod, true)
      })
    }

    if (typeOf(this.onScrollYEnd) === 'function') {
      this.$().on('ps-y-reach-end', () => {
        debounce(this, this.onScrollYEnd, debouncePeriod, true)
      })
    }

    if (typeOf(this.attrs['on-scroll-y-end']) === 'function') {
      deprecate('on-scroll-y-end has been deprecated in favor of onScrollYEnd',
        false,
        {
          id: 'frost-debug.deprecate-on-scroll-y-end',
          until: '1.0.0',
          url: 'http://ciena-frost.github.io/ember-frost-core/#/scroll'
        }
      )
      this.$().on('ps-y-reach-end', () => {
        debounce(this, this['on-scroll-y-end'], debouncePeriod, true)
      })
    }
  })
  /* eslint-enable complexity */

})<commit_msg>Make sure to unbind events<commit_after>import Ember from 'ember'
const {
  Component,
  deprecate,
  on,
  run: {
    debounce,
    scheduleOnce
  },
  typeOf
} = Ember
import PropTypeMixin, {PropTypes} from 'ember-prop-types'

const debouncePeriod = 150

export default Component.extend(PropTypeMixin, {

  // == Component properties ==================================================

  classNames: ['frost-scroll'],

  // == State properties ======================================================

  propTypes: {
    hook: PropTypes.string
  },

  // == Events ================================================================

  /* eslint-disable complexity */
  initializeScroll: on('didInsertElement', function () {
    scheduleOnce('afterRender', this, () => {
      window.Ps.initialize(this.$()[0])
    })

    this._legacyScrollYEndHandler = () => {
      debounce(this, this['on-scroll-y-end'], debouncePeriod, true)
    }

    this._scrollDownHandler = () => {
      debounce(this, this.onScrollDown, debouncePeriod, true)
    }

    this._scrollUpHandler = () => {
      debounce(this, this.onScrollUp, debouncePeriod, true)
    }

    this._scrollYEndHandler = () => {
      debounce(this, this.onScrollYEnd, debouncePeriod, true)
    }

    this._scrollYStartHandler = () => {
      debounce(this, this.onScrollYStart, debouncePeriod, true)
    }

    if (typeOf(this.onScrollUp) === 'function') {
      this.$().on('ps-scroll-up', this._scrollUpHandler)
    }

    if (typeOf(this.onScrollDown) === 'function') {
      this.$().on('ps-scroll-down', this._scrollDownHandler)
    }

    if (typeOf(this.onScrollYStart) === 'function') {
      this.$().on('ps-y-reach-start', this._scrollYStartHandler)
    }

    if (typeOf(this.onScrollYEnd) === 'function') {
      this.$().on('ps-y-reach-end', this._scrollYEndHandler)
    }

    if (typeOf(this.attrs['on-scroll-y-end']) === 'function') {
      deprecate('on-scroll-y-end has been deprecated in favor of onScrollYEnd',
        false,
        {
          id: 'frost-debug.deprecate-on-scroll-y-end',
          until: '1.0.0',
          url: 'http://ciena-frost.github.io/ember-frost-core/#/scroll'
        }
      )
      this.$().on('ps-y-reach-end', this._legacyScrollYEndHandler)
    }
  }),
  /* eslint-enable complexity */

  cleanup: on('willDestroyElement', function () {
    this.$().off('ps-scroll-down', this._scrollDownHandler)
    this.$().off('ps-scroll-up', this._scrollUpHandler)
    this.$().off('ps-y-reach-end', this._legacyScrollYEndHandler)
    this.$().off('ps-y-reach-end', this._scrollYEndHandler)
    this.$().off('ps-y-reach-start', this._scrollYStartHandler)
  })
})
{'fraction_non_alphanumeric': 0.2352437981180496, 'fraction_numerical': 0.0029940119760479044, 'mean_word_length': 3.0704960835509136, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5606767', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1468, 'n_words': 225}