1
0
Fork 0
mirror of synced 2024-08-10 23:51:24 +12:00

Reduce state updates when selecting layouts

This commit is contained in:
Andrew Kingston 2022-07-14 16:24:16 +01:00
parent 99c3323390
commit 56b255cfc9
2 changed files with 17 additions and 4 deletions

View file

@ -331,10 +331,23 @@ export const getFrontendStore = () => {
},
layouts: {
select: layoutId => {
// Check this layout exists
const state = get(store)
const layout = store.actions.layouts.find(layoutId)
if (!layout) {
return
}
// Check layout isn't already selected
if (
state.selectedLayoutId === layout._id &&
state.selectedComponentId === layout.props?._id
) {
return
}
// Select new layout
store.update(state => {
const layout =
store.actions.layouts.find(layoutId) || get(store).layouts[0]
if (!layout) return
state.selectedLayoutId = layout._id
state.selectedComponentId = layout.props?._id
return state

View file

@ -13,7 +13,7 @@
indentLevel={0}
selected={$store.selectedLayoutId === layout._id}
text={layout.name}
on:click={() => ($store.selectedLayoutId = layout._id)}
on:click={() => store.actions.layouts.select(layout._id)}
>
<LayoutDropdownMenu {layout} />
</NavItem>