Skip to content

Commit

Permalink
Merge branch 'master' into type-portal-email-store
Browse files Browse the repository at this point in the history
  • Loading branch information
aptkingston authored Jan 2, 2025
2 parents de3f700 + ad0e486 commit 460088f
Showing 1 changed file with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,35 @@ export const initialise = (context: StoreContext) => {
})
)

function sortHasChanged(
newSort: {
column: string | null | undefined
order: SortOrder
},
existingSort?: {
field: string
order?: SortOrder
}
) {
const newColumn = newSort.column ?? null
const existingColumn = existingSort?.field ?? null
if (newColumn !== existingColumn) {
return true
}

if (!newColumn) {
return false
}

const newOrder = newSort.order ?? null
const existingOrder = existingSort?.order ?? null
if (newOrder !== existingOrder) {
return true
}

return false
}

// When sorting changes, ensure view definition is kept up to date
unsubscribers.push(
sort.subscribe(async $sort => {
Expand All @@ -161,10 +190,7 @@ export const initialise = (context: StoreContext) => {
}

// Skip if nothing actually changed
if (
$sort?.column === $view.sort?.field &&
$sort?.order === $view.sort?.order
) {
if (!sortHasChanged($sort, $view.sort)) {
return
}

Expand Down

0 comments on commit 460088f

Please sign in to comment.