🔨 drop manager pattern for vertical color legend / TAS-799 #4368
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.
Drops the 'manager pattern' for the vertical colour legend component.
Current state
VerticalColorLegend
is a React class component that receives amanager
as a prop<VerticalColorLegend manager={this} />
new VerticalColorLegend({ manager: this })
)Changes
This PR splits the vertical colour legend into two pieces, separating state from rendering:
VerticalColorLegend
is a class with MobX properties that calculates the position of each placed bin and derives its width and height (this instance can be used to get the dimension of a legend)VerticalColorLegendComponent
is a function component that accepts aVerticalColorLegend
instance (and other props) and renders it at a given positionDrawback
Using the manager pattern allows MobX to be smart about dependencies. For example, suppose the width of a legend depends on a subset of props consumed by the legend. MobX only recomputes the width if any of the props change that are actually used to calculate the width. Passing props explicitly means that all props are considered dependencies for all computed MobX state of the legend. As a result, (i) the legend is recomputed and rerendered more often, and (ii) MobX complains about cyclic dependencies more often (and some of the complaints are false positives).
Rendering more often is probably okay since legend components are typically lightweight. The second effect (cyclic dependencies) is mitigated by splitting the component into state and rendering. We don't see any additional cyclic dependencies in this PR, but we get one in the next where the legends of the map chart component are refactored.
I didn't anticipate this when I started working on this and now I'm honestly a bit on the fence about it. I wouldn't mind if we decided to close this PR without merging.