Skip to content

Commit 50cfa09

Browse files
Adapt reducer and fixes
1 parent 227890f commit 50cfa09

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

packages/blocks/src/api/registration.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,9 @@ export const registerBlockBindingsSource = ( source ) => {
806806

807807
/*
808808
* Check if the source has been already registered on the client.
809-
* If the `getValue` property is defined, it could be assumed the source is already registered.
809+
* If the `getValues` property is defined, it could be assumed the source is already registered.
810810
*/
811-
if ( existingSource?.getValue ) {
811+
if ( existingSource?.getValues ) {
812812
warning(
813813
'Block bindings source "' + name + '" is already registered.'
814814
);
@@ -891,7 +891,14 @@ export const registerBlockBindingsSource = ( source ) => {
891891
return;
892892
}
893893

894-
return unlock( dispatch( blocksStore ) ).addBlockBindingsSource( source );
894+
return unlock( dispatch( blocksStore ) ).addBlockBindingsSource( {
895+
name,
896+
label,
897+
getValues,
898+
setValues,
899+
getPlaceholder,
900+
canUserEditValue,
901+
} );
895902
};
896903

897904
/**

packages/blocks/src/api/test/registration.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ describe( 'blocks', () => {
16161616
const source = {
16171617
name: 'core/test-source',
16181618
label: 'Test Source',
1619-
getValue: () => 'value',
1619+
getValues: () => 'value',
16201620
};
16211621
registerBlockBindingsSource( source );
16221622
registerBlockBindingsSource( source );

packages/blocks/src/store/reducer.js

+6-18
Original file line numberDiff line numberDiff line change
@@ -374,34 +374,22 @@ export function collections( state = {}, action ) {
374374
export function blockBindingsSources( state = {}, action ) {
375375
switch ( action.type ) {
376376
case 'ADD_BLOCK_BINDINGS_SOURCE':
377-
// Filter the name property, the type property, and the undefined values.
378-
const newProperties = Object.fromEntries(
379-
Object.entries( action ).filter(
380-
( [ key, value ] ) =>
381-
value !== undefined && key !== 'name' && key !== 'type'
382-
)
383-
);
384-
385377
return {
386378
...state,
387379
[ action.name ]: {
388-
// Keep the existing properties if it has been bootstrapped.
389-
...state[ action.name ],
390-
// Update with the new properties.
391-
...newProperties,
392-
canUserEditValue:
393-
action.canUserEditValue || ( () => false ),
380+
// Don't override the label if it's already set.
381+
label: state[ action.name ]?.label || action.label,
382+
getValues: action.getValues,
383+
setValues: action.setValues,
384+
getPlaceholder: action.getPlaceholder,
385+
canUserEditValue: action.canUserEditValue,
394386
},
395387
};
396388
case 'ADD_BOOTSTRAPPED_BLOCK_BINDINGS_SOURCE':
397389
return {
398390
...state,
399391
[ action.name ]: {
400392
label: action.label,
401-
getValues: action.getValues,
402-
setValues: action.setValues,
403-
getPlaceholder: action.getPlaceholder,
404-
canUserEditValue: action.canUserEditValue,
405393
usesContext: action.usesContext,
406394
},
407395
};

0 commit comments

Comments
 (0)