Skip to content

Commit

Permalink
useNestedSettingsUpdate: prevent unneeded syncing by returning false …
Browse files Browse the repository at this point in the history
…from getTemplateLock
  • Loading branch information
jsnajdr committed Dec 8, 2022
1 parent d5dcbd1 commit fab34f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ _Parameters_

_Returns_

- `?string`: Block Template Lock
- `string|false`: Block Template Lock

### hasBlockMovingClientId

Expand Down
11 changes: 3 additions & 8 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1425,19 +1425,14 @@ export function getTemplate( state ) {
* @param {Object} state Editor state.
* @param {?string} rootClientId Optional block root client ID.
*
* @return {?string} Block Template Lock
* @return {string|false} Block Template Lock
*/
export function getTemplateLock( state, rootClientId ) {
if ( ! rootClientId ) {
return state.settings.templateLock;
return state.settings.templateLock ?? false;
}

const blockListSettings = getBlockListSettings( state, rootClientId );
if ( ! blockListSettings ) {
return undefined;
}

return blockListSettings.templateLock;
return getBlockListSettings( state, rootClientId )?.templateLock ?? false;
}

const checkAllowList = ( list, item, defaultResult = null ) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/block-editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3733,15 +3733,15 @@ describe( 'selectors', () => {
} );

describe( 'getTemplateLock', () => {
it( 'should return the general template lock if no clientId was set', () => {
it( 'should return the general template lock if no clientId was specified', () => {
const state = {
settings: { templateLock: 'all' },
};

expect( getTemplateLock( state ) ).toBe( 'all' );
} );

it( 'should return undefined if the specified clientId was not found', () => {
it( 'should return false if the specified clientId was not found', () => {
const state = {
settings: { templateLock: 'all' },
blockListSettings: {
Expand All @@ -3751,10 +3751,10 @@ describe( 'selectors', () => {
},
};

expect( getTemplateLock( state, 'ribs' ) ).toBe( undefined );
expect( getTemplateLock( state, 'ribs' ) ).toBe( false );
} );

it( 'should return undefined if template lock was not set on the specified block', () => {
it( 'should return false if template lock was not set on the specified block', () => {
const state = {
settings: { templateLock: 'all' },
blockListSettings: {
Expand All @@ -3764,7 +3764,7 @@ describe( 'selectors', () => {
},
};

expect( getTemplateLock( state, 'ribs' ) ).toBe( undefined );
expect( getTemplateLock( state, 'chicken' ) ).toBe( false );
} );

it( 'should return the template lock for the specified clientId', () => {
Expand Down

0 comments on commit fab34f3

Please sign in to comment.