Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions dist/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var ReactMediumEditor = function (_React$Component) {
function ReactMediumEditor(props) {
_classCallCheck(this, ReactMediumEditor);

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ReactMediumEditor).call(this, props));
var _this = _possibleConstructorReturn(this, (ReactMediumEditor.__proto__ || Object.getPrototypeOf(ReactMediumEditor)).call(this, props));

_this.state = {
text: _this.props.text
Expand All @@ -57,7 +57,6 @@ var ReactMediumEditor = function (_React$Component) {

this.medium = new MediumEditor(dom, this.props.options);
this.medium.subscribe('editableInput', function (e) {
_this2._updated = true;
_this2.change(dom.innerHTML);
});
}
Expand All @@ -70,15 +69,20 @@ var ReactMediumEditor = function (_React$Component) {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.medium.destroy();
this._editorText = null;
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (nextProps.text !== this.state.text && !this._updated) {
if (nextProps.text !== this._editorText) {
this.setState({ text: nextProps.text });
}

if (this._updated) this._updated = false;
}
}, {
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps, nextState) {
if (this._editorText === nextState.text) return false;
return true;
}
}, {
key: 'render',
Expand All @@ -99,6 +103,8 @@ var ReactMediumEditor = function (_React$Component) {
}, {
key: 'change',
value: function change(text) {
this._editorText = text;
this.setState({ text: text });
if (this.props.onChange) this.props.onChange(text, this.medium);
}
}]);
Expand Down
11 changes: 8 additions & 3 deletions lib/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default class ReactMediumEditor extends React.Component {

this.medium = new MediumEditor(dom, this.props.options);
this.medium.subscribe('editableInput', (e) => {
this._updated = true;
this.change(dom.innerHTML);
});
}
Expand All @@ -36,14 +35,18 @@ export default class ReactMediumEditor extends React.Component {

componentWillUnmount() {
this.medium.destroy();
this._editorText = null;
}

componentWillReceiveProps(nextProps) {
if (nextProps.text !== this.state.text && !this._updated) {
if(nextProps.text !== this._editorText){
this.setState({ text: nextProps.text });
}
}

if (this._updated) this._updated = false;
shouldComponentUpdate(nextProps, nextState) {
if(this._editorText === nextState.text) return false;
return true;
}

render() {
Expand All @@ -62,6 +65,8 @@ export default class ReactMediumEditor extends React.Component {
}

change(text) {
this._editorText = text;
this.setState({text});
if (this.props.onChange) this.props.onChange(text, this.medium);
}
}