【发布时间】:2019-12-02 20:19:45
【问题描述】:
我有这些代码:
export function updated(list, el) {
const id = list.findIndex(item => item.id === el.id);
return id < 0 ? list.push(el) : list.set(id, el); // chiedere come
}
如何在没有 immutableJS 的情况下替换 list.set(id, el)。
我试过了
list.id = el
list = {
el: id,
}
list[id] = el;
所有这些都是错误的。
你能给我一个建议吗?
更新
根据@code-apprentice 的要求
我不需要函数的不同行为,我需要从一个大项目中删除不可变的。 现在与
list.id = el
list = {
el: id,
}
带有 airbnb 配置的 esLint 说这是 no-return-assign for this line
如果我尝试list[id] = el,我会收到no-return-assign for this line 和no-param-reassign for this line
【问题讨论】:
-
对于您尝试过的每一件事,它们是如何“错误”的?发生了什么,您希望它做些什么不同的事情?
-
@Code-Apprentice 更新
标签: reactjs immutable.js