Skip to content

Commit

Permalink
Avoid 'handle-' method names
Browse files Browse the repository at this point in the history
Try to describe what the method does instead of merely what event it
handles.
  • Loading branch information
noisysocks committed Mar 25, 2018
1 parent 2896b2e commit c4035be
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions editor/components/post-text-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,29 @@ class PostTextEditor extends Component {
constructor() {
super( ...arguments );

this.handleFocus = this.handleFocus.bind( this );
this.handleChange = this.handleChange.bind( this );
this.handleBlur = this.handleBlur.bind( this );
this.startEditing = this.startEditing.bind( this );
this.edit = this.edit.bind( this );
this.stopEditing = this.stopEditing.bind( this );

this.state = {
value: null,
isDirty: false,
};
}

handleFocus() {
startEditing() {
// Copying the post content into local state ensures that edits won't be
// clobbered by changes to global editor state
this.setState( { value: this.props.value } );
}

handleChange( event ) {
edit( event ) {
const value = event.target.value;
this.props.onChange( value );
this.setState( { value, isDirty: true } );
}

handleBlur() {
stopEditing() {
if ( this.state.isDirty ) {
this.props.onPersist( this.state.value );
}
Expand All @@ -54,9 +56,9 @@ class PostTextEditor extends Component {
<Textarea
autoComplete="off"
value={ this.state.value || this.props.value }
onFocus={ this.handleFocus }
onChange={ this.handleChange }
onBlur={ this.handleBlur }
onFocus={ this.startEditing }
onChange={ this.edit }
onBlur={ this.stopEditing }
className="editor-post-text-editor"
/>
);
Expand Down

0 comments on commit c4035be

Please sign in to comment.