chore: add removeDuplicateEntry dispatcher to history store (#2955)

This commit is contained in:
Akash K 2023-03-30 15:13:25 +05:30 committed by GitHub
parent cc802b1e9f
commit dbb45e7253
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -163,6 +163,20 @@ const RESTHistoryDispatchers = defineDispatchers({
}),
}
},
// only used for history.sync.ts to prevent double insertion of history entries from storeSync and Subscriptions
removeDuplicateEntry(currentVal: RESTHistoryType, { id }: { id: string }) {
const entries = currentVal.state.filter((e) => e.id === id)
if (entries.length == 2) {
const indexToRemove = currentVal.state.findIndex((e) => e.id === id)
currentVal.state.splice(indexToRemove, 1)
}
return {
state: currentVal.state,
}
},
})
const GQLHistoryDispatchers = defineDispatchers({
@ -212,6 +226,20 @@ const GQLHistoryDispatchers = defineDispatchers({
}),
}
},
// only used for history.sync.ts to prevent double insertion of history entries from storeSync and Subscriptions
removeDuplicateEntry(currentVal: GraphqlHistoryType, { id }: { id: string }) {
const entries = currentVal.state.filter((e) => e.id === id)
if (entries.length == 2) {
const indexToRemove = currentVal.state.findIndex((e) => e.id === id)
currentVal.state.splice(indexToRemove, 1)
}
return {
state: currentVal.state,
}
},
})
export const restHistoryStore = new DispatchingStore(
@ -297,6 +325,20 @@ export function toggleGraphqlHistoryEntryStar(entry: GQLHistoryEntry) {
})
}
export function removeDuplicateRestHistoryEntry(id: string) {
restHistoryStore.dispatch({
dispatcher: "removeDuplicateEntry",
payload: { id },
})
}
export function removeDuplicateGraphqlHistoryEntry(id: string) {
graphqlHistoryStore.dispatch({
dispatcher: "removeDuplicateEntry",
payload: { id },
})
}
// Listen to completed responses to add to history
completedRESTResponse$.subscribe((res) => {
if (res !== null) {