View flow-example.js
// no types
function getFields(fields) {
return fields.reduce((prev, curr) => (prev[curr] = curr, prev), {})
}
// no return type
function getFields(fields: Array<string>) {
return fields.reduce((prev, curr) => (prev[curr] = curr, prev), {})
}
View webpack-unused-files.sh
# ----------------------------------- #
webpack --display-modules | awk '{print $2}' | grep ^\.\/ > files-processed.txt;
cd public/js/; # assumes all your files are here
find . -name "*.js" | grep -v eslint | grep -v __ > ../../files-all.txt; # excludes __tests__ and .eslintrc files
cd ../..;
cat files-all.txt | xargs -I '{}' sh -c "grep -q '{}' files-processed.txt || echo '{}'";
rm files-processed.txt files-all.txt;
# ----------------------------------- #
View promise-anti-patterns.md
View flow-experience.md

Trying Flow on my node.js code…Let’s see how this goes

Finding the getting started guide:

  1. google flow
  2. click “getflow.com”
  3. was something else
  4. google flow javascript
  5. found flowtype.org
  6. Click “get started” and landed here https://flowtype.org/docs/getting-started.html#_
View async-router.js
// catch any errors in the promise and either forward them to next(err) or ignore them
const catchErrors = fn => (req, res, next) => fn(req, res, next).catch(next)
const ignoreErrors = fn => (req, res, next) => fn(req, res, next).catch(() => next())
// wrap my routes in those helpers functions to get error handling
app.get('/sendMoney/:amount', catchErrors(sendMoney))
// use our ignoreErrors helper to ignore any errors in the logging middleware
app.get('/doSomethingElse', ignoreErrors(logSomething), doSomethingElse)
View await-fail.js
// rely on try/catch around the awaited Promise
async function doSomething() {
try {
let data = await getData()
} catch (err) {
console.error(err)
}
}
// add a catch handler
View await-fail.js
// basic error handling with async functions
async function getData(param) {
if (isBad(param)) {
throw new Error("this is a bad param")
}
// ...
}
// basic promise-based error handling example
function getData(param) {
View await.js
// async function to show user data
async function displayUserData() {
let me = await fetch('/users/me')
console.log(me)
}
// promise-based equivalent
function displayUserData() {
return fetch('/users/me').then(function(me) {
console.log(me)
View async-wait.js
// here is an async function
async function getNumber() {
return 4 // actually returns a Promise
}
// the same function using promises
function getNumber() {
return Promise.resolve(4)
}
View webpack-sorted-sizes.sh
webpack --display-modules | awk '{print $3$4" "$2}' | grep -v bytes | sort -n | tail -100