<commit_before>import React, { PropTypes } from 'react'
import PaddedList from 'components/PaddedList'
import ArtistItem from '../ArtistItem'
const ROW_HEIGHT = 40

class ArtistList extends React.Component {
  static propTypes = {
    artists: PropTypes.object.isRequired,
    songs: PropTypes.object.isRequired,
    queuedSongIds: PropTypes.array.isRequired,
    expandedArtists: PropTypes.array.isRequired,
    scrollTop: PropTypes.number.isRequired,
    width: PropTypes.number.isRequired,
    height: PropTypes.number.isRequired,
    paddingTop: PropTypes.number.isRequired,
    paddingBottom: PropTypes.number.isRequired,
    // actions
    queueSong: PropTypes.func.isRequired,
    scrollArtists: PropTypes.func.isRequired,
    toggleArtistExpanded: PropTypes.func.isRequired,
  }

  render () {
    if (this.props.artists.result.length === 0) return null

    return (
      <PaddedList
        width={this.props.width}
        height={this.props.height}
        scrollTop={this.props.scrollTop}
        paddingTop={this.props.paddingTop}
        paddingBottom={this.props.paddingBottom}
        rowCount={this.props.artists.result.length}
        rowHeight={this.rowHeight}
        rowRenderer={this.rowRenderer}
        onScroll={this.handleScroll}
        onRef={this.setRef}
      />
    )
  }

  componentDidUpdate(prevProps) {
    if (!this.ref) return
    // nuclear option
    this.ref.recomputeRowHeights()
    this.ref.forceUpdate()
  }

  rowRenderer = ({index, key, style}) => {
    const { artists, songs, expandedArtists } = this.props
    const artist = artists.entities[artists.result[index]]

    return (
      <ArtistItem
        songs={songs}
        songIds={artist.songIds} // "children"
        queuedSongIds={this.props.queuedSongIds}
        name={artist.name}
        isExpanded={expandedArtists.indexOf(artist.artistId) !== -1}
        onArtistClick={() => this.handleArtistClick(artist.artistId)}
        onSongClick={this.props.queueSong}
        key={key}
        style={style}
      />
    )
  }

  rowHeight = ({index}) => {
    const artistId = this.props.artists.result[index]
    let rows = 1

    if (this.props.expandedArtists.indexOf(artistId) !== -1) {
      rows += this.props.artists.entities[artistId].songIds.length
    }

    return rows * ROW_HEIGHT
  }

  handleArtistClick = (artistId) => {
    this.props.toggleArtistExpanded(artistId)

    this.ref.recomputeRowHeights()
    this.ref.forceUpdate()
  }

  handleScroll = ({ scrollTop }) => {
    this.props.scrollArtists(scrollTop)
  }

  setRef = (ref) => {
    this.ref = ref
  }
}

export default ArtistList<commit_msg>Remove redundant forced updates<commit_after>import React, { PropTypes } from 'react'
import PaddedList from 'components/PaddedList'
import ArtistItem from '../ArtistItem'
const ROW_HEIGHT = 40

class ArtistList extends React.Component {
  static propTypes = {
    artists: PropTypes.object.isRequired,
    songs: PropTypes.object.isRequired,
    queuedSongIds: PropTypes.array.isRequired,
    expandedArtists: PropTypes.array.isRequired,
    scrollTop: PropTypes.number.isRequired,
    width: PropTypes.number.isRequired,
    height: PropTypes.number.isRequired,
    paddingTop: PropTypes.number.isRequired,
    paddingBottom: PropTypes.number.isRequired,
    // actions
    queueSong: PropTypes.func.isRequired,
    scrollArtists: PropTypes.func.isRequired,
    toggleArtistExpanded: PropTypes.func.isRequired,
  }

  render () {
    if (this.props.artists.result.length === 0) return null

    return (
      <PaddedList
        width={this.props.width}
        height={this.props.height}
        scrollTop={this.props.scrollTop}
        paddingTop={this.props.paddingTop}
        paddingBottom={this.props.paddingBottom}
        rowCount={this.props.artists.result.length}
        rowHeight={this.rowHeight}
        rowRenderer={this.rowRenderer}
        onScroll={this.handleScroll}
        onRef={this.setRef}
      />
    )
  }

  componentDidUpdate(prevProps) {
    if (!this.ref) return
    // nuclear option
    this.ref.recomputeRowHeights()
    this.ref.forceUpdate()
  }

  rowRenderer = ({index, key, style}) => {
    const { artists, songs, expandedArtists } = this.props
    const artist = artists.entities[artists.result[index]]

    return (
      <ArtistItem
        songs={songs}
        songIds={artist.songIds} // "children"
        queuedSongIds={this.props.queuedSongIds}
        name={artist.name}
        isExpanded={expandedArtists.indexOf(artist.artistId) !== -1}
        onArtistClick={() => this.handleArtistClick(artist.artistId)}
        onSongClick={this.props.queueSong}
        key={key}
        style={style}
      />
    )
  }

  rowHeight = ({index}) => {
    const artistId = this.props.artists.result[index]
    let rows = 1

    if (this.props.expandedArtists.indexOf(artistId) !== -1) {
      rows += this.props.artists.entities[artistId].songIds.length
    }

    return rows * ROW_HEIGHT
  }

  handleArtistClick = (artistId) => {
    this.props.toggleArtistExpanded(artistId)
  }

  handleScroll = ({ scrollTop }) => {
    this.props.scrollArtists(scrollTop)
  }

  setRef = (ref) => {
    this.ref = ref
  }
}

export default ArtistList
{'fraction_non_alphanumeric': 0.120944519101555, 'fraction_numerical': 0.002303705125743905, 'mean_word_length': 3.035631293570875, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '4039681', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1642, 'n_words': 260}