<commit_before>import { boundMethod } from 'autobind-decorator'
import PT from 'prop-types'
import * as React from 'react'
import embed from 'vega-embed'

// TODO: refactor to use hooks
class Vega extends React.Component {
  static propTypes = {
    // eslint-disable-next-line react/forbid-prop-types
    spec: PT.object.isRequired,
  }

  constructor() {
    super()
    this.state = { el: null }
  }

  componentDidMount() {
    this.embed()
  }

  componentDidUpdate(prevProps, prevState) {
    if (prevState.el !== this.state.el || prevProps.spec !== this.props.spec) this.embed()
  }

  @boundMethod
  setEl(el) {
    this.setState({ el })
  }

  embed() {
    if (this.state.el) embed(this.state.el, this.props.spec, { actions: false })
  }

  render() {
    const { spec, ...props } = this.props<commit_msg>Add "Save as" to Vega dropdown menu (#2235)<commit_after>import { boundMethod } from 'autobind-decorator'
import PT from 'prop-types'
import * as React from 'react'
import embed from 'vega-embed'

const VEGA_OPTIONS = {
  actions: {
    compiled: false,
    editor: false,
    export: true,
    source: false,
  },
}

// TODO: refactor to use hooks
class Vega extends React.Component {
  static propTypes = {
    // eslint-disable-next-line react/forbid-prop-types
    spec: PT.object.isRequired,
  }

  constructor() {
    super()
    this.state = { el: null }
  }

  componentDidMount() {
    this.embed()
  }

  componentDidUpdate(prevProps, prevState) {
    if (prevState.el !== this.state.el || prevProps.spec !== this.props.spec) this.embed()
  }

  @boundMethod
  setEl(el) {
    this.setState({ el })
  }

  embed() {
    if (this.state.el) embed(this.state.el, this.props.spec, VEGA_OPTIONS)
  }

  render() {
    const { spec, ...props } = this.props
{'fraction_non_alphanumeric': 0.14366197183098592, 'fraction_numerical': 0.0022535211267605635, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '407555', 'n_tokens_mistral': 623, 'n_tokens_neox': 605, 'n_words': 142}