Skip to content

Commit

Permalink
Make use of accessing private APIs from thunks directly (#52214)
Browse files Browse the repository at this point in the history
* Make use of accessing private APIs from thunks directly

* Actually register the getUndo/RedoEdits private selectors
  • Loading branch information
jsnajdr authored Jul 10, 2023
1 parent de251b6 commit 01b527d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
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

0 comments on commit 01b527d

Please sign in to comment.