PK
ór}X react-in-a-tweet-1.0.0/PK
ór}X react-in-a-tweet-1.0.0/lib/PK
ór}Xö8û¢~ ~ . react-in-a-tweet-1.0.0/lib/react-in-a-tweet.js// paste into react.jsbin.com
// remove scripts loading the actual react lib if any
// https://react.jsbin.com/godotur/1/edit?js,output
// React + ReactDOM.render (no virtual DOM)
function Co(p){this.props=p}A='appendChild',g=a=>a.map?a.flatMap(g):[a]
React={[C='createElement']:(t,p,...c)=>t.bind?new t(p):(e=document[C](t),(()=>{for(n in p)e[n]=p[n]})(),g(c).map(a=>e[A](a.tagName?a:new Text(a))),e)}
render=(r,h)=>(r.h=h,h[A](r.render()))
// the correct one
// function Co(p){this.props=p}A='appendChild',g=a=>(a||'').map?a.flatMap(g):[a||'']
// React={[C='createElement']:(t,p,...c)=>t.bind?new t(p):(e=document[C](t),(()=>{for(n in p)e[n]=p[n]})(),g(c).map(a=>e[A](a.tagName?a:new Text(a))),e)}
// render=(r,h)=>(r.h=h,h[A](r.render()))
// Additional plugin, if you also want setState
Co.prototype.setState=function(s){
this.state={...this.state,...s}
this.h.innerHTML=''
render(this,this.h)
}
// Usage
class App extends Co {
constructor(){super();this.state={count:0}}
handleClick() {this.setState({count:this.state.count+1})}
render() {
return (
Count: {this.state.count}
);
}
}
render(
,
document.getElementById('container')
);
;
JS Bin
;
body {
font: 14px "Century Gothic", Futura, sans-serif;
margin: 20px;
}
ol, ul {
padding-left: 30px;
}
.board-row:after {
clear: both;
content: "";
display: table;
}
.status {
margin-bottom: 10px;
}
.square {
background: #fff;
border: 1px solid #999;
float: left;
font-size: 24px;
font-weight: bold;
line-height: 34px;
height: 34px;
margin-right: -1px;
margin-top: -1px;
padding: 0;
text-align: center;
width: 34px;
}
.square:focus {
outline: none;
}
.kbd-navigation .square:focus {
background: #ddd;
}
.game {
display: flex;
flex-direction: row;
}
.game-info {
margin-left: 20px;
}
;
A = 'appendChild'
g = a => (
// console.log('g', a),
a = a || [],
a.map ? a.flatMap(g) : [a]
)
React = {
Component: function(p) {
this.props = p
},
[C = 'createElement']: (t, p, ...c) => (
// console.log('createElement', '\n>>', t, '\n>>', p, '\n>>', c, '\n'),
t.bind
? new t(p)
: (
e = document[C](t),
(() => {
for (n in p)
e[n] = p[n]
})(),
g(c).map(a => (
// (!e || !e[A]) && console.log('tpc', t, p, c),
e[A](
a.props
? a.render()
: a.part
? a
: new Text(a)
)
)),
// console.log('e',e),
e
)
)
}
// Additional ReactDOM plugin
ReactDOM = {
render: (r, h) => (
r.h = h,
// (!h || !h[A]) && console.log('rh', r, h),
h[A](r.render())
)
}
// Additional plugin, if you also want setState
React.Component.prototype.setState=function(s){
this.state={...this.state,...s};
!this.h && console.log('setState', this, this.h);
this.h.innerHTML='';
ReactDOM.render(this,this.h)
}
function Square(props) {
return (
{props.value}
);
}
class Board extends React.Component {
renderSquare(i) {
return (
this.props.onClick(i)}
/>
);
}
render() {
return (
{this.renderSquare(0)}
{this.renderSquare(1)}
{this.renderSquare(2)}
{this.renderSquare(3)}
{this.renderSquare(4)}
{this.renderSquare(5)}
{this.renderSquare(6)}
{this.renderSquare(7)}
{this.renderSquare(8)}
);
}
}
class Game extends React.Component {
constructor(props) {
super(props);
this.state = {
history: [
{
squares: Array(9).fill(null)
}
],
stepNumber: 0,
xIsNext: true
};
}
handleClick(i) {
console.log('handleClick', i);
const history = this.state.history.slice(0, this.state.stepNumber + 1);
const current = history[history.length - 1];
const squares = current.squares.slice();
if (calculateWinner(squares) || squares[i]) {
return;
}
squares[i] = this.state.xIsNext ? "X" : "O";
this.setState({
history: history.concat([
{
squares: squares
}
]),
stepNumber: history.length,
xIsNext: !this.state.xIsNext
});
}
jumpTo(step) {
this.setState({
stepNumber: step,
xIsNext: (step % 2) === 0
});
}
render() {
const history = this.state.history;
const current = history[this.state.stepNumber];
const winner = calculateWinner(current.squares);
const moves = history.map((step, move) => {
const desc = move ?
'Go to move #' + move :
'Go to game start';
return (
this.jumpTo(move)}>{desc}
);
});
let status;
if (winner) {
status = "Winner: " + winner;
} else {
status = "Next player: " + (this.state.xIsNext ? "X" : "O");
}
return (
);
}
}
// ========================================
ReactDOM.render( , document.getElementById("root"));
console.log('✓')
function calculateWinner(squares) {
const lines = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6]
];
for (let i = 0; i < lines.length; i++) {
const [a, b, c] = lines[i];
if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
return squares[a];
}
}
return null;
}
;PK
ór}XÁÞ«Ï Ï # react-in-a-tweet-1.0.0/package.json{
"name": "@runkit/asyncanup_react-in-a-tweet",
"version": "1.0.0",
"main": "./lib/react-in-a-tweet",
"dependencies": {},
"scripts": {
"install": "node scripts/install.js"
}
}PK
ór}XnÀlwd d * react-in-a-tweet-1.0.0/npm-shrinkwrap.json{
"name": "@runkit/asyncanup_react-in-a-tweet",
"version": "1.0.0",
"dependencies": {}
}PK
ór}X react-in-a-tweet-1.0.0/scripts/PK
ór}X çšCZ Z ) react-in-a-tweet-1.0.0/scripts/install.jsvar fs = require('fs');
var path = require('path');
var json = require("../package.json");
var match = json.name.match(/^@runkit\/(.*)_(.*)$/);
// check if our module name actually makes sense, otherwise abort
if (!match) throw new Error("Unknown package structure!");
// check if we're actually inside a node_modules/@runkit folder, otherwise don't create symlinks
if (path.basename(path.dirname(process.cwd())) !== "@runkit" || path.basename(path.dirname(path.dirname(process.cwd()))) !== "node_modules") {
console.log("Not installing as notebook: " + process.cwd());
return;
}
console.log("creating notebook symlinks");
var userPath = path.join("..", match[1]);
var repoPath = path.join(userPath, match[2]);
mkdir(userPath);
mkdir(repoPath);
var branchMatch = json.version.match(/^0\.0\.0\-(.*)$/);
if (branchMatch) {
var branchPath = path.join(repoPath, "branches");
mkdir(branchPath);
var versionPath = path.join(branchPath, branchMatch[1]);
var relativePath = path.join("..", "..", "..", path.basename(process.cwd()));
unlink(versionPath);
fs.symlinkSync(relativePath, versionPath);
} else {
var relativePath = path.join("..", "..", path.basename(process.cwd()));
var latestPath = path.join(repoPath, "latest");
var versionPath = path.join(repoPath, json.version);
unlink(latestPath);
fs.symlinkSync(relativePath, latestPath);
unlink(versionPath);
fs.symlinkSync(relativePath, versionPath);
}
function mkdir(p) {
try {
fs.mkdirSync(p);
} catch (e) {}
}
function unlink(p) {
try {
fs.unlinkSync(p);
} catch (e) {}
}PK
ór}X react-in-a-tweet-1.0.0/PK
ór}X 5 react-in-a-tweet-1.0.0/lib/PK
ór}Xö8û¢~ ~ . n react-in-a-tweet-1.0.0/lib/react-in-a-tweet.jsPK
ór}XÁÞ«Ï Ï # 8 react-in-a-tweet-1.0.0/package.jsonPK
ór}XnÀlwd d * H react-in-a-tweet-1.0.0/npm-shrinkwrap.jsonPK
ór}X ô react-in-a-tweet-1.0.0/scripts/PK
ór}X çšCZ Z ) 1 react-in-a-tweet-1.0.0/scripts/install.jsPK 7 Ò&