Skip to content

Instantly share code, notes, and snippets.

// Variable Assignment
const getData = async function () {
try {
const data = await fakeAsyncCall();
console.log(data); // foo data
} catch (error) {
console.error(`Uh oh: ${error}`);
}
};
async function getData() {
try {
const data = await fakeAsyncCall();
console.log(data); // foo data
} catch (error) {
console.error(`Uh oh: ${error}`);
}
}
function fakeAsyncCall(resultText = 'foo data') {
return new Promise((resolve, reject) => {
if (typeof resultText !== 'string') {
return reject('result text should equal string');
}
setTimeout(() => { resolve(resultText) }, 1000);
});
}
async function getData() {
async function getData() {
const f1 = await fakeAsyncCall();
const f2 = await fakeAsyncCall();
const f3 = await fakeAsyncCall();
const f4 = await fakeAsyncCall();
console.log(f1, f2, f3, f4); // 'foo data' x 4
}
function fakeAsyncCall(resultText = 'foo data') {
return new Promise((resolve) => {
setTimeout(() => resolve(resultText), 1000);
});
}
function getData() {
fakeAsyncCall()
.then(fakeAsyncCall)
.then(fakeAsyncCall)
@johnstew
johnstew / index.js
Created July 13, 2017 20:31
Exploring App State
function equal(objA, objB) {
const sObjA = JSON.stringify(objA);
const sObjB = JSON.stringify(objB);
return (sObjA === sObjB);
}
class AppState {
constructor(state = {}, components = []) {
this.state = state;
this.components = components;
@johnstew
johnstew / icons.sh
Created March 4, 2017 15:46
Replace Atom Icon (maybe other icons also)
# Steps taken from here: https://sethvargo.com/replace-icons-osx/
ls /Applications/Atom.app/Contents/Resources | grep .icns
cp ~/.custom-icons/atom.icns /Applications/Atom.app/Contents/Resources/atom.icns
touch /Applications/Atom.app
sudo killall Finder && sudo killall Finder
@johnstew
johnstew / package.json
Created February 2, 2017 00:49
tree-shaking webpack package.json
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "",
"scripts": {
"start": "webpack --config webpack.config.js",
"build": "webpack -p --config webpack.config.js"
},
"keywords": [],
@johnstew
johnstew / index.bundle.js
Created February 2, 2017 00:35
tree-shaking webpack index.bundle.js
([function(e, t, n) {
"use strict";
function r() {
console.log("foo called")
}
// NO MORE BAR :)
t.a = r
}, function(e, t, n) {
"use strict";
@johnstew
johnstew / index.bundle.js
Created February 2, 2017 00:33
tree-shaking webpack index.bundle.js
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (immutable) */ __webpack_exports__["a"] = foo;
/* unused harmony export bar */
function foo() {
console.log('foo called');
}