Skip to content

Commit

Permalink
Included componentWillRecieveProps to handle values in async
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercf committed May 22, 2016
1 parent 72e42b9 commit 1cacd1c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions example/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react'
import { render } from 'react-dom'
import ScribeEditor from '../src'
import ScribeEditor from '../src/ScribeEditor'

const ShowCase = props => {
return (
Expand All @@ -27,7 +27,7 @@ class DemoApp extends Component {
render() {
return (
<div>
<ScribeEditor defaultValue='hello world' onChange={this.handleChange} />
<ScribeEditor value='hello world' onChange={this.handleChange} />
<ShowCase demoContent={this.state.text} />
</div>
)
Expand Down
6 changes: 3 additions & 3 deletions lib/react-scribe-editor.js

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-scribe",
"version": "0.2.4",
"version": "0.2.5",
"description": "The Guardian's scribe.js react component",
"main": "lib/react-scribe-editor.js",
"dependencies": {
Expand All @@ -9,17 +9,9 @@
"scribe-editor": "^3.2.0",
"scribe-plugin-blockquote-command": "^0.1.0",
"scribe-plugin-code-command": "^0.1.0",
"scribe-plugin-curly-quotes": "^1.0.1",
"scribe-plugin-formatter-html-ensure-semantic-elements": "^1.0.1",
"scribe-plugin-formatter-plain-text-convert-new-lines-to-html": "^0.1.1",
"scribe-plugin-heading-command": "^0.1.0",
"scribe-plugin-inline-styles-to-elements": "^0.1.0",
"scribe-plugin-intelligent-unlink-command": "^0.1.6",
"scribe-plugin-keyboard-shortcuts": "^0.1.1",
"scribe-plugin-link-prompt-command": "^1.0.0",
"scribe-plugin-noting": "^0.3.28",
"scribe-plugin-sanitizer": "^0.1.10",
"scribe-plugin-smart-lists": "^0.1.8",
"scribe-plugin-toolbar": "^1.0.0",
"lodash-amd": "^3.5.0",
"lodash": "^4.0.0"
Expand Down
13 changes: 11 additions & 2 deletions src/ScribeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ScribeEditor extends Component {
this.updateContent = this.updateContent.bind(this);

this.state = {
value: this.isControlled() ? this.props.value : this.props.defaultValue
value: this.props.value
};
}

Expand All @@ -44,10 +44,19 @@ class ScribeEditor extends Component {
// update content
scribe.on('content-changed', () => {
this.updateContent(scribe.getHTML());
if(this.props.onChange){
if (this.props.onChange) {
this.props.onChange(scribe.getHTML());
}
});

this.scribe = scribe;
}

componentWillReceiveProps(nextProps) {
const value = this.isControlled() ? nextProps.value : nextProps.defaultValue;
if (this.state.value !== value) {
this.scribe.setContent(value);
}
}

isControlled() {
Expand Down

0 comments on commit 1cacd1c

Please sign in to comment.