Skip to content

Commit 8655301

Browse files
authored
Merge pull request #1 from galenhuntington/galen/any-tips
Allow tips to be any type.
2 parents 0534109 + 1474185 commit 8655301

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"react/no-danger": 0,
2222
"jsx-quotes": 2,
2323
"indent": [2, 2, {"SwitchCase": 1}],
24+
"no-nested-ternary": 0,
2425
"no-unused-expressions": 0,
2526
"no-undef": 0,
2627
"prefer-arrow-callback": [0, { "allowNamedFunctions": true }],

lib/jsondiff-for-react.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
3030

3131
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
3232

33-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
34-
* Created by guoguangyu on 2016/10/25.
35-
*/
36-
33+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
3734

3835
var formatters = Jsondiffpatch.formatters;
3936

@@ -56,19 +53,20 @@ var JsonDiffReact = function (_Component) {
5653
show = _props$show === undefined ? true : _props$show,
5754
_props$annotated = _props.annotated,
5855
annotated = _props$annotated === undefined ? false : _props$annotated,
59-
tips = _props.tips,
56+
_props$tips = _props.tips,
57+
tips = _props$tips === undefined ? "Both objects are identical." : _props$tips,
6058
objectHash = _props.objectHash;
6159

6260
var delta = Jsondiffpatch.create({
6361
objectHash: objectHash
6462
}).diff(left, right);
6563
var html = annotated ? formatters.annotated.format(delta) : formatters.html.format(delta, left);
6664
show ? formatters.html.showUnchanged() : formatters.html.hideUnchanged();
67-
return html ? _react2.default.createElement("div", { dangerouslySetInnerHTML: { __html: html } }) : _react2.default.createElement(
65+
return html ? _react2.default.createElement("div", { dangerouslySetInnerHTML: { __html: html } }) : typeof tips === "string" ? _react2.default.createElement(
6866
"p",
6967
{ style: { fontSize: 12, color: "#999" } },
70-
tips || "Both objects are identical."
71-
);
68+
tips
69+
) : tips;
7270
}
7371
}]);
7472

@@ -80,7 +78,7 @@ JsonDiffReact.propTypes = {
8078
left: _propTypes2.default.any,
8179
show: _propTypes2.default.bool,
8280
annotated: _propTypes2.default.bool,
83-
tips: _propTypes2.default.string,
81+
tips: _propTypes2.default.any,
8482
objectHash: _propTypes2.default.func
8583
};
8684
exports.default = JsonDiffReact;

src/jsondiff-for-react.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class JsonDiffReact extends Component {
1212
left: PropTypes.any,
1313
show: PropTypes.bool,
1414
annotated: PropTypes.bool,
15-
tips: PropTypes.string,
15+
tips: PropTypes.any,
1616
objectHash: PropTypes.func,
1717
};
1818
render() {
@@ -21,7 +21,7 @@ class JsonDiffReact extends Component {
2121
left,
2222
show = true,
2323
annotated = false,
24-
tips,
24+
tips = "Both objects are identical.",
2525
objectHash,
2626
} = this.props;
2727
const delta = Jsondiffpatch.create({
@@ -33,10 +33,10 @@ class JsonDiffReact extends Component {
3333
show ? formatters.html.showUnchanged() : formatters.html.hideUnchanged();
3434
return html ? (
3535
<div dangerouslySetInnerHTML={{ __html: html }} />
36+
) : typeof tips === "string" ? (
37+
<p style={{ fontSize: 12, color: "#999" }}>{tips}</p>
3638
) : (
37-
<p style={{ fontSize: 12, color: "#999" }}>
38-
{tips || "Both objects are identical."}
39-
</p>
39+
tips
4040
);
4141
}
4242
}

0 commit comments

Comments
 (0)