Skip to content

Commit

Permalink
Fix selector bug - getPreference must be exported
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Mar 3, 2022
1 parent eb4ef01 commit 510c531
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions packages/edit-site/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ import {
/**
* Helper for getting a preference from the preferences store.
*
* This is only used so that `getSettings` doesn't need to be
* made a registry selector. Do not export it.
* This is only present so that `getSettings` doesn't need to be made a
* registry selector.
*
* It's unstable because the selector needs to be exported and so part of the
* public API to work.
*/
const getPreference = createRegistrySelector( ( select ) => ( state, name ) => {
return select( preferencesStore ).get( 'core/edit-site', name );
} );
export const __unstableGetPreference = createRegistrySelector(
( select ) => ( state, name ) =>
select( preferencesStore ).get( 'core/edit-site', name )
);

/**
* Returns whether the given feature is enabled or not.
Expand All @@ -57,7 +61,7 @@ export function isFeatureActive( state, featureName ) {
alternative: `select( 'core/preferences' ).get`,
} );

return !! getPreference( state, featureName );
return !! __unstableGetPreference( state, featureName );
}

/**
Expand Down Expand Up @@ -111,8 +115,11 @@ export const getSettings = createSelector(
const settings = {
...state.settings,
outlineMode: true,
focusMode: !! getPreference( state, 'focusMode' ),
hasFixedToolbar: !! getPreference( state, 'fixedToolbar' ),
focusMode: !! __unstableGetPreference( state, 'focusMode' ),
hasFixedToolbar: !! __unstableGetPreference(
state,
'fixedToolbar'
),
__experimentalSetIsInserterOpened: setIsInserterOpen,
__experimentalReusableBlocks: getReusableBlocks( state ),
__experimentalPreferPatternsOnRoot:
Expand All @@ -136,8 +143,8 @@ export const getSettings = createSelector(
( state ) => [
getCanUserCreateMedia( state ),
state.settings,
getPreference( state, 'focusMode' ),
getPreference( state, 'fixedToolbar' ),
__unstableGetPreference( state, 'focusMode' ),
__unstableGetPreference( state, 'fixedToolbar' ),
getReusableBlocks( state ),
getEditedPostType( state ),
]
Expand Down Expand Up @@ -351,8 +358,10 @@ export const getCurrentTemplateTemplateParts = createRegistrySelector(
/**
* Returns the current editing mode.
*
* @param {Object} state Global application state.
*
* @return {string} Editing mode.
*/
export function getEditorMode() {
return getPreference( 'editorMode' );
export function getEditorMode( state ) {
return __unstableGetPreference( state, 'editorMode' );
}

0 comments on commit 510c531

Please sign in to comment.