/** * Creates a function that gets run every `x` milliseconds. This function is a wrapper * around `window.setInterval`. There are a few reasons to use this one instead though. * 1. It gets cleared via {@link Component#clearInterval} when * {@link Component#dispose} gets called. * 2. The function callback will be a {@link Component~GenericCallback} * * @param {Component~GenericCallback} fn * The function to run every `x` seconds. * * @param {number} interval * Execute the specified function every `x` milliseconds. * * @return {number} * Returns an id that can be used to identify the interval. It can also be be used in * {@link Component#clearInterval} to clear the interval. * * @listens Component#dispose * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval} */ setInterval(fn, interval) { fn = Fn.bind(this, fn); const intervalId = window.setInterval(fn, interval); const disposeFn = () => this.clearInterval(intervalId); disposeFn.guid = `vjs-interval-${intervalId}`; this.on('dispose', disposeFn); return intervalId; }
componentDidMount() { window.setInterval( () => this.setState({treemapData: this._getRandomData()}), 5000 ); }
componentDidMount() { window.setInterval( () => this.setState({tableData: this._getTableData()}), 5000 ); }