/**
 * Mixin for history.
 * @mixin ApHistoryMixin
 */

'use strict'

import React, {PropTypes as types} from 'react'
import apHistory from 'apeman-brws-history'
import defaults from 'defaults'

/** @lends ApHistoryMixin */
let ApHistoryMixin = {

  // --------------------
  // Custom
  // --------------------
  $apHistoryMixed: true,

  // --------------------
  // Specs
  // --------------------

  // --------------------
  // Lifecycle
  // --------------------

  componentWillMount () {
    const s = this
    let noop = () => undefined
    defaults(s, {
      historyDidPop: noop
    })
  },

  componentDidMount () {
    const s = this
    apHistory.onPop(s.historyDidPop)
  },

  componentWillUnmount () {
    const s = this
    apHistory.offPop(s.historyDidPop)
  }

}

export default Object.freeze(ApHistoryMixin)
