From 50822b796de1d1e07204fae67623634a50b854a5 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Fri, 31 May 2024 15:12:02 +0800 Subject: [PATCH] Simplify variable name to just bindings --- .../src/hooks/use-bindings-attributes.js | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/packages/block-editor/src/hooks/use-bindings-attributes.js b/packages/block-editor/src/hooks/use-bindings-attributes.js index 9e76e694cdba55..334c751bc01b0b 100644 --- a/packages/block-editor/src/hooks/use-bindings-attributes.js +++ b/packages/block-editor/src/hooks/use-bindings-attributes.js @@ -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 ( @@ -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; } @@ -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; @@ -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, @@ -225,7 +220,7 @@ export const withBlockBindingSupport = createHigherOrderComponent( }, [ registry, - bindingsWithDefaults, + bindings, name, clientId, context,