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

Avoid using a memoized selector without dependencies #57257

Merged
merged 1 commit into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions packages/edit-widgets/src/store/private-selectors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
/**
* External dependencies
*/
import createSelector from 'rememo';

/**
* WordPress dependencies
*/
import { createRef } from '@wordpress/element';

export const getListViewToggleRef = createSelector(
() => {
return createRef();
},
() => []
);
export function getListViewToggleRef( state ) {
return state.listViewToggleRef;
}
11 changes: 11 additions & 0 deletions packages/edit-widgets/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ export function listViewPanel( state = false, action ) {
return state;
}

/**
* This reducer does nothing aside initializing a ref to the list view toggle.
* We will have a unique ref per "editor" instance.
*
* @param {Object} state
* @return {Object} Reference to the list view toggle button.
*/
export function listViewToggleRef( state = { current: null } ) {
return state;
}

export default combineReducers( {
blockInserterPanel,
listViewPanel,
Expand Down
15 changes: 3 additions & 12 deletions packages/editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/**
* External dependencies
*/
import createSelector from 'rememo';

/**
* WordPress dependencies
*/
import { store as blockEditorStore } from '@wordpress/block-editor';
import { createRegistrySelector } from '@wordpress/data';
import { createRef } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -52,9 +46,6 @@ export const getInsertionPoint = createRegistrySelector(
}
);

export const getListViewToggleRef = createSelector(
() => {
return createRef();
},
() => []
);
export function getListViewToggleRef( state ) {
return state.listViewToggleRef;
}
12 changes: 12 additions & 0 deletions packages/editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,17 @@ export function listViewPanel( state = false, action ) {
return state;
}

/**
* This reducer does nothing aside initializing a ref to the list view toggle.
* We will have a unique ref per "editor" instance.
*
* @param {Object} state
* @return {Object} Reference to the list view toggle button.
*/
export function listViewToggleRef( state = { current: null } ) {
return state;
}

export default combineReducers( {
postId,
postType,
Expand All @@ -365,4 +376,5 @@ export default combineReducers( {
removedPanels,
blockInserterPanel,
listViewPanel,
listViewToggleRef,
} );
Loading