This file contains hidden or 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
| import React from 'react'; | |
| import connect from './connect'; | |
| // model | |
| class User { | |
| name = null; | |
| } | |
| // view | |
| const _App = ({ user }) => user.name === null |
This file contains hidden or 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
| 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 | |
| }; | |
| } | |
| }); |
This file contains hidden or 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
| 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> |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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); | |
| } |
This file contains hidden or 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
| 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>) | |
| } |
This file contains hidden or 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
| const fs = require('fs'); | |
| const JSON5 = require('json5'); | |
| const [file] = process.argv.slice(2); | |
| fs.writeFileSync( | |
| file.replace(/\.json5$/, '.json'), | |
| JSON.stringify( | |
| JSON5.parse( fs.readFileSync(file) ), | |
| null, |
This file contains hidden or 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
| const loadImage = src => new Promise((resolve, reject) => Object.assign(new Image(), { | |
| src, | |
| onload() { | |
| resolve(this); | |
| }, | |
| onerror(err) { | |
| reject(err); | |
| }, | |
| })); |
This file contains hidden or 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
| const promisify = func => | |
| (...args) => | |
| new Promise((resolve, reject) => | |
| func(...args, (err, result) => | |
| err && reject(err) || resolve(result) | |
| ) | |
| ); |
This file contains hidden or 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
| function splice(array, ...args) { | |
| let newArray = [...array]; | |
| newArray.splice(...args); | |
| return newArray; | |
| } |