[v1.3] 修正React重绘问题 (Popup) by cyfung1031 · Pull Request #1181 · scriptscat/scriptcat

const updateList = (list: ScriptMenu[], update: TUpdateEntryFn, options: TUpdateListOption | undefined) => {
// 如果更新跟当前 list 的子项无关,则不用更改 list 的物件参考
const newList = [];
let changed = false;
for (let i = 0; i < list.length; i++) {
const oldItem = list[i];
const newItem = update(oldItem); // 如没有更改,物件参考会保持一致
if (newItem !== oldItem) changed = true;
if (newItem) {
newList.push(newItem);
}
}
if (options?.sort) {
newList.sort(scriptListSorter);
}
if (!changed && list.map((e) => e.uuid).join(",") !== newList.map((e) => e.uuid).join(",")) {
// 单一项未有改变,但因为 sort值改变 而改变了次序
changed = true;
}
return changed ? newList : list; // 如子项没任何变化,则返回原list参考
};