From edce96a9a451faeb165d24f83636abbc51265ca4 Mon Sep 17 00:00:00 2001 From: Bruno Lemos Date: Wed, 5 Dec 2018 19:06:15 -0200 Subject: [PATCH] Cleanup unused subscriptions on a single action instead of multiple dispatches --- packages/components/src/redux/actions/subscriptions.ts | 4 ++-- packages/components/src/redux/reducers/columns.ts | 4 ++-- .../components/src/redux/reducers/subscriptions.ts | 10 +++++++--- packages/components/src/redux/sagas/subscriptions.ts | 6 +----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/components/src/redux/actions/subscriptions.ts b/packages/components/src/redux/actions/subscriptions.ts index 8453806b..19a1a75c 100644 --- a/packages/components/src/redux/actions/subscriptions.ts +++ b/packages/components/src/redux/actions/subscriptions.ts @@ -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) } diff --git a/packages/components/src/redux/reducers/columns.ts b/packages/components/src/redux/reducers/columns.ts index bcc3b738..6a5882b9 100644 --- a/packages/components/src/redux/reducers/columns.ts +++ b/packages/components/src/redux/reducers/columns.ts @@ -54,7 +54,7 @@ export const columnsReducer: Reducer = ( 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 = ( draft.byId![columnId].subscriptionIds = draft.byId![ columnId - ].subscriptionIds.filter(id => id !== action.payload) + ].subscriptionIds.filter(id => !action.payload.includes(id)) }) }) diff --git a/packages/components/src/redux/reducers/subscriptions.ts b/packages/components/src/redux/reducers/subscriptions.ts index ba80cbd2..710adb60 100644 --- a/packages/components/src/redux/reducers/subscriptions.ts +++ b/packages/components/src/redux/reducers/subscriptions.ts @@ -40,12 +40,16 @@ export const subscriptionsReducer: Reducer = ( ) }) - 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': diff --git a/packages/components/src/redux/sagas/subscriptions.ts b/packages/components/src/redux/sagas/subscriptions.ts index 068aefec..0bef65a1 100644 --- a/packages/components/src/redux/sagas/subscriptions.ts +++ b/packages/components/src/redux/sagas/subscriptions.ts @@ -28,11 +28,7 @@ function* cleanupSubscriptions() { usedSubscriptionIds, ) - yield all( - unusedSubscriptionIds.map(subscriptionId => - put(actions.deleteColumnSubscription(subscriptionId)), - ), - ) + yield put(actions.deleteColumnSubscriptions(unusedSubscriptionIds)) } export function* subscriptionsSagas() {