diff --git a/app/soapbox/reducers/alerts.js b/app/soapbox/reducers/alerts.ts similarity index 61% rename from app/soapbox/reducers/alerts.js rename to app/soapbox/reducers/alerts.ts index 31428d402..f8219d199 100644 --- a/app/soapbox/reducers/alerts.js +++ b/app/soapbox/reducers/alerts.ts @@ -15,24 +15,31 @@ const AlertRecord = ImmutableRecord({ actionLink: '', }); -const initialState = ImmutableList(); +import type { AnyAction } from 'redux'; + +type PlainAlert = Record; +type Alert = ReturnType; +type State = ImmutableList; // Get next key based on last alert -const getNextKey = state => state.size > 0 ? state.last().get('key') + 1 : 0; +const getNextKey = (state: State): number => { + const last = state.last(); + return last ? last.key + 1 : 0; +}; // Import the alert -const importAlert = (state, alert) => { +const importAlert = (state: State, alert: PlainAlert): State => { const key = getNextKey(state); const record = AlertRecord({ ...alert, key }); return state.push(record); }; // Delete an alert by its key -const deleteAlert = (state, alert) => { +const deleteAlert = (state: State, alert: PlainAlert): State => { return state.filterNot(item => item.key === alert.key); }; -export default function alerts(state = initialState, action) { +export default function alerts(state: State = ImmutableList(), action: AnyAction): State { switch(action.type) { case ALERT_SHOW: return importAlert(state, action); diff --git a/app/soapbox/selectors/index.ts b/app/soapbox/selectors/index.ts index ee5f526c4..f0ba336b3 100644 --- a/app/soapbox/selectors/index.ts +++ b/app/soapbox/selectors/index.ts @@ -195,7 +195,7 @@ type Alert = ReturnType; export const getAlerts = createSelector([getAlertsBase], (base): Alert[] => { const arr: Alert[] = []; - base.forEach((item: any) => arr.push(buildAlert(item))); + base.forEach(item => arr.push(buildAlert(item))); return arr; });