-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix deprecated getEntity (fixes #67) #71
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution! I've got a few questions here..
src/stateToHTML.js
Outdated
); | ||
this.inlineStyles = inlineStyles; | ||
this.styleOrder = styleOrder; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between the code on the left and the code on the right? If there are no changes can you rebase this PR so they are the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change really, must be some spacing or something changed just be opening and saving the file in my editor. I couldn't manage to unstage the hunk either using SourceTree.
src/stateToHTML.js
Outdated
export default function stateToHTML(content: ContentState, options: ?Options): string { | ||
return new MarkupGenerator(content, options).generate(); | ||
export default function stateToHTML(content: ContentState, options: ?Options): string { | ||
return new MarkupGenerator(content, options).generate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, what is the difference here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change really, must be some spacing or something changed just be opening and saving the file in my editor. I couldn't manage to unstage the hunk either using SourceTree.
src/stateToHTML.js
Outdated
@@ -341,7 +340,7 @@ class MarkupGenerator { | |||
} | |||
return content; | |||
}).join(''); | |||
let entity = entityKey ? Entity.get(entityKey) : null; | |||
let entity = entityKey ? this.contentState.getEntity(entityKey) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main change of this PR, right? This fixes the issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, Entity.get is deprecated as of 0.10 and replaced by contentState.getEntity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the accidental trailing whitespace changes now.
👍 |
Have tested and this works well for me in |
How is it now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution. My only concern is that this will NOT work with older versions draft-js which do not support contentState.getEntity()
We should create a helper function with feature detection:
function getEntity(contentState, entityKey) {
return contentState.getEntity ? contentState.getEntity(entityKey) : Entity.get(entityKey);
}
Then you can change line 343 to:
let entity = entityKey ? getEntity(this.contentState, entityKey) : null;
…ions of draft-js as per sstur's suggestion
Added your improvements for backward compatibility |
@@ -377,6 +376,10 @@ class MarkupGenerator { | |||
|
|||
} | |||
|
|||
function getEntity(contentState, entityKey) { | |||
return contentState.getEntity ? contentState.getEntity(entityKey) : Entity.get(entityKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entity
is not defined, is it?
I think because you removed line 7.
Thanks! |
WARNING: DraftEntity.get will be deprecated soon! Please use "contentState.getEntity" instead.