-
Notifications
You must be signed in to change notification settings - Fork 68
[LG-5137]: refactor option updates and improve memory usage #2861
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
Conversation
🦋 Changeset detectedLatest commit: f420e61 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Size Change: -9 B (0%) Total Size: 1.51 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! A few little stylistic thoughts but all nit's so going to approve.
if (!ready) { | ||
return; | ||
} | ||
|
||
return () => { | ||
removeFromGroup(); | ||
}; | ||
if (!groupId) { | ||
return; | ||
} | ||
|
||
addToGroup(groupId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'm totally ok with the early return pattern used here, but this could be simplified to one boolean if you want
if (!ready || !groupId) {
return;
}
addToGroup(groupId);
Or just simply:
if (ready && groupId) {
addToGroup(groupId);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops I should have cleaned these up. I previously had them broken up for debugging purposes. will consolidate / abstract into readable variables where appropriate :)
charts/core/src/Echart/useEchart.ts
Outdated
if (!echartsCoreRef.current) { | ||
return; | ||
} | ||
|
||
const echartsInstance = getEchartsInstance(); | ||
const echartsInstance = echartsInstanceRef.current; | ||
|
||
if ((echartsInstance as EChartsType).group !== groupId) { | ||
(echartsInstance as EChartsType).group = groupId; | ||
echartsCoreRef.current.connect(groupId); | ||
if (!echartsInstance) { | ||
return; | ||
} | ||
|
||
if (echartsInstance.group === groupId) { | ||
return; | ||
} | ||
}, | ||
); | ||
|
||
const removeFromGroup: EChartsInstance['removeFromGroup'] = withInstanceCheck( | ||
() => { | ||
const echartsInstance = getEchartsInstance(); | ||
(echartsInstance as EChartsType).group = ''; | ||
echartsInstance.group = groupId; | ||
echartsCoreRef.current.connect(groupId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Same thought regarding this code being a bit longer than necessary. Feel free to leave be but just wanted to throw out a more condensed alternative.
if (!echartsCoreRef.current) { | |
return; | |
} | |
const echartsInstance = getEchartsInstance(); | |
const echartsInstance = echartsInstanceRef.current; | |
if ((echartsInstance as EChartsType).group !== groupId) { | |
(echartsInstance as EChartsType).group = groupId; | |
echartsCoreRef.current.connect(groupId); | |
if (!echartsInstance) { | |
return; | |
} | |
if (echartsInstance.group === groupId) { | |
return; | |
} | |
}, | |
); | |
const removeFromGroup: EChartsInstance['removeFromGroup'] = withInstanceCheck( | |
() => { | |
const echartsInstance = getEchartsInstance(); | |
(echartsInstance as EChartsType).group = ''; | |
echartsInstance.group = groupId; | |
echartsCoreRef.current.connect(groupId); | |
if (echartsCoreRef.current | |
&& echartsInstanceRef.current | |
&& echartsInstance.group !== groupId) { | |
echartsInstance.group = groupId; | |
echartsCoreRef.current.connect(groupId); | |
} |
charts/core/src/Echart/useEchart.ts
Outdated
if (!container) { | ||
return; | ||
} | ||
|
||
if ( | ||
echartsInstanceRef.current && | ||
echartsInstanceRef.current.getDom() === container && | ||
!echartsInstanceRef.current.isDisposed() | ||
) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Since these conditionals do the same things (return), they could be combined. If it feels too verbose the ref checks can be added to a named variable to make it more readable:
if (!container) { | |
return; | |
} | |
if ( | |
echartsInstanceRef.current && | |
echartsInstanceRef.current.getDom() === container && | |
!echartsInstanceRef.current.isDisposed() | |
) { | |
return; | |
} | |
const isChartRendered = echartsInstanceRef.current && | |
echartsInstanceRef.current.getDom() === container && | |
!echartsInstanceRef.current.isDisposed(); | |
if (!container || isChartRendered) { | |
return; | |
} |
charts/core/src/Echart/useEchart.ts
Outdated
if (!echartsInstance) { | ||
return; | ||
} | ||
|
||
if (echartsInstance.isDisposed()) { | ||
return; | ||
} | ||
|
||
if (echartsInstance) { | ||
(echartsInstance as EChartsType).dispose(); | ||
if (echartsInstance.getDom() !== container) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I keep nitpicking these but again, it's really just a stylistic opinion so feel free to leave be if you prefer what's already there.
if (!echartsInstance ||
echartsInstance.isDisposed() ||
echartsInstance.getDom() !== container
) {
return;
}
Or simply:
if (echartsInstance &&
!echartsInstance.isDisposed() &&
echartsInstance.getDom() === container
) {
activeHandlersMap.clear();
echartsInstance.dispose();
echartsInstanceRef.current = null;
}
✍️ Proposed changes
🎟 Jira ticket: LG-5137
✅ Checklist
For bug fixes, new features & breaking changes
pnpm changeset
and documented my changes🧪 How to test changes