Skip to content

Commit 2166742

Browse files
committed
Pushing some more tx changes to CharmManager
1 parent c090045 commit 2166742

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

packages/charm/src/manager.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ export class CharmManager {
185185
const newPinnedCharms = filterOutEntity(this.pinnedCharms, charmId);
186186

187187
if (newPinnedCharms.length !== this.pinnedCharms.get().length) {
188-
this.pinnedCharms.set(newPinnedCharms);
188+
const tx = this.runtime.edit();
189+
const pinnedCharms = this.pinnedCharms.withTx(tx);
190+
pinnedCharms.set(newPinnedCharms);
191+
await tx.commit();
189192
await this.runtime.idle();
190193
return true;
191194
}
@@ -243,7 +246,10 @@ export class CharmManager {
243246

244247
async emptyTrash() {
245248
await this.syncCharms(this.trashedCharms);
246-
this.trashedCharms.set([]);
249+
const tx = this.runtime.edit();
250+
const trashedCharms = this.trashedCharms.withTx(tx);
251+
trashedCharms.set([]);
252+
await tx.commit();
247253
await this.runtime.idle();
248254
return true;
249255
}
@@ -861,13 +867,19 @@ export class CharmManager {
861867

862868
// Move to trash if not already there
863869
if (!this.trashedCharms.get().some((c) => isSameEntity(c, id))) {
864-
this.trashedCharms.push(charm);
870+
const tx = this.runtime.edit();
871+
const trashedCharms = this.trashedCharms.withTx(tx);
872+
trashedCharms.push(charm);
873+
await tx.commit();
865874
}
866875

867876
// Remove from main list
868877
const newCharms = filterOutEntity(this.charms, id);
869878
if (newCharms.length !== this.charms.get().length) {
870-
this.charms.set(newCharms);
879+
const tx = this.runtime.edit();
880+
const charms = this.charms.withTx(tx);
881+
charms.set(newCharms);
882+
await tx.commit();
871883
await this.runtime.idle();
872884
return true;
873885
}
@@ -885,7 +897,9 @@ export class CharmManager {
885897
// Remove from trash if present
886898
const newTrashedCharms = filterOutEntity(this.trashedCharms, id);
887899
if (newTrashedCharms.length !== this.trashedCharms.get().length) {
888-
this.trashedCharms.set(newTrashedCharms);
900+
const tx = this.runtime.edit();
901+
this.trashedCharms.withTx(tx).set(newTrashedCharms);
902+
tx.commit();
889903
await this.runtime.idle();
890904
return true;
891905
}

0 commit comments

Comments
 (0)