Skip to content

Commit

Permalink
Simplify variable name to just bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed May 31, 2024
1 parent 79e6822 commit d7128b3
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions packages/block-editor/src/hooks/use-bindings-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,24 @@ export const withBlockBindingSupport = createHigherOrderComponent(
const sources = useSelect( ( select ) =>
unlock( select( blocksStore ) ).getAllBlockBindingsSources()
);
const bindings = props.attributes.metadata?.bindings;
const { name, clientId, context } = props;
const bindingsWithDefaults = useMemo(
() => replacePatternOverrideDefaultBindings( name, bindings ),
[ bindings, name ]
const bindings = useMemo(
() =>
replacePatternOverrideDefaultBindings(
name,
props.attributes.metadata?.bindings
),
[ props.attributes.metadata?.bindings, name ]
);
const boundAttributes = useSelect( () => {
if ( ! bindingsWithDefaults ) {
if ( ! bindings ) {
return;
}

const attributes = {};

for ( const [ attributeName, boundAttribute ] of Object.entries(
bindingsWithDefaults
bindings
) ) {
const source = sources[ boundAttribute.source ];
if (
Expand Down Expand Up @@ -141,21 +144,14 @@ export const withBlockBindingSupport = createHigherOrderComponent(
}

return attributes;
}, [
bindingsWithDefaults,
name,
clientId,
context,
registry,
sources,
] );
}, [ bindings, name, clientId, context, registry, sources ] );

const { setAttributes } = props;

const _setAttributes = useCallback(
( nextAttributes ) => {
registry.batch( () => {
if ( ! bindingsWithDefaults ) {
if ( ! bindings ) {
setAttributes( nextAttributes );
return;
}
Expand All @@ -168,13 +164,13 @@ export const withBlockBindingSupport = createHigherOrderComponent(
keptAttributes
) ) {
if (
! bindingsWithDefaults[ attributeName ] ||
! bindings[ attributeName ] ||
! canBindAttribute( name, attributeName )
) {
continue;
}

const binding = bindingsWithDefaults[ attributeName ];
const binding = bindings[ attributeName ];
const source = sources[ binding?.source ];
if ( ! source?.setValue && ! source?.setValues ) {
continue;
Expand Down Expand Up @@ -203,8 +199,7 @@ export const withBlockBindingSupport = createHigherOrderComponent(
attributeName,
value,
] of Object.entries( attributes ) ) {
const binding =
bindingsWithDefaults[ attributeName ];
const binding = bindings[ attributeName ];
source.setValue( {
registry,
context,
Expand All @@ -225,7 +220,7 @@ export const withBlockBindingSupport = createHigherOrderComponent(
},
[
registry,
bindingsWithDefaults,
bindings,
name,
clientId,
context,
Expand Down

0 comments on commit d7128b3

Please sign in to comment.