diffConfig always returns true if modeBarButtons (array of array) is populated
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 18.3k
- 派生
- 2k
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 28
描述
diffConfig function has bug where it always returns true if modeBarButtons (array of array) is populated. This results in unnecessary re-rendering. The function should check if the array member is array inside a for loop, It should be -
/*
-
simple diff for config - for now, just treat all changes as equivalent
*/
function diffConfig(oldConfig, newConfig) {
var key;for(key in oldConfig) {
if(key.charAt(0) === '_') continue;
var oldVal = oldConfig[key];
var newVal = newConfig[key];
if(oldVal !== newVal) {
if(Lib.isPlainObject(oldVal) && Lib.isPlainObject(newVal)) {
if(diffConfig(oldVal, newVal)) {
return true;
}
} else if(Array.isArray(oldVal) && Array.isArray(newVal)) {
if(oldVal.length !== newVal.length) {
return true;
}for(var i = 0; i < oldVal.length; i++) { if(oldVal[i] !== newVal[i]) { **if(Array.isArray(oldVal[i]) && Array.isArray(newVal[i])){ if(diffConfig(oldVal[i], newVal[i])) { return true; } } else** if(Lib.isPlainObject(oldVal[i]) && Lib.isPlainObject(newVal[i])) { if(diffConfig(oldVal[i], newVal[i])) { return true; } } else { return true; } } } } else { return true; } }}
}
e.g Config object used -
const plotlyConfig: Partial = {
responsive: true,
displaylogo: false,
displayModeBar: true,
doubleClick: false,
showTips: false,
scrollZoom: false,
modeBarButtons: [
[
'select2d',
'lasso2d',
'zoom2d',
'pan2d',
'resetScale2d',
],
],
locale: language,
locales: locales
}
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
定位 diffConfig 函数,并使用包含嵌套 modeBarButtons 数组的 plotlyConfig 示例作为复现案例。比较等价的嵌套数组,并验证未更改的配置不会被报告为不同,从而避免不必要的重新渲染;该 issue 未指定文件或测试。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- data-visualization, frontend
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 55/100