Skip to content

Commit 00cdf31

Browse files
committed
refactor: send all addon changes at once
1 parent f3a50f4 commit 00cdf31

File tree

1 file changed

+43
-65
lines changed

1 file changed

+43
-65
lines changed

client/src/addon_manager/services/settings.service.ts

Lines changed: 43 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -35,48 +35,38 @@ export const applyAddonSettings = async (
3535
) => {
3636
if (!folder) throw new ConfigError(`Workspace is not open!`);
3737

38-
const promises = [];
38+
const changes = [];
3939
for (const [newKey, newValue] of Object.entries(config)) {
4040
if (Array.isArray(newValue)) {
41-
promises.push(
42-
setConfig([
43-
{
44-
action: "add",
45-
key: newKey,
46-
value: newValue,
47-
uri: folder.uri,
48-
},
49-
])
50-
);
41+
changes.push({
42+
action: "add",
43+
key: newKey,
44+
value: newValue,
45+
uri: folder.uri,
46+
});
5147
} else if (typeof newValue === "object") {
52-
promises.push(
53-
setConfig(
54-
Object.entries(newValue).map(([key, value]) => {
55-
return {
56-
action: "prop",
57-
key: newKey,
58-
prop: key,
59-
value,
60-
uri: folder.uri,
61-
};
62-
})
63-
)
64-
);
65-
} else {
66-
promises.push(
67-
setConfig([
68-
{
69-
action: "set",
48+
changes.push(
49+
...Object.entries(newValue).map(([key, value]) => {
50+
return {
51+
action: "prop",
7052
key: newKey,
71-
value: newValue,
53+
prop: key,
54+
value,
7255
uri: folder.uri,
73-
},
74-
])
56+
};
57+
})
7558
);
59+
} else {
60+
changes.push({
61+
action: "set",
62+
key: newKey,
63+
value: newValue,
64+
uri: folder.uri,
65+
});
7666
}
7767
}
7868

79-
return Promise.all(promises);
69+
return await setConfig(changes);
8070
};
8171

8272
export const revokeAddonSettings = async (
@@ -85,7 +75,7 @@ export const revokeAddonSettings = async (
8575
) => {
8676
if (!folder) throw new ConfigError(`Workspace is not open!`);
8777

88-
const promises = [];
78+
const changes = [];
8979
for (const [newKey, newValue] of Object.entries(config)) {
9080
const currentValue = await getConfig(newKey, folder.uri);
9181

@@ -94,46 +84,34 @@ export const revokeAddonSettings = async (
9484
const notAddon = currentValue.filter(
9585
(oldValue) => !newValue.includes(oldValue)
9686
);
97-
promises.push(
98-
setConfig([
99-
{
100-
action: "set",
101-
key: newKey,
102-
value: notAddon,
103-
uri: folder.uri,
104-
},
105-
])
106-
);
87+
changes.push({
88+
action: "set",
89+
key: newKey,
90+
value: notAddon,
91+
uri: folder.uri,
92+
});
10793
} else if (typeof newValue === "object") {
10894
for (const objectKey of Object.keys(newValue)) {
10995
delete currentValue[objectKey];
11096
}
11197
// If object is now empty, delete it
11298
if (Object.keys(currentValue).length === 0) {
113-
promises.push(
114-
setConfig([
115-
{
116-
action: "set",
117-
key: newKey,
118-
value: undefined,
119-
uri: folder.uri,
120-
},
121-
])
122-
);
99+
changes.push({
100+
action: "set",
101+
key: newKey,
102+
value: undefined,
103+
uri: folder.uri,
104+
});
123105
} else {
124-
promises.push(
125-
setConfig([
126-
{
127-
action: "set",
128-
key: newKey,
129-
value: currentValue,
130-
uri: folder.uri,
131-
},
132-
])
133-
);
106+
changes.push({
107+
action: "set",
108+
key: newKey,
109+
value: currentValue,
110+
uri: folder.uri,
111+
});
134112
}
135113
}
136114
}
137115

138-
return Promise.all(promises);
116+
return await setConfig(changes);
139117
};

0 commit comments

Comments
 (0)