import React from 'react'
import hashsum from 'hash-sum'

export default function phash(_props) {
  const props = Object.keys(_props).reduce((acc, key) => {
    const prop = _props[key]

    if (key == '__flint')
      return acc

    if (prop instanceof Object && prop.hashCode)
      acc[key] = prop.hashCode()

    // TODO: traverse children
    else if (React.isValidElement(prop))
      acc[key] = prop.key

    else
      acc[key] = prop

    return acc
  }, {})

  return hashsum(props)
}

import React from 'react'
import hashsum from 'hash-sum'

const disableHashing = /\?nohash/.test(window.location.search)

export default function phash(_props) {
  if (disableHashing)
    return hashsum(Math.random())

  const props = Object.keys(_props).reduce((acc, key) => {
    const prop = _props[key]

    if (key == '__flint')
      return acc

    if (prop instanceof Object && prop.hashCode)
      acc[key] = prop.hashCode()

    // TODO: traverse children
    else if (React.isValidElement(prop))
      acc[key] = prop.key

    else
      acc[key] = prop

    return acc
  }, {})

  return hashsum(props)
}

add disable option