Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
交互
解决有多个交互的时候,状态不共享的问题:比如 legend 和 slider 的状态不能同时保留。(fix: #5393)
开始使用
解决思路
一些交互的状态是保留在 DOM 上,比如 elementHighlight;一些交互的状态是通过 spec 体现:比如 slider 改变 x 和 y scale 的 domain。这里主要解决第二种交互。
首先用一个全局 store 存储每个交互或者组件对应的 state,该 state 是一个 reducer:是个函数,参数是当前的 options,返回新的 options。
同时提供方法更新每个交互的 reducer,以及根据所有的 reducer 重新渲染的方法 udpate。
当触法更新交互状态的时候,首先调用 setState 方法,然后调用 update 方法。