Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing actions and tests for lockPostAutosaving, unlockPostAutosaving #18854

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/designers-developers/developers/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,23 @@ _Related_

- insertDefaultBlock in core/block-editor store.

<a name="lockPostAutosaving" href="#lockPostAutosaving">#</a> **lockPostAutosaving**

Returns an action object used to signal that post autosaving is locked.

_Usage_

// Lock post autosaving with the lock key `mylock`:
wp.data.dispatch( 'core/editor' ).lockPostAutosaving( 'mylock' );

_Parameters_

- _lockName_ `string`: The lock name.

_Returns_

- `Object`: Action object

<a name="lockPostSaving" href="#lockPostSaving">#</a> **lockPostSaving**

Returns an action object used to signal that post saving is locked.
Expand Down Expand Up @@ -1386,6 +1403,23 @@ Action generator for trashing the current post in the editor.

Returns an action object used in signalling that undo history should pop.

<a name="unlockPostAutosaving" href="#unlockPostAutosaving">#</a> **unlockPostAutosaving**

Returns an action object used to signal that post autosaving is unlocked.

_Usage_

// Unlock post saving with the lock key `mylock`:
wp.data.dispatch( 'core/editor' ).unlockPostAutosaving( 'mylock' );

_Parameters_

- _lockName_ `string`: The lock name.

_Returns_

- `Object`: Action object

<a name="unlockPostSaving" href="#unlockPostSaving">#</a> **unlockPostSaving**

Returns an action object used to signal that post saving is unlocked.
Expand Down
40 changes: 40 additions & 0 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,46 @@ export function unlockPostSaving( lockName ) {
};
}

/**
* Returns an action object used to signal that post autosaving is locked.
*
* @param {string} lockName The lock name.
*
* @example
* ```
* // Lock post autosaving with the lock key `mylock`:
* wp.data.dispatch( 'core/editor' ).lockPostAutosaving( 'mylock' );
* ```
*
* @return {Object} Action object
*/
export function lockPostAutosaving( lockName ) {
return {
type: 'LOCK_POST_AUTOSAVING',
lockName,
};
}

/**
* Returns an action object used to signal that post autosaving is unlocked.
*
* @param {string} lockName The lock name.
*
* @example
* ```
* // Unlock post saving with the lock key `mylock`:
* wp.data.dispatch( 'core/editor' ).unlockPostAutosaving( 'mylock' );
* ```
*
* @return {Object} Action object
*/
export function unlockPostAutosaving( lockName ) {
return {
type: 'UNLOCK_POST_AUTOSAVING',
lockName,
};
}

/**
* Returns an action object used to signal that the blocks have been updated.
*
Expand Down
20 changes: 20 additions & 0 deletions packages/editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,24 @@ describe( 'Editor actions', () => {
} );
} );
} );

describe( 'lockPostAutosaving', () => {
it( 'should return the LOCK_POST_AUTOSAVING action', () => {
const result = actions.lockPostAutosaving( 'test' );
expect( result ).toEqual( {
type: 'LOCK_POST_AUTOSAVING',
lockName: 'test',
} );
} );
} );

describe( 'unlockPostAutosaving', () => {
it( 'should return the UNLOCK_POST_AUTOSAVING action', () => {
const result = actions.unlockPostAutosaving( 'test' );
expect( result ).toEqual( {
type: 'UNLOCK_POST_AUTOSAVING',
lockName: 'test',
} );
} );
} );
} );