Skip to content

Commit

Permalink
Editor: Reuse hook name across disparate hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jan 3, 2019
1 parent f64538d commit 454c93f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/editor/src/components/post-locked-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ class PostLockedModal extends Component {
}

componentDidMount() {
const hookNamePrefix = this.getHookNamePrefix();
const hookName = this.getHookName();

// Details on these events on the Heartbeat API docs
// https://developer.wordpress.org/plugins/javascript/heartbeat-api/
addAction( 'heartbeat.send', hookNamePrefix + '-send', this.sendPostLock );
addAction( 'heartbeat.tick', hookNamePrefix + '-tick', this.receivePostLock );
addAction( 'heartbeat.send', hookName, this.sendPostLock );
addAction( 'heartbeat.tick', hookName, this.receivePostLock );
}

componentWillUnmount() {
const hookNamePrefix = this.getHookNamePrefix();
const hookName = this.getHookName();

removeAction( 'heartbeat.send', hookNamePrefix + '-send' );
removeAction( 'heartbeat.tick', hookNamePrefix + '-tick' );
removeAction( 'heartbeat.send', hookName );
removeAction( 'heartbeat.tick', hookName );
}

/**
Expand All @@ -51,9 +51,9 @@ class PostLockedModal extends Component {
*
* @return {string} Hook name prefix.
*/
getHookNamePrefix() {
getHookName() {
const { instanceId } = this.props;
return 'core/editor/post-locked-modal-' + instanceId + '-heartbeat';
return 'core/editor/post-locked-modal-' + instanceId;
}

/**
Expand Down

0 comments on commit 454c93f

Please sign in to comment.