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

Make use of accessing private APIs from thunks directly #52214

Merged
merged 2 commits into from
Jul 10, 2023
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
3 changes: 1 addition & 2 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
} from '../utils/selection';
import {
__experimentalUpdateSettings,
ensureDefaultBlock,
privateRemoveBlocks,
} from './private-actions';

Expand Down Expand Up @@ -403,7 +402,7 @@ export const replaceBlocks =
initialPosition,
meta,
} );
dispatch( ensureDefaultBlock() );
dispatch.ensureDefaultBlock();
};

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/block-editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ describe( 'actions', () => {
getBlockCount: () => 1,
};
const dispatch = jest.fn();
dispatch.ensureDefaultBlock = jest.fn();

replaceBlock( 'chicken', block )( { select, dispatch } );

Expand Down Expand Up @@ -281,6 +282,7 @@ describe( 'actions', () => {
getBlockCount: () => 1,
};
const dispatch = jest.fn();
dispatch.ensureDefaultBlock = jest.fn();

replaceBlocks( [ 'chicken' ], blocks )( { select, dispatch } );

Expand Down Expand Up @@ -314,6 +316,7 @@ describe( 'actions', () => {
getBlockCount: () => 1,
};
const dispatch = jest.fn();
dispatch.ensureDefaultBlock = jest.fn();

replaceBlocks(
[ 'chicken' ],
Expand Down
7 changes: 2 additions & 5 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { receiveItems, removeItems, receiveQueriedItems } from './queried-data';
import { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';
import { createBatch } from './batch';
import { STORE_NAME } from './name';
import { getUndoEdits, getRedoEdits } from './private-selectors';

/**
* Returns an action object used in signalling that authors have been received.
Expand Down Expand Up @@ -407,8 +406,7 @@ export const editEntityRecord =
export const undo =
() =>
( { select, dispatch } ) => {
// Todo: we shouldn't have to pass "root" here.
const undoEdit = select( ( state ) => getUndoEdits( state.root ) );
const undoEdit = select.getUndoEdits();
if ( ! undoEdit ) {
return;
}
Expand All @@ -425,8 +423,7 @@ export const undo =
export const redo =
() =>
( { select, dispatch } ) => {
// Todo: we shouldn't have to pass "root" here.
const redoEdit = select( ( state ) => getRedoEdits( state.root ) );
const redoEdit = select.getRedoEdits();
if ( ! redoEdit ) {
return;
}
Expand Down
6 changes: 2 additions & 4 deletions packages/core-data/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { createReduxStore, register } from '@wordpress/data';
*/
import reducer from './reducer';
import * as selectors from './selectors';
import * as privateSelectors from './private-selectors';
import * as actions from './actions';
import * as resolvers from './resolvers';
import createLocksActions from './locks/actions';
import { rootEntitiesConfig, getMethodName } from './entities';
import { STORE_NAME } from './name';
import { unlock } from './private-apis';
import { getNavigationFallbackId } from './private-selectors';

// The entity selectors/resolvers and actions are shortcuts to their generic equivalents
// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
Expand Down Expand Up @@ -64,9 +64,7 @@ const storeConfig = () => ( {
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
*/
export const store = createReduxStore( STORE_NAME, storeConfig() );
unlock( store ).registerPrivateSelectors( {
getNavigationFallbackId,
} );
unlock( store ).registerPrivateSelectors( privateSelectors );
register( store ); // Register store after unlocking private selectors to allow resolvers to use them.

export { default as EntityProvider } from './entity-provider';
Expand Down