mirror of
https://github.com/zhigang1992/devhub.git
synced 2026-06-15 09:58:29 +08:00
Cleanup unused subscriptions on a single action instead of multiple dispatches
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createAction } from '../helpers'
|
||||
|
||||
export function deleteColumnSubscription(columnId: string) {
|
||||
return createAction('DELETE_COLUMN_SUBSCRIPTION', columnId)
|
||||
export function deleteColumnSubscriptions(subscriptionIds: string[]) {
|
||||
return createAction('DELETE_COLUMN_SUBSCRIPTIONS', subscriptionIds)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ export const columnsReducer: Reducer<State> = (
|
||||
if (draft.byId) delete draft.byId[action.payload]
|
||||
})
|
||||
|
||||
case 'DELETE_COLUMN_SUBSCRIPTION':
|
||||
case 'DELETE_COLUMN_SUBSCRIPTIONS':
|
||||
return immer(state, draft => {
|
||||
if (!(draft.allIds && draft.byId)) return
|
||||
|
||||
@@ -63,7 +63,7 @@ export const columnsReducer: Reducer<State> = (
|
||||
|
||||
draft.byId![columnId].subscriptionIds = draft.byId![
|
||||
columnId
|
||||
].subscriptionIds.filter(id => id !== action.payload)
|
||||
].subscriptionIds.filter(id => !action.payload.includes(id))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -40,12 +40,16 @@ export const subscriptionsReducer: Reducer<State> = (
|
||||
)
|
||||
})
|
||||
|
||||
case 'DELETE_COLUMN_SUBSCRIPTION':
|
||||
case 'DELETE_COLUMN_SUBSCRIPTIONS':
|
||||
return immer(state, draft => {
|
||||
if (draft.allIds)
|
||||
draft.allIds = draft.allIds.filter(id => id !== action.payload)
|
||||
draft.allIds = draft.allIds.filter(id => !action.payload.includes(id))
|
||||
|
||||
if (draft.byId) delete draft.byId[action.payload]
|
||||
if (!draft.byId) return
|
||||
|
||||
action.payload.forEach(id => {
|
||||
delete draft.byId[id]
|
||||
})
|
||||
})
|
||||
|
||||
case 'REPLACE_COLUMNS':
|
||||
|
||||
@@ -28,11 +28,7 @@ function* cleanupSubscriptions() {
|
||||
usedSubscriptionIds,
|
||||
)
|
||||
|
||||
yield all(
|
||||
unusedSubscriptionIds.map(subscriptionId =>
|
||||
put(actions.deleteColumnSubscription(subscriptionId)),
|
||||
),
|
||||
)
|
||||
yield put(actions.deleteColumnSubscriptions(unusedSubscriptionIds))
|
||||
}
|
||||
|
||||
export function* subscriptionsSagas() {
|
||||
|
||||
Reference in New Issue
Block a user