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

Block Bindings: Move logic to core functions instead of using a hook #61817

Draft
wants to merge 18 commits into
base: try/sync-block-context-in-store
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Access context through selector
  • Loading branch information
SantosGuillamot committed May 28, 2024
commit cd125153338f48032458b98a9ca78343f088926e
5 changes: 3 additions & 2 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ export const updateBlockAttributes =
} );

if ( updatesBySource.size ) {
// TODO: Access the block context.
const context = {};
const context = registry
.select( STORE_NAME )
.getBlockContext( clientId );
for ( const [ source, boundAttributes ] of updatesBySource ) {
if ( source.setValues ) {
source.setValues( {
Expand Down
12 changes: 2 additions & 10 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ let isProcessingBindings;
*/
export const getBlockAttributes = createRegistrySelector(
( select ) => ( state, clientId ) => {
// TODO: Check how to properly access the block context.
const blockContext = {};
const block = state.blocks.byClientId.get( clientId );
if ( ! block ) {
return null;
Expand All @@ -147,6 +145,8 @@ export const getBlockAttributes = createRegistrySelector(
}
isProcessingBindings = true;

const context = select( STORE_NAME ).getBlockContext( clientId );

const sources = unlock(
select( blocksStore )
).getAllBlockBindingsSources();
Expand All @@ -162,14 +162,6 @@ export const getBlockAttributes = createRegistrySelector(
continue;
}

const context = {};

if ( source.usesContext?.length ) {
for ( const key of source.usesContext ) {
context[ key ] = blockContext[ key ];
}
}

const args = {
select,
context,
Expand Down