Skip to content

Commit

Permalink
Using a mutation observer to update the flag for performance reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Feb 26, 2018
1 parent f38c0d1 commit d040066
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions editor/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class BlockListBlock extends Component {
this.onClick = this.onClick.bind( this );
this.selectOnOpen = this.selectOnOpen.bind( this );
this.onSelectionChange = this.onSelectionChange.bind( this );
this.updateHasEditableContent = this.updateHasEditableContent.bind( this );

this.previousOffset = null;
this.hadTouchStart = false;
Expand Down Expand Up @@ -140,6 +141,9 @@ export class BlockListBlock extends Component {
this.focusTabbable();
}

this.contentObserver = new window.MutationObserver( this.updateHasEditableContent );
this.contentObserver.observe( this.node, { childList: true, subtree: true } );

this.updateHasEditableContent();
}

Expand Down Expand Up @@ -169,8 +173,6 @@ export class BlockListBlock extends Component {
this.previousOffset = null;
}

this.updateHasEditableContent();

// Bind or unbind mousemove from page when user starts or stops typing
if ( this.props.isTyping !== prevProps.isTyping ) {
if ( this.props.isTyping ) {
Expand All @@ -188,6 +190,7 @@ export class BlockListBlock extends Component {
componentWillUnmount() {
this.removeStopTypingListener();
document.removeEventListener( 'selectionchange', this.onSelectionChange );
this.contentObserver.disconnect();
}

removeStopTypingListener() {
Expand Down

0 comments on commit d040066

Please sign in to comment.