View top-state.js
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
const stateMap = {}; | |
function render(state) { | |
for (const component of state.components) component.forceUpdate(); | |
} | |
export default function useTopState(name, initialValue) { | |
let state = stateMap[name]; | |
if (!state) { |
View gist:7876a4629ba11291ed65882c5d364f04
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
// Original code | |
const score = 7; | |
const someVar = | |
score < 10 ? 'some long string' : | |
score < 20 ? 'this is looking promising' : | |
score < 30 ? 'passing' : | |
score < 40 ? 'proficient' : | |
'expert'; | |
// What Prettier does |
View type-classes.js
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
const colorNameToHexMap = { | |
red: 'FF0000', | |
green: '00FF00', | |
blue: '0000FF' | |
}; | |
const colorHexToNameMap = { | |
FF0000: 'red', | |
'00FF00': 'green', | |
'0000FF': 'blue' |
View type-classes.hs
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
import qualified Data.Map as Map | |
-- A tuple of three Ints | |
type RGB = (Int, Int, Int) | |
-- Colors can be specified in three ways. | |
data Color = | |
ColorName String | | |
ColorHex String | | |
ColorRgb Int Int Int |
View demo.hs
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
instance LogType (IO a) where | |
logn' arr = do | |
-- Call putStr on all the elements in arr. | |
mapM_ putStr arr -- functions that end in _ ignore their result | |
-- Output a newline. | |
putStrLn "" | |
-- The "do" block must return something. | |
return undefined | |
instance (Show a, LogType r) => LogType (a -> r) where |
View matt-follett.js
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
// @flow | |
type Action1Type = { | |
type: 'A1', | |
payload: { | |
name: string | |
} | |
}; | |
type Action2Type = { |
View demo.js
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
const double = require('./math').double; | |
console.log(double('20')); |
View math.js
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
// @flow | |
function product(a, b) { | |
return a * b; | |
} | |
exports.product = product; |
View foo.js
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
stream.on('readable', function () { | |
var data; | |
while (true) { | |
data = stream.read(); | |
if (data === null) break; | |
// use the data | |
} | |
}); | |
stream.on('end', function () { |
View form.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
<html> | |
<head> | |
<title>Test Form</title> | |
<script src="form.js"></script> | |
</head> | |
<body> | |
<form id="myform" method="post" action="http://localhost:3000"> | |
<label for="name">Name:</label> | |
<input id="name" name="name" type="text"/> | |
<button type="submit">Go!</button> |
NewerOlder