Skip to content

Commit

Permalink
remove unnecessary structuredClone() call, simplify SortActions
Browse files Browse the repository at this point in the history
  • Loading branch information
afshinm committed Jan 14, 2024
1 parent a221513 commit 7090d69
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/view/plugin/sort/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export const SortColumn =
compare?: Comparator<TCell>,
) =>
(state) => {
let columns = state.sort ? structuredClone(state.sort.columns) : [];
let columns = state.sort?.columns

Check warning on line 11 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 11 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 11 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 11 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
? state.sort.columns.map((x) => {

Check warning on line 12 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
return { ...x };

Check warning on line 13 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
})

Check warning on line 14 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
: [];

Check warning on line 15 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 15 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
const count = columns.length;
const column = columns.find((x) => x.index === index);
const exists = column !== undefined;
Expand Down Expand Up @@ -86,23 +90,23 @@ export const SortColumn =

export const SortToggle =
(index: number, multi: boolean, compare?: Comparator<TCell>) => (state) => {
const columns = state.sort ? structuredClone(state.sort.columns) : [];
const columns = state.sort ? [...state.sort.columns] : [];

Check warning on line 93 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 93 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 93 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
const column = columns.find((x) => x.index === index);

if (!column) {
return {
...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,

Check warning on line 107 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 107 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
multi,
compare,
)(state),

Check warning on line 110 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
};
};

Check warning on line 112 in src/view/plugin/sort/actions.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

0 comments on commit 7090d69

Please sign in to comment.