Skip to content

Instantly share code, notes, and snippets.

@rtre84
Created January 30, 2020 01:47
Show Gist options
  • Select an option

  • Save rtre84/42b150b6253181cd02c7bd065eaf4f4d to your computer and use it in GitHub Desktop.

Select an option

Save rtre84/42b150b6253181cd02c7bd065eaf4f4d to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/cotowohoda
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://fb.me/react-with-addons-15.1.0.js"></script>
<script src="https://fb.me/react-dom-15.1.0.js"></script>
<div>
<button onClick=thing()>Thing function</button>
</div>
<div id="todos-example">Loading...</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 _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
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; }
thing = function () {
ar = [23, 233223, 2, 4];
console.log(ar);
// console.log(ar.reverse());
for (var i = ar.length - 1; i > 0; i--) {
if (ar[i] === 2) {
ar[i] = ar[i + 1];
ar[i + 1] = 2;
}
}
console.log(ar);
ar.push("end");
ar.unshift("beginning");
ar = ["start"].concat(_toConsumableArray(ar), ["real end"]);
console.log(ar);
};
var TodoApp = (function (_React$Component) {
_inherits(TodoApp, _React$Component);
function TodoApp(props) {
_classCallCheck(this, TodoApp);
_get(Object.getPrototypeOf(TodoApp.prototype), "constructor", this).call(this, props);
this.state = { items: [], text: '' };
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
_createClass(TodoApp, [{
key: "render",
value: function render() {
return React.createElement(
"div",
null,
React.createElement(
"h3",
null,
"TODO"
),
React.createElement(TodoList, { items: this.state.items }),
React.createElement(
"form",
{ onSubmit: this.handleSubmit },
React.createElement(
"label",
{ htmlFor: "new-todo" },
"What needs to be done?"
),
React.createElement("input", {
id: "new-todo",
onChange: this.handleChange,
value: this.state.text
}),
React.createElement(
"button",
null,
"Add #",
this.state.items.length + 1
)
)
);
}
}, {
key: "handleChange",
value: function handleChange(e) {
this.setState({ text: e.target.value });
}
}, {
key: "handleSubmit",
value: function handleSubmit(e) {
e.preventDefault();
if (!this.state.text.length) {
return;
}
var newItem = {
text: this.state.text,
id: Date.now()
};
this.setState(function (state) {
return {
items: state.items.concat(newItem),
text: ''
};
});
}
}]);
return TodoApp;
})(React.Component);
var TodoList = (function (_React$Component2) {
_inherits(TodoList, _React$Component2);
function TodoList() {
_classCallCheck(this, TodoList);
_get(Object.getPrototypeOf(TodoList.prototype), "constructor", this).apply(this, arguments);
}
_createClass(TodoList, [{
key: "render",
value: function render() {
return React.createElement(
"ul",
null,
this.props.items.map(function (item) {
return React.createElement(
"li",
{ key: item.id },
item.text
);
})
);
}
}]);
return TodoList;
})(React.Component);
ReactDOM.render(React.createElement(TodoApp, null), document.getElementById('todos-example'));
</script>
<script id="jsbin-source-javascript" type="text/javascript">thing = () => {
ar = [23, 233223, 2, 4];
console.log(ar);
// console.log(ar.reverse());
for (let i = ar.length-1;i > 0;i--) {
if (ar[i] === 2) {
ar[i] = ar[i+1];
ar[i+1] = 2;
}
}
console.log(ar);
ar.push("end");
ar.unshift("beginning");
ar = ["start", ...ar, "real end"]
console.log(ar);
}
class TodoApp extends React.Component {
constructor(props) {
super(props);
this.state = { items: [], text: '' };
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
render() {
return (
<div>
<h3>TODO</h3>
<TodoList items={this.state.items} />
<form onSubmit={this.handleSubmit}>
<label htmlFor="new-todo">
What needs to be done?
</label>
<input
id="new-todo"
onChange={this.handleChange}
value={this.state.text}
/>
<button>
Add #{this.state.items.length + 1}
</button>
</form>
</div>
);
}
handleChange(e) {
this.setState({ text: e.target.value });
}
handleSubmit(e) {
e.preventDefault();
if (!this.state.text.length) {
return;
}
const newItem = {
text: this.state.text,
id: Date.now()
};
this.setState(state => ({
items: state.items.concat(newItem),
text: ''
}));
}
}
class TodoList extends React.Component {
render() {
return (
<ul>
{this.props.items.map(item => (
<li key={item.id}>{item.text}</li>
))}
</ul>
);
}
}
ReactDOM.render(
<TodoApp />,
document.getElementById('todos-example')
);</script></body>
</html>
"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 _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
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; }
thing = function () {
ar = [23, 233223, 2, 4];
console.log(ar);
// console.log(ar.reverse());
for (var i = ar.length - 1; i > 0; i--) {
if (ar[i] === 2) {
ar[i] = ar[i + 1];
ar[i + 1] = 2;
}
}
console.log(ar);
ar.push("end");
ar.unshift("beginning");
ar = ["start"].concat(_toConsumableArray(ar), ["real end"]);
console.log(ar);
};
var TodoApp = (function (_React$Component) {
_inherits(TodoApp, _React$Component);
function TodoApp(props) {
_classCallCheck(this, TodoApp);
_get(Object.getPrototypeOf(TodoApp.prototype), "constructor", this).call(this, props);
this.state = { items: [], text: '' };
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
_createClass(TodoApp, [{
key: "render",
value: function render() {
return React.createElement(
"div",
null,
React.createElement(
"h3",
null,
"TODO"
),
React.createElement(TodoList, { items: this.state.items }),
React.createElement(
"form",
{ onSubmit: this.handleSubmit },
React.createElement(
"label",
{ htmlFor: "new-todo" },
"What needs to be done?"
),
React.createElement("input", {
id: "new-todo",
onChange: this.handleChange,
value: this.state.text
}),
React.createElement(
"button",
null,
"Add #",
this.state.items.length + 1
)
)
);
}
}, {
key: "handleChange",
value: function handleChange(e) {
this.setState({ text: e.target.value });
}
}, {
key: "handleSubmit",
value: function handleSubmit(e) {
e.preventDefault();
if (!this.state.text.length) {
return;
}
var newItem = {
text: this.state.text,
id: Date.now()
};
this.setState(function (state) {
return {
items: state.items.concat(newItem),
text: ''
};
});
}
}]);
return TodoApp;
})(React.Component);
var TodoList = (function (_React$Component2) {
_inherits(TodoList, _React$Component2);
function TodoList() {
_classCallCheck(this, TodoList);
_get(Object.getPrototypeOf(TodoList.prototype), "constructor", this).apply(this, arguments);
}
_createClass(TodoList, [{
key: "render",
value: function render() {
return React.createElement(
"ul",
null,
this.props.items.map(function (item) {
return React.createElement(
"li",
{ key: item.id },
item.text
);
})
);
}
}]);
return TodoList;
})(React.Component);
ReactDOM.render(React.createElement(TodoApp, null), document.getElementById('todos-example'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment