Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State: Prevent unnecessary state updates to edit-post preferences #5990

Merged
merged 2 commits into from
Apr 5, 2018

Conversation

aduth
Copy link
Member

@aduth aduth commented Apr 5, 2018

Related: #5974 (comment)

This pull request seeks to resolve two issues with unnecessary state updates and dispatching to the edit post store:

  1. Most preferences values were not comparing to the current state, merging into the state object and creating a new reference even if the new preference was the same. By returning a new object reference, all state subscribers were being invoked. With these changes, leveraging combineReducers has the benefit of avoiding state updates when each key of preferences is strictly equal.
  2. The store subscriptions introduced in Opens the block inspector automatically when the block is selected #5882 were dispatching in response to a change in the UID of the selected block, when it was sufficient to listen for a change in plainly whether or not there is a selected block (only having two states true and false, rather than unlimited states of possible set of block UIDs). With these changes, the subscribe listener will only dispatch when going from a state of cleared selection to having a selection, but not when changing selection from one block to another.

Testing instructions:

Verify that there are no regressions in the behaviors of preferences (toggled panels, active sidebar, editor mode).

Repeat testing instructions from #5882, verifying no regressions.

@aduth aduth added Framework Issues related to broader framework topics, especially as it relates to javascript [Type] Performance Related to performance efforts labels Apr 5, 2018
},
};
case 'SWITCH_MODE':
export const preferences = combineReducers( {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring 👍

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@youknowriad youknowriad added this to the 2.6 milestone Apr 5, 2018
@youknowriad youknowriad merged commit c33ccb3 into master Apr 5, 2018
@youknowriad youknowriad deleted the fix/block-selection-active-sidebar branch April 5, 2018 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants