Skip to content

Commit

Permalink
API: Stabilize localAutosave()
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf committed Feb 10, 2020
1 parent ad44389 commit b72de73
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
5 changes: 5 additions & 0 deletions docs/designers-developers/developers/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,11 @@ _Related_

- insertDefaultBlock in core/block-editor store.

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

Action generator used in signalling that the post should be locally
autosaved (e.g. on the Web, it might be committed to Session Storage).

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

Returns an action object used to signal that post autosaving is locked.
Expand Down
24 changes: 6 additions & 18 deletions packages/e2e-tests/specs/editor/various/autosave.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ describe( 'autosave', () => {

// Trigger local autosave
await page.evaluate( () =>
window.wp.data
.dispatch( 'core/editor' )
.__experimentalLocalAutosave()
window.wp.data.dispatch( 'core/editor' ).localAutosave()
);
// Reload without saving on the server
await page.reload();
Expand Down Expand Up @@ -213,9 +211,7 @@ describe( 'autosave', () => {

// Trigger local autosave
await page.evaluate( () =>
window.wp.data
.dispatch( 'core/editor' )
.__experimentalLocalAutosave()
window.wp.data.dispatch( 'core/editor' ).localAutosave()
);
expect(
await page.evaluate( () => window.sessionStorage.length )
Expand All @@ -239,9 +235,7 @@ describe( 'autosave', () => {

// Trigger local autosave
await page.evaluate( () =>
window.wp.data
.dispatch( 'core/editor' )
.__experimentalLocalAutosave()
window.wp.data.dispatch( 'core/editor' ).localAutosave()
);
expect(
await page.evaluate( () => window.sessionStorage.length )
Expand All @@ -266,9 +260,7 @@ describe( 'autosave', () => {

// Trigger local autosave
await page.evaluate( () =>
window.wp.data
.dispatch( 'core/editor' )
.__experimentalLocalAutosave()
window.wp.data.dispatch( 'core/editor' ).localAutosave()
);
expect(
await page.evaluate( () => window.sessionStorage.length )
Expand All @@ -289,9 +281,7 @@ describe( 'autosave', () => {

// Trigger local autosave
await page.evaluate( () =>
window.wp.data
.dispatch( 'core/editor' )
.__experimentalLocalAutosave()
window.wp.data.dispatch( 'core/editor' ).localAutosave()
);
expect(
await page.evaluate( () => window.sessionStorage.length )
Expand Down Expand Up @@ -320,9 +310,7 @@ describe( 'autosave', () => {

// Force conflicting local autosave
await page.evaluate( () =>
window.wp.data
.dispatch( 'core/editor' )
.__experimentalLocalAutosave()
window.wp.data.dispatch( 'core/editor' ).localAutosave()
);
expect(
await page.evaluate( () => window.sessionStorage.length )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ function useAutosavePurge() {
}

function LocalAutosaveMonitor() {
const { __experimentalLocalAutosave } = useDispatch( 'core/editor' );
const { localAutosave } = useDispatch( 'core/editor' );
const autosave = useCallback( () => {
requestIdleCallback( __experimentalLocalAutosave );
requestIdleCallback( localAutosave );
}, [] );
useAutosaveNotice();
useAutosavePurge();
Expand Down
6 changes: 5 additions & 1 deletion packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@ export function* autosave( options ) {
yield dispatch( STORE_KEY, 'savePost', { isAutosave: true, ...options } );
}

export function* __experimentalLocalAutosave() {
/**
* Action generator used in signalling that the post should be locally
* autosaved (e.g. on the Web, it might be committed to Session Storage).
*/
export function* localAutosave() {
const post = yield select( STORE_KEY, 'getCurrentPost' );
const title = yield select( STORE_KEY, 'getEditedPostAttribute', 'title' );
const content = yield select(
Expand Down

0 comments on commit b72de73

Please sign in to comment.