Skip to content

Commit

Permalink
Consolidate onChange content logic
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Mar 29, 2017
1 parent 52461da commit 08a46f4
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions editor/editor/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class Layout extends wp.element.Component {
constructor( props ) {
super( ...arguments );
this.switchMode = this.switchMode.bind( this );
this.changeHtml = this.changeHtml.bind( this );
this.changeBlocks = this.changeBlocks.bind( this );
this.state = {
mode: 'visual',
html: props.initialContent,
Expand All @@ -29,16 +27,8 @@ class Layout extends wp.element.Component {
} );
}

changeHtml( html ) {
this.setState( {
html
} );
}

changeBlocks( blocks ) {
this.setState( {
blocks
} );
createChangeHandler( type ) {
return ( value ) => this.setState( { [ type ]: value } );
}

render() {
Expand All @@ -49,8 +39,8 @@ class Layout extends wp.element.Component {
<ModeSwitcher mode={ mode } onSwitch={ this.switchMode } />
</div>
<div className="editor__body">
{ mode === 'text' && <EditorText html={ html } onChange={ this.changeHtml } /> }
{ mode === 'visual' && <EditorVisual blocks={ blocks } onChange={ this.changeBlocks } /> }
{ mode === 'text' && <EditorText html={ html } onChange={ this.createChangeHandler( 'html' ) } /> }
{ mode === 'visual' && <EditorVisual blocks={ blocks } onChange={ this.createChangeHandler( 'blocks' ) } /> }
</div>
</div>
);
Expand Down

0 comments on commit 08a46f4

Please sign in to comment.