made with esnextbin
Last active
April 5, 2016 21:15
-
-
Save nfcampos/03dcae315f27f7085504f3df0dfe6e46 to your computer and use it in GitHub Desktop.
esnextbin sketch
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 charset="utf-8"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
<div id='root'></div> | |
</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
// write ES2015 code and import modules from npm | |
// and then press "Execute" to run your program | |
import React, {Component} from 'react' | |
import ReactDOM from 'react-dom' | |
import {connect} from 'react-refetch' | |
class InnerComponent extends Component { | |
render() { | |
return <div>hi {this.context.foo}</div> | |
} | |
} | |
InnerComponent.contextTypes = { | |
foo: React.PropTypes.string | |
} | |
class OuterComponent extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
foo: 'bar', | |
bar: 'foo' | |
} | |
} | |
getChildContext() { | |
return { | |
foo: this.state.foo | |
} | |
} | |
setContext(foo) { | |
this.setState({ foo }) | |
} | |
setProp(bar) { | |
this.setState({ bar }) | |
} | |
render() { | |
return <InnerComponent bar={this.state.bar} /> | |
} | |
} | |
OuterComponent.childContextTypes = { | |
foo: React.PropTypes.string | |
} | |
InnerComponent = connect((p, c) => console.log('context: ', c))(InnerComponent) | |
ReactDOM.render(<OuterComponent />, document.getElementById('root')) |
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
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"react": "0.14.8", | |
"babel-runtime": "6.6.1", | |
"react-refetch": "1.0.0-beta.2", | |
"react-dom": "0.14.8" | |
} | |
} |
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 _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | |
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | |
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | |
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | |
var _createClass2 = require('babel-runtime/helpers/createClass'); | |
var _createClass3 = _interopRequireDefault(_createClass2); | |
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | |
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | |
var _inherits2 = require('babel-runtime/helpers/inherits'); | |
var _inherits3 = _interopRequireDefault(_inherits2); | |
var _react = require('react'); | |
var _react2 = _interopRequireDefault(_react); | |
var _reactDom = require('react-dom'); | |
var _reactDom2 = _interopRequireDefault(_reactDom); | |
var _reactRefetch = require('react-refetch'); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
var InnerComponent = (function (_Component) { | |
(0, _inherits3.default)(InnerComponent, _Component); | |
function InnerComponent() { | |
(0, _classCallCheck3.default)(this, InnerComponent); | |
return (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(InnerComponent).apply(this, arguments)); | |
} | |
(0, _createClass3.default)(InnerComponent, [{ | |
key: 'render', | |
value: function render() { | |
return _react2.default.createElement( | |
'div', | |
null, | |
'hi ', | |
this.context.foo | |
); | |
} | |
}]); | |
return InnerComponent; | |
})(_react.Component); // write ES2015 code and import modules from npm | |
// and then press "Execute" to run your program | |
InnerComponent.contextTypes = { | |
foo: _react2.default.PropTypes.string | |
}; | |
var OuterComponent = (function (_Component2) { | |
(0, _inherits3.default)(OuterComponent, _Component2); | |
function OuterComponent(props) { | |
(0, _classCallCheck3.default)(this, OuterComponent); | |
var _this2 = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(OuterComponent).call(this, props)); | |
_this2.state = { | |
foo: 'bar', | |
bar: 'foo' | |
}; | |
return _this2; | |
} | |
(0, _createClass3.default)(OuterComponent, [{ | |
key: 'getChildContext', | |
value: function getChildContext() { | |
return { | |
foo: this.state.foo | |
}; | |
} | |
}, { | |
key: 'setContext', | |
value: function setContext(foo) { | |
this.setState({ foo: foo }); | |
} | |
}, { | |
key: 'setProp', | |
value: function setProp(bar) { | |
this.setState({ bar: bar }); | |
} | |
}, { | |
key: 'render', | |
value: function render() { | |
return _react2.default.createElement(InnerComponent, { bar: this.state.bar }); | |
} | |
}]); | |
return OuterComponent; | |
})(_react.Component); | |
OuterComponent.childContextTypes = { | |
foo: _react2.default.PropTypes.string | |
}; | |
InnerComponent = (0, _reactRefetch.connect)(function (p, c) { | |
return console.log('context: ', c); | |
})(InnerComponent); | |
_reactDom2.default.render(_react2.default.createElement(OuterComponent, null), document.getElementById('root')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment