From 7090d69c09d9a617a67600c90b4bd9a8e570e09c Mon Sep 17 00:00:00 2001 From: Afshin Mehrabani Date: Sun, 14 Jan 2024 16:05:57 +0000 Subject: [PATCH] remove unnecessary structuredClone() call, simplify SortActions --- src/view/plugin/sort/actions.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/view/plugin/sort/actions.ts b/src/view/plugin/sort/actions.ts index e642c0b7..908fc7db 100644 --- a/src/view/plugin/sort/actions.ts +++ b/src/view/plugin/sort/actions.ts @@ -8,7 +8,11 @@ export const SortColumn = compare?: Comparator, ) => (state) => { - let columns = state.sort ? structuredClone(state.sort.columns) : []; + let columns = state.sort?.columns + ? state.sort.columns.map((x) => { + return { ...x }; + }) + : []; const count = columns.length; const column = columns.find((x) => x.index === index); const exists = column !== undefined; @@ -86,7 +90,7 @@ export const SortColumn = export const SortToggle = (index: number, multi: boolean, compare?: Comparator) => (state) => { - const columns = state.sort ? structuredClone(state.sort.columns) : []; + const columns = state.sort ? [...state.sort.columns] : []; const column = columns.find((x) => x.index === index); if (!column) { @@ -94,15 +98,15 @@ export const SortToggle = ...state, ...SortColumn(index, 1, multi, compare)(state), }; - } else { - return { - ...state, - ...SortColumn( - index, - column.direction === 1 ? -1 : 1, - multi, - compare, - )(state), - }; } + + return { + ...state, + ...SortColumn( + index, + column.direction === 1 ? -1 : 1, + multi, + compare, + )(state), + }; };