Skip to content

Commit

Permalink
Add docs for LocalAutosaveMonitor and __experimentalUpdateLocalAutosa…
Browse files Browse the repository at this point in the history
…veInterval (#19915)
  • Loading branch information
mcsf authored Jan 28, 2020
1 parent 17f6eae commit a911562
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/edit-post/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ export function updatePreferredStyleVariations( blockName, blockStyle ) {
};
}

/**
* Returns an action object used in signalling that the editor should attempt
* to locally autosave the current post every `interval` seconds.
*
* @param {number} interval The new interval, in seconds.
* @return {Object} Action object.
*/
export function __experimentalUpdateLocalAutosaveInterval( interval ) {
return {
type: 'UPDATE_LOCAL_AUTOSAVE_INTERVAL',
Expand Down
20 changes: 20 additions & 0 deletions packages/editor/src/components/local-autosave-monitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# LocalAutosaveMonitor

`LocalAutosaveMonitor` is a component based on `AutosaveMonitor` that ensures that a local copy of the current post is regularly saved in `sessionStorage`. Additionally, it will:

- attempt to clear the local copy if a copy is successful saved on the server;
- warn the user upon loading a post that there is a local copy that can be loaded;
- defer to remote autosaves, if any is available.

`LocalAutosaveMonitor` observes a saving interval defined specifically for local autosaves, in contrast with remote (server-side) autosaving. See editor setting `__experimentalLocalAutosaveInterval` and setter `__experimentalUpdateLocalAutosaveInterval`.

## Example

```js
const MyLayout = () => (
<main>
<LocalAutosaveMonitor />
<MyEditor />
</main>
);
```

0 comments on commit a911562

Please sign in to comment.