Skip to content

Commit

Permalink
Use blockBindingsBySource name
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed Jul 19, 2024
1 parent c4bf3dd commit ce80330
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/block-editor/src/hooks/use-bindings-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const withBlockBindingSupport = createHigherOrderComponent(

const attributes = {};

const bindingsBySource = new Map();
const blockBindingsBySource = new Map();

for ( const [ attributeName, binding ] of Object.entries(
blockBindings
Expand All @@ -135,16 +135,16 @@ export const withBlockBindingSupport = createHigherOrderComponent(
continue;
}

bindingsBySource.set( source, {
...bindingsBySource.get( source ),
blockBindingsBySource.set( source, {
...blockBindingsBySource.get( source ),
[ attributeName ]: {
args: sourceArgs,
},
} );
}

if ( bindingsBySource.size ) {
for ( const [ source, bindings ] of bindingsBySource ) {
if ( blockBindingsBySource.size ) {
for ( const [ source, bindings ] of blockBindingsBySource ) {
// Get values in batch if the source supports it.
const values = source.getValues( {
registry,
Expand Down Expand Up @@ -190,7 +190,7 @@ export const withBlockBindingSupport = createHigherOrderComponent(
}

const keptAttributes = { ...nextAttributes };
const bindingsBySource = new Map();
const blockBindingsBySource = new Map();

// Loop only over the updated attributes to avoid modifying the bound ones that haven't changed.
for ( const [ attributeName, newValue ] of Object.entries(
Expand All @@ -208,8 +208,8 @@ export const withBlockBindingSupport = createHigherOrderComponent(
if ( ! source?.setValues ) {
continue;
}
bindingsBySource.set( source, {
...bindingsBySource.get( source ),
blockBindingsBySource.set( source, {
...blockBindingsBySource.get( source ),
[ attributeName ]: {
args: binding.args,
newValue,
Expand All @@ -218,8 +218,11 @@ export const withBlockBindingSupport = createHigherOrderComponent(
delete keptAttributes[ attributeName ];
}

if ( bindingsBySource.size ) {
for ( const [ source, bindings ] of bindingsBySource ) {
if ( blockBindingsBySource.size ) {
for ( const [
source,
bindings,
] of blockBindingsBySource ) {
source.setValues( {
registry,
context,
Expand Down

0 comments on commit ce80330

Please sign in to comment.