Skip to content

Commit

Permalink
Remove createClass. (#66)
Browse files Browse the repository at this point in the history
The `React.createClass` is going to be deprecated soon and will be
removed in React v16.
facebook/react#9232

This patch changes the component to a class extended from
`React.Component`. It does it manually by assigning to the prototype,
to avoid introducing a build step.
  • Loading branch information
goto-bus-stop authored and rexxars committed Mar 28, 2017
1 parent 818570b commit be588dd
Showing 1 changed file with 53 additions and 52 deletions.
105 changes: 53 additions & 52 deletions src/react-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,66 @@ var ReactRenderer = require('commonmark-react-renderer');

var propTypes = React.PropTypes;

var ReactMarkdown = React.createClass({
displayName: 'ReactMarkdown',
function ReactMarkdown(props) {
React.Component.call(this, props);
}

propTypes: {
className: propTypes.string,
containerProps: propTypes.object,
source: propTypes.string.isRequired,
containerTagName: propTypes.string,
childBefore: propTypes.object,
childAfter: propTypes.object,
sourcePos: propTypes.bool,
escapeHtml: propTypes.bool,
skipHtml: propTypes.bool,
softBreak: propTypes.string,
allowNode: propTypes.func,
allowedTypes: propTypes.array,
disallowedTypes: propTypes.array,
transformLinkUri: propTypes.func,
transformImageUri: propTypes.func,
unwrapDisallowed: propTypes.bool,
renderers: propTypes.object,
walker: propTypes.func,
parserOptions: propTypes.object
},
ReactMarkdown.prototype = Object.create(React.Component.prototype);
ReactMarkdown.prototype.constructor = ReactMarkdown;

getDefaultProps: function() {
return {
containerTagName: 'div',
parserOptions: {}
};
},
ReactMarkdown.prototype.render = function() {
var containerProps = this.props.containerProps || {};
var renderer = new ReactRenderer(this.props);
var parser = new Parser(this.props.parserOptions);
var ast = parser.parse(this.props.source || '');

render: function() {
var containerProps = this.props.containerProps || {};
var renderer = new ReactRenderer(this.props);
var parser = new Parser(this.props.parserOptions);
var ast = parser.parse(this.props.source || '');
if (this.props.walker) {
var walker = ast.walker();
var event;

if (this.props.walker) {
var walker = ast.walker();
var event;

while ((event = walker.next())) {
this.props.walker.call(this, event, walker);
}
}

if (this.props.className) {
containerProps.className = this.props.className;
while ((event = walker.next())) {
this.props.walker.call(this, event, walker);
}
}

return React.createElement.apply(React,
[this.props.containerTagName, containerProps, this.props.childBefore]
.concat(renderer.render(ast).concat(
[this.props.childAfter]
))
);
if (this.props.className) {
containerProps.className = this.props.className;
}
});

return React.createElement.apply(React,
[this.props.containerTagName, containerProps, this.props.childBefore]
.concat(renderer.render(ast).concat(
[this.props.childAfter]
))
);
};

ReactMarkdown.propTypes = {
className: propTypes.string,
containerProps: propTypes.object,
source: propTypes.string.isRequired,
containerTagName: propTypes.string,
childBefore: propTypes.object,
childAfter: propTypes.object,
sourcePos: propTypes.bool,
escapeHtml: propTypes.bool,
skipHtml: propTypes.bool,
softBreak: propTypes.string,
allowNode: propTypes.func,
allowedTypes: propTypes.array,
disallowedTypes: propTypes.array,
transformLinkUri: propTypes.func,
transformImageUri: propTypes.func,
unwrapDisallowed: propTypes.bool,
renderers: propTypes.object,
walker: propTypes.func,
parserOptions: propTypes.object
};

ReactMarkdown.defaultProps = {
containerTagName: 'div',
parserOptions: {}
};

ReactMarkdown.types = ReactRenderer.types;
ReactMarkdown.renderers = ReactRenderer.renderers;
Expand Down

0 comments on commit be588dd

Please sign in to comment.