Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Fix/tex example (#699)
Browse files Browse the repository at this point in the history
this pull request fixed broken Tex example by removing outdated syntax that changed
in #376.

refer issue to #697
  • Loading branch information
mzbac authored and flarnie committed Oct 4, 2016
1 parent 8c9afc4 commit 1559e9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 6 additions & 7 deletions examples/tex/js/components/TeXBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import katex from 'katex';
import React from 'react';
import {Entity} from 'draft-js';

class KatexOutput extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -93,12 +92,12 @@ export default class TeXBlock extends React.Component {

this._save = () => {
var entityKey = this.props.block.getEntityAt(0);
Entity.mergeData(entityKey, {content: this.state.texValue});
var newContentState = this.props.contentState.mergeEntityData(entityKey, {content: this.state.texValue});
this.setState({
invalidTeX: false,
editMode: false,
texValue: null,
}, this._finishEdit);
}, this._finishEdit.bind(this, newContentState));
};

this._remove = () => {
Expand All @@ -107,14 +106,14 @@ export default class TeXBlock extends React.Component {
this._startEdit = () => {
this.props.blockProps.onStartEdit(this.props.block.getKey());
};
this._finishEdit = () => {
this.props.blockProps.onFinishEdit(this.props.block.getKey());
this._finishEdit = (newContentState) => {
this.props.blockProps.onFinishEdit(this.props.block.getKey(), newContentState);
};
}

_getValue() {
return Entity
.get(this.props.block.getEntityAt(0))
return this.props.contentState
.getEntity(this.props.block.getEntityAt(0))
.getData()['content'];
}

Expand Down
7 changes: 5 additions & 2 deletions examples/tex/js/components/TeXEditorExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ export default class TeXEditorExample extends React.Component {
var {liveTeXEdits} = this.state;
this.setState({liveTeXEdits: liveTeXEdits.set(blockKey, true)});
},
onFinishEdit: (blockKey) => {
onFinishEdit: (blockKey, newContentState) => {
var {liveTeXEdits} = this.state;
this.setState({liveTeXEdits: liveTeXEdits.remove(blockKey)});
this.setState({
liveTeXEdits: liveTeXEdits.remove(blockKey),
editorState:EditorState.createWithContent(newContentState),
});
},
onRemove: (blockKey) => this._removeTeX(blockKey),
},
Expand Down

3 comments on commit 1559e9f

@Casen
Copy link

@Casen Casen commented on 1559e9f Nov 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flarnie it is my understanding that this breaks as of 0.9.1

I don't believe contentState gets passed via the blockRendererFn, and according to your docs and my testing, ContentState.mergeEntityData is not a thing anymore.

Am I just confused?

@Casen
Copy link

@Casen Casen commented on 1559e9f Nov 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking at the TeX example, and this commit everything looks good: 36b0e71

@flarnie
Copy link
Contributor

@flarnie flarnie commented on 1559e9f Nov 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Casen - you are right that this change doesn't work with Draft version 0.9.1. The API on the master branch has changed compared to what is present in version 0.9.1. We have landed an API change as of #376 that changed the syntax. It has not been released yet, and we are working on updating the documentation and creating a guide for folks to migrate to the new API. Hopefully we will release the update soon and get things back in sync.

Thanks for your patience - please let me know if any questions remain.

Please sign in to comment.