Skip to content

Commit

Permalink
fix: last typescript errors due to pinia getters not being allowed to…
Browse files Browse the repository at this point in the history
… mutate state
  • Loading branch information
valeriansaliou committed Nov 3, 2023
1 parent d1ea49a commit 4d3ac7f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 44 deletions.
14 changes: 6 additions & 8 deletions src/store/tables/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ const $activity = defineStore("activity", {
};
},

getters: {
getActivity: function () {
return (jid: JID): ActivityEntry => {
return this.assert(jid);
};
}
},

actions: {
assert(jid: JID): ActivityEntry {
const jidString = jid.toString();
Expand All @@ -75,6 +67,12 @@ const $activity = defineStore("activity", {
return this.entries[jidString];
},

getActivity(jid: JID): ActivityEntry {
// Notice: pseudo-getter, which needs to be defined as an action since \
// it might mutate the state (as we are asserting).
return this.assert(jid);
},

setActivity(jid: JID, status?: UserActivity): ActivityEntry {
// Assert activity
const activity = this.assert(jid);
Expand Down
14 changes: 6 additions & 8 deletions src/store/tables/avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ const $avatar = defineStore("avatar", {
};
},

getters: {
getAvatarDataUrl: function () {
return (jid: JID): AvatarDataURL | undefined => {
return this.assert(jid);
};
}
},

actions: {
events(): ReturnType<typeof mitt> {
// Return event bus
Expand All @@ -81,6 +73,12 @@ const $avatar = defineStore("avatar", {
return this.entries[jid.toString()];
},

getAvatarDataUrl(jid: JID): AvatarDataURL | undefined {
// Notice: pseudo-getter, which needs to be defined as an action since \
// it might mutate the state (as we are asserting).
return this.assert(jid);
},

async load(jid: JID): Promise<void> {
const jidString = jid.toString();

Expand Down
38 changes: 18 additions & 20 deletions src/store/tables/inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,6 @@ const $inbox = defineStore("inbox", {
};
},

getters: {
getMessages: function () {
return (roomId: RoomID): Array<InboxEntryMessage> => {
return this.assert(roomId).messages.list;
};
},

getMessage: function () {
return (roomId: RoomID, id: string): InboxEntryMessage | void => {
return this.assert(roomId).messages.byId[id] || undefined;
};
},

getStates: function () {
return (roomId: RoomID): InboxEntryStates => {
return this.assert(roomId).states;
};
}
},

actions: {
events(): ReturnType<typeof mitt> {
// Return event bus
Expand Down Expand Up @@ -149,6 +129,24 @@ const $inbox = defineStore("inbox", {
return entries[roomId];
},

getMessages(roomId: RoomID): Array<InboxEntryMessage> {
// Notice: pseudo-getter, which needs to be defined as an action since \
// it might mutate the state (as we are asserting).
return this.assert(roomId).messages.list;
},

getMessage(roomId: RoomID, id: string): InboxEntryMessage | void {
// Notice: pseudo-getter, which needs to be defined as an action since \
// it might mutate the state (as we are asserting).
return this.assert(roomId).messages.byId[id] || undefined;
},

getStates(roomId: RoomID): InboxEntryStates {
// Notice: pseudo-getter, which needs to be defined as an action since \
// it might mutate the state (as we are asserting).
return this.assert(roomId).states;
},

insertCoreMessages(roomId: RoomID, messages: CoreMessage[]): boolean {
return this.insertMessages(
roomId,
Expand Down
14 changes: 6 additions & 8 deletions src/store/tables/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ const $profile = defineStore("profile", {
};
},

getters: {
getProfile: function () {
return (jid: JID): ProfileEntry => {
return this.assert(jid);
};
}
},

actions: {
assert(jid: JID): ProfileEntry {
const jidString = jid.toString();
Expand All @@ -136,6 +128,12 @@ const $profile = defineStore("profile", {
return this.entries[jidString];
},

getProfile(jid: JID): ProfileEntry {
// Notice: pseudo-getter, which needs to be defined as an action since \
// it might mutate the state (as we are asserting).
return this.assert(jid);
},

async load(jid: JID, reload = false): Promise<ProfileEntry> {
// Assert profile data
const profile = this.assert(jid);
Expand Down

0 comments on commit 4d3ac7f

Please sign in to comment.