Created
October 12, 2018 09:07
-
-
Save arichter83/9a485639df40b538a0921026825568d2 to your computer and use it in GitHub Desktop.
React Hello World w/ JSBin [add your bin description] // source https://jsbin.com/kahuwun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="[add your bin description]"> | |
<script src="http://fb.me/react-0.13.1.js"></script> | |
<meta charset="utf-8"> | |
<title>React Hello World w/ JSBin</title> | |
</head> | |
<body> | |
<div id="react_example"></div> | |
<script id="jsbin-javascript"> | |
"use strict"; | |
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | |
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
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; } | |
var ChildComponent = (function (_React$Component) { | |
_inherits(ChildComponent, _React$Component); | |
function ChildComponent() { | |
_classCallCheck(this, ChildComponent); | |
_get(Object.getPrototypeOf(ChildComponent.prototype), "constructor", this).apply(this, arguments); | |
} | |
_createClass(ChildComponent, [{ | |
key: "calculate", | |
value: function calculate() { | |
return this.props.a + this.props.b; | |
} | |
}, { | |
key: "render", | |
value: function render() { | |
return React.createElement( | |
"span", | |
null, | |
this.props.a + this.props.b, | |
" " | |
); | |
} | |
}]); | |
return ChildComponent; | |
})(React.Component); | |
var ParentComponent = (function (_React$Component2) { | |
_inherits(ParentComponent, _React$Component2); | |
function ParentComponent() { | |
_classCallCheck(this, ParentComponent); | |
_get(Object.getPrototypeOf(ParentComponent.prototype), "constructor", this).apply(this, arguments); | |
} | |
_createClass(ParentComponent, [{ | |
key: "render", | |
value: function render() { | |
var children = [React.createElement(ChildComponent, { a: 2, b: 3, key: "1" }), React.createElement(ChildComponent, { a: 1, b: 2, key: "2" })]; | |
var children_sorted = children.slice(); | |
children_sorted.sort(function (a, b) { | |
return a.type.prototype.calculate.bind(a)() - b.type.prototype.calculate.bind(b)(); | |
}); | |
return React.createElement( | |
"h1", | |
null, | |
"Children ", | |
children, | |
" -> ", | |
children_sorted | |
); | |
} | |
}]); | |
return ParentComponent; | |
})(React.Component); | |
React.render(React.createElement(ParentComponent, null), document.getElementById('react_example')); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="[add your bin description]"> | |
<script src="//fb.me/react-0.13.1.js"><\/script> | |
<meta charset="utf-8"> | |
<title>React Hello World w/ JSBin</title> | |
</head> | |
<body> | |
<div id="react_example"></div> | |
</body> | |
</html></script> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
class ChildComponent extends React.Component { | |
calculate() { | |
return this.props.a + this.props.b; | |
} | |
render() { | |
return <span>{this.props.a + this.props.b} </span> | |
} | |
} | |
class ParentComponent extends React.Component { | |
render() { | |
var children = [ | |
<ChildComponent a={2} b={3} key="1" />, | |
<ChildComponent a={1} b={2} key="2" /> | |
]; | |
var children_sorted = children.slice(); | |
children_sorted.sort((a,b) => { | |
return a.type.prototype.calculate.bind(a)() | |
- b.type.prototype.calculate.bind(b)() | |
}); | |
return ( | |
<h1>Children {children} -> {children_sorted}</h1> | |
); | |
} | |
} | |
React.render( | |
<ParentComponent/>, | |
document.getElementById('react_example') | |
);</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | |
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
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; } | |
var ChildComponent = (function (_React$Component) { | |
_inherits(ChildComponent, _React$Component); | |
function ChildComponent() { | |
_classCallCheck(this, ChildComponent); | |
_get(Object.getPrototypeOf(ChildComponent.prototype), "constructor", this).apply(this, arguments); | |
} | |
_createClass(ChildComponent, [{ | |
key: "calculate", | |
value: function calculate() { | |
return this.props.a + this.props.b; | |
} | |
}, { | |
key: "render", | |
value: function render() { | |
return React.createElement( | |
"span", | |
null, | |
this.props.a + this.props.b, | |
" " | |
); | |
} | |
}]); | |
return ChildComponent; | |
})(React.Component); | |
var ParentComponent = (function (_React$Component2) { | |
_inherits(ParentComponent, _React$Component2); | |
function ParentComponent() { | |
_classCallCheck(this, ParentComponent); | |
_get(Object.getPrototypeOf(ParentComponent.prototype), "constructor", this).apply(this, arguments); | |
} | |
_createClass(ParentComponent, [{ | |
key: "render", | |
value: function render() { | |
var children = [React.createElement(ChildComponent, { a: 2, b: 3, key: "1" }), React.createElement(ChildComponent, { a: 1, b: 2, key: "2" })]; | |
var children_sorted = children.slice(); | |
children_sorted.sort(function (a, b) { | |
return a.type.prototype.calculate.bind(a)() - b.type.prototype.calculate.bind(b)(); | |
}); | |
return React.createElement( | |
"h1", | |
null, | |
"Children ", | |
children, | |
" -> ", | |
children_sorted | |
); | |
} | |
}]); | |
return ParentComponent; | |
})(React.Component); | |
React.render(React.createElement(ParentComponent, null), document.getElementById('react_example')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment