dc.js
dc.js copied to clipboard
Being friendly to Single Page Frameworks
Usage of JS SPA frameworks like Angular and React are gaining momentum. I know dc has already been used in such environments. Since we will be refactoring this library for v5, we can factor in changes that will help these frameworks further.
Please add to this task any items that would help in this regard. Also, feel free to add people who can contribute to this discussion.
One thing that comes to my mind that reducing global state should help. Even now, the global state is quite limited, however, I will see if it can be reduced further.
@plourenco, any thoughts here?
Hey @gordonwoodhull , @kum-deepak
Thanks for the mention.
Unfortunately, I haven't yet reached a stage where I'm able to identify a lot of tasks related to this issue. Most of my previous work has been around letting dc
handle all of the DOM manipulations.
However, there's something I can perhaps bring up. A future alternative to even further integrate react with dc would be to do the render and redraw on this [react] side and let React decide what to update based on the state that changed. Sticking to use dc
only as a store for state. In other words, generating the HTML templates too. For this to be possible, we would need:
- to update multiple chart properties at once - even though we can always do this as a combination of existing methods;
- most importantly, be notified of every change that happens to a chart internal state (
onChange(state)
).
The react component would then listen to the chart state and update its own internal state (setState
) whenever something changed, triggering a render()
. We could potentially make this even more granular, creating child components for props that update less often. The goal would be having the DOM being surgically updated only in the exact parts that changed.
I've thought about this in the past, but I'm not sure how worth this change would be.
As for the current implementation, it relies on dc.js
to re-render and re-draw whenever props
change. The only improvement I can probably bring up until now is if there is an ability to detect if a chart has already been rendered (and should now redraw)?
Many thanks @plourenco!
This release is targetting to split dc into smaller components with specific responsibilities. That should help with the plans you have. To be specific - data providers and filters will become their own concerns. I will tag you to issues that relate to these areas.
Multiple property changes is planned, see https://github.com/dc-js/dc.js/issues/1707
Let us continue our discussion.
Completed.