mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 15:30:41 +09:00
Push multiple updates in each update event
Refactor HostUpdatesEvent, InstanceDetailsUpdatesEvent, ModUpdatesEvent, ModPackUpdatesEvent and UserUpdatesEvent to have multiple updates of the entities they support in each event. This is intended to make the events capable of syncing the entire list that they represent.
This commit is contained in:
1 parent
f12a9926eb
commit
20330bc2c3
18 files changed
+215
-190
No files matched your search
@@ -31,11 +31,11 @@ export function useInstance(id: number): [InstanceState, ()=>void] {
|
||||
}
|
||||
updateInstance();
|
||||
|
||||
function updateHandler(newInstance: lib.InstanceDetails) {
|
||||
if (newInstance.id !== id) {
|
||||
return;
|
||||
function updateHandler(newInstances: lib.InstanceDetails[]) {
|
||||
const newInstance = newInstances.find(i => i.id === id);
|
||||
if (newInstance) {
|
||||
setInstance({ ...newInstance, present: true });
|
||||
}
|
||||
setInstance({ ...newInstance, present: true });
|
||||
}
|
||||
|
||||
control.instanceUpdate.subscribe(updateHandler);
|
||||
@@ -62,18 +62,20 @@ export function useInstanceList() {
|
||||
useEffect(() => {
|
||||
updateInstanceList();
|
||||
|
||||
function updateHandler(newInstance: lib.InstanceDetails) {
|
||||
function updateHandler(newInstances: lib.InstanceDetails[]) {
|
||||
setInstanceList(oldList => {
|
||||
let newList = oldList.concat();
|
||||
let index = newList.findIndex(s => s.id === newInstance.id);
|
||||
if (newInstance.status !== "deleted") {
|
||||
if (index !== -1) {
|
||||
newList[index] = newInstance;
|
||||
} else {
|
||||
newList.push(newInstance);
|
||||
for (const newInstance of newInstances) {
|
||||
let index = newList.findIndex(s => s.id === newInstance.id);
|
||||
if (newInstance.status !== "deleted") {
|
||||
if (index !== -1) {
|
||||
newList[index] = newInstance;
|
||||
} else {
|
||||
newList.push(newInstance);
|
||||
}
|
||||
} else if (index !== -1) {
|
||||
newList.splice(index, 1);
|
||||
}
|
||||
} else if (index !== -1) {
|
||||
newList.splice(index, 1);
|
||||
}
|
||||
return newList;
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user