Skip to content

Commit

Permalink
Merge pull request #91 from buggregator/bugfix/event-order
Browse files Browse the repository at this point in the history
add initialize event method
  • Loading branch information
butschster committed Dec 3, 2023
2 parents 5bd48c2 + 5775301 commit 0dab43b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugins/events.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default defineNuxtPlugin(() => {
const getAll = () => {
getEventsAll().then((events: ServerEvent<unknown>[]) => {
if (events.length) {
eventsStore.addList(events);
eventsStore.initialize(events);
cachedIdsStore.syncWithActive(events.map(({ uuid }) => uuid));
} else {
// NOTE: clear cached events hardly
Expand Down
5 changes: 4 additions & 1 deletion stores/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ export const useEventStore = defineStore("useEventStore", {
events: [] as ServerEvent<unknown>[],
}),
actions: {
initialize(events: ServerEvent<unknown>[]) {
this.events = events;
},
addList(events: ServerEvent<unknown>[]) {
events.forEach((event) => {
const isExistedEvent = this.events.some((el) => el.uuid === event.uuid);
if (!isExistedEvent) {
this.events.push(event);
this.events.unshift(event);
} else {
this.events = this.events.map((el) => {
if (el.uuid !== event.uuid) {
Expand Down

0 comments on commit 0dab43b

Please sign in to comment.