优化:使用Set避免数据重复

pull/1754/MERGE
ChenX 3 years ago
parent c2d468662f
commit 1d7d1eeb22

@ -166,7 +166,7 @@ export function AppendUserInfo(d: Data | any)
d.uid = localStorage.getItem(StoreageKeys.Uid); d.uid = localStorage.getItem(StoreageKeys.Uid);
} }
export function Entitys2Data(ents: Entity[]): Data export function Entitys2Data(ents: Iterable<Entity>): Data
{ {
let d: Data = { Entitys: [], Materials: [] }; let d: Data = { Entitys: [], Materials: [] };
for (let e of ents) for (let e of ents)

@ -58,9 +58,9 @@ export class SyncDataReactor
{ {
if (!userConfig.synchronousEnable) return; if (!userConfig.synchronousEnable) return;
let createEntitys: Entity[] = []; let createEntitys = new Set<Entity>();
let changeEntitys: Entity[] = []; let changeEntitys = new Set<Entity>();
let deleteEntitys: Entity[] = []; let deleteEntitys = new Set<Entity>();
for (let [h, hs] of historyRec.HistoryList) for (let [h, hs] of historyRec.HistoryList)
{ {
@ -73,13 +73,13 @@ export class SyncDataReactor
{ {
let ent = data.RemoveObject as Entity; let ent = data.RemoveObject as Entity;
if (IsSyncEntity(ent)) if (IsSyncEntity(ent))
deleteEntitys.push(ent); deleteEntitys.add(ent);
} }
else if (data instanceof CreateObjectData) else if (data instanceof CreateObjectData)
{ {
let ent = data.CreateObject as Entity; let ent = data.CreateObject as Entity;
if (IsSyncEntity(ent)) if (IsSyncEntity(ent))
createEntitys.push(ent); createEntitys.add(ent);
} }
} }
} }
@ -93,20 +93,20 @@ export class SyncDataReactor
{ {
if ((isUndo ? h.undoData : h.redoData) instanceof CreateObjectData) if ((isUndo ? h.undoData : h.redoData) instanceof CreateObjectData)
{ {
createEntitys.push(e); createEntitys.add(e);
break; break;
} }
else else
{ {
if (e.IsErase) if (e.IsErase)
deleteEntitys.push(e); deleteEntitys.add(e);
else else
changeEntitys.push(e); changeEntitys.add(e);
} }
} }
} }
if (createEntitys.length > 0 || deleteEntitys.length > 0 || changeEntitys.length > 0) if (createEntitys.size > 0 || deleteEntitys.size > 0 || changeEntitys.size > 0)
{ {
let d: IncrementData = { Add: Entitys2Data(createEntitys), Change: Entitys2Data(changeEntitys), Delete: Entitys2Data(deleteEntitys) }; let d: IncrementData = { Add: Entitys2Data(createEntitys), Change: Entitys2Data(changeEntitys), Delete: Entitys2Data(deleteEntitys) };
AppendUserInfo(d); AppendUserInfo(d);

Loading…
Cancel
Save