Skip to content

Commit

Permalink
fix: limiting closedWindows array to 50 window
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Abdelaziz committed Nov 2, 2019
1 parent e99f139 commit cb73fd2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/app/reducers/local/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import * as local from '../../actions/local/local';

const MAX_CLOSED_WINDOWS_LENGTH = 50;

export interface State {
closedWindows: any[];
}
Expand All @@ -11,14 +13,17 @@ const initialState: State = {
};

export function localReducer(state = initialState, action: local.Action): State {
const len = state.closedWindows.length;
switch (action.type) {
case local.PUSH_CLOSED_WINDOW_TO_LOCAL:
return {
...state,
closedWindows: [ ...state.closedWindows, action.payload.window ],
closedWindows: len === MAX_CLOSED_WINDOWS_LENGTH ?
[ ...state.closedWindows.slice(1), action.payload.window ] :
[ ...state.closedWindows, action.payload.window ],

};
case local.POP_FROM_CLOSED_WINDOWS:
const len = state.closedWindows.length;
return {
...state,
closedWindows: state.closedWindows.filter((_, i) => i < len - 1),
Expand Down

0 comments on commit cb73fd2

Please sign in to comment.