import React from 'react' import PropTypes from 'prop-types' import sideEffect from './side-effect' class Head extends React.Component { static contextTypes = { headManager: PropTypes.object } render () { return null } } export function defaultHead () { return [] } function reduceComponents (components) { return components .map((c) => c.props.children) .map((children) => React.Children.toArray(children)) .reduce((a, b) => a.concat(b), []) .reverse() .concat(...defaultHead()) .filter((c) => !!c) .filter(unique()) .reverse() .map((c) => { const className = (c.className ? c.className + ' ' : '') + 'next-head' return React.cloneElement(c, { className }) }) } function mapOnServer (head) { return head } function onStateChange (head) { if (this.context && this.context.headManager) { this.context.headManager.updateHead(head) } } const METATYPES = ['name', 'httpEquiv', 'charSet', 'itemProp', 'property'] // returns a function for filtering head child elements // which shouldn't be duplicated, like