Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new forceRecreation prop #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexanderLukin
Copy link

I faced with an issue when updateChart() method doesn't work properly.
Assume we have a component that needs to pass additional arguments to Chartist listener using bind. Like in this example

import ChartistGraph from 'react-chartist';

export default class ComplexComponent extends React.PureComponent {
  chartDrawHandler(info, data) {
    var pointShape = getPointShape(info[data.index], data);
    // continue
  }

  render() {
    var listener = {
      draw: this.chartDrawHandler.bind(this, info)
    };

    return (
      <ChartistGraph listener={listener}/>
    )
  }
}

In the current implementation, react-chartist component binds additional data to listeners only once, when the new chart instance is created. But in the above example, we need to bind new data to listener each time when render() method of the ComplexComponent is called.

To fix this issue I added new forceRecreation boolean prop to react-chartist component. If this prop has a true value, we unbind all listeners from the existing instance of Chartist graph and create the new instance of it from scratch in each call of updateChart() method.

I faced with an issue when `updateChart()` method doesn't work properly.
Assume we have a component that needs to pass additional arguments to Chartist listener using `bind`. Like in this example

```
export default class ComplexComponent extends React.PureComponent {

  chartDrawHandler(info, data) {
    var pointShape = getPointShape(info[data.index], data);
    // continue
  }

  render() {
    // payload
    var listener = {
          draw: this.chartDrawHandler.bind(this, info)
    };

    return (
      <ChartistGraph listener={listener}/>
    )
  }
}
```

In the current implementation, `react-chartist` component binds additional data to listeners only once, when the new chart instance is created. But in the above example, we need to bind new data to listener each time when `render()` method of the `ComplexComponent` is called.

To fix this issue I added new `forceRecreation` boolean prop to `react-chartist` component. It this prop has a true value, we unbind all listeners from the existing instance of Chartist graph and create the new instance of it from scratch in each call of `updateChart()` method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant