Skip to content

Commit

Permalink
Editor: Implement editor tearDown to un-ready state
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jul 5, 2019
1 parent 9aabe75 commit fa46691
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class EditorProvider extends Component {
}
}

componentWillUnmount() {
this.props.tearDownEditor();
}

render() {
const {
children,
Expand Down Expand Up @@ -187,6 +191,7 @@ export default compose( [
resetEditorBlocks,
updateEditorSettings,
updateBlockSources,
tearDownEditor,
} = dispatch( 'core/editor' );
const { createWarningNotice } = dispatch( 'core/notices' );

Expand All @@ -197,6 +202,7 @@ export default compose( [
resetEditorBlocks,
updateEditorSettings,
updateBlockSources,
tearDownEditor,
resetEditorBlocksWithoutUndoLevel( blocks ) {
resetEditorBlocks( blocks, {
__unstableShouldCreateUndoLevel: false,
Expand Down
10 changes: 10 additions & 0 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ export function* setupEditor( post, edits, template ) {
yield resetEditorBlocks( blocks );
}

/**
* Returns an action object signalling that the editor is being destroyed and
* that any necessary state or side-effect cleanup should occur.
*
* @return {Object} Action object.
*/
export function tearDownEditor() {
return { type: 'TEAR_DOWN_EDITOR' };
}

/**
* Action generator function used in signalling that sources are to be updated
* in response to a single block attributes update.
Expand Down
3 changes: 3 additions & 0 deletions packages/editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ export function isReady( state = false, action ) {
switch ( action.type ) {
case 'SETUP_EDITOR_STATE':
return true;

case 'TEAR_DOWN_EDITOR':
return false;
}

return state;
Expand Down

0 comments on commit fa46691

Please sign in to comment.