Acts like objects but uses indeces as keys
const array = [ 1, 2, 3 ]
const newArray = [...array, 4: 5 ]
create-react-app $NAME | |
npm install --save electron | |
npm run eject | |
replace scripts/start.js with this start.js | |
replace config/webpack.config.dev.js with this webpack.config.dev.js |
import ast | |
import jedi | |
from os import path | |
from pipenv.project import Project | |
from git import Repo | |
from git.refs.tag import TagReference | |
from pkg_resources import get_distribution | |
class Semver: |
import React from 'react'; | |
import connect from './connect'; | |
// model | |
class User { | |
name = null; | |
} | |
// view | |
const _App = ({ user }) => user.name === null |
import Form from './form.jsx'; | |
const App = (setState) => ({ entities }) => ( | |
<div> | |
<h1>Entities Editor</h1> | |
<h2>Select an entity</h2> | |
<div>{ | |
entities.map(entity => ( | |
<div> | |
<h3>{ entity.id }</h3> |
const WithPath = (target, path = []) => new Proxy(target, { | |
get(target, property, receiver) { | |
const value = target[property]; | |
const thisPath = [...path, property]; | |
return { | |
...(typeof value !== 'object' ? value : WithPath(value, thisPath)), | |
[WithPath.Path]: thisPath | |
}; | |
} | |
}); |
function component(...args) { | |
const [func, opts = {}] = args.reverse(); | |
if (opts.constructor !== Object) { | |
throw new Error('Options must be a plain object'); | |
} | |
class FunctionalComponent extends (opts.impure ? React.Component : React.PureComponent) { | |
constructor() { | |
super(...arguments); | |
this.setState = this.setState.bind(this); | |
} |
import { Label } from './label.scss'; | |
export default function Form({ fields }) { | |
return fields.map(field => <div> | |
<Label color="red" highlighted>{field}</Label> | |
<input type="text" /> | |
</div>) | |
} |
const loadImage = src => new Promise((resolve, reject) => Object.assign(new Image(), { | |
src, | |
onload() { | |
resolve(this); | |
}, | |
onerror(err) { | |
reject(err); | |
}, | |
})); |
const promisify = func => | |
(...args) => | |
new Promise((resolve, reject) => | |
func(...args, (err, result) => | |
err && reject(err) || resolve(result) | |
) | |
); |