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
<!DOCTYPE html> | |
<html dir="ltr" lang="en-US"> | |
<head> | |
<base href="https://raw.githubusercontent.com/rachelandrew/css-for-print/master/"> | |
<style> | |
/* this stylesheet is used when generating a PDF with PrinceXML or any other tool that understands the CSS used. */ | |
/* define a page */ | |
@page { | |
size: 5.5in 8.5in; |
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 createDb from './database.js'; | |
import { randomWait, log } from './helper.js'; | |
const db = createDb(); | |
// Current middleware approach | |
const logger = log('Full'); | |
// Simulated two concurrent fetch and save requests | |
Promise.all([ |
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
// Helper function to generate random delay | |
function randomWait() { | |
return new Promise(resolve => { | |
setTimeout(resolve, Math.ceil(Math.random() * 1000)); | |
}); | |
} | |
// The "database" | |
const dataStore = { | |
// Records Collection |
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 makeCheeseSandwich({bread, cheeses, condiments = ['mustard']}) { | |
return {bread, cheeses, condiments}; | |
} | |
console.log(makeCheeseSandwich(dagwoodSandwich)); | |
// output: { bread: 'rye', cheeses: [ 'cheddar' ], condiments: [ 'mustard' ] } |
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
// The argument name syntax is a Destructuring Assignment | |
function makeCheeseSandwich({bread, cheeses}) { | |
return {bread, cheeses}; | |
} | |
console.log(makeCheeseSandwich(dagwoodSandwich)); | |
// output: { bread: 'rye', cheeses: [ 'cheddar' ] } |
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
let {bread, cheeses, condiments = ['mustard']} = dagwoodSandwich; | |
console.log({bread, cheeses, condiments}); | |
// output: { bread: 'rye', cheeses: ['cheddar'], condiments: ['mustard'] } |
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
let dagwoodSandwich = { | |
bread: 'rye', | |
cheeses: ['cheddar'], | |
meats: ['salami', 'ham', 'turkey', 'bologna'], | |
toppings: ['lettuce', 'tomatoes', 'onions', 'fried egg', 'olives'] | |
}; | |
let {bread, cheeses} = dagwoodSandwich; // <-- Destructuring Assignment | |
console.log({bread, cheeses}); // ouptut: { bread: 'rye', cheeses: ['cheddar'] } |
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
/* ES5 equivalent (ignoring assignment of intended falsy values) | |
var obj = {}; | |
var one = obj.one; | |
var two = obj.two || 2; | |
*/ | |
let obj = {}; | |
let {one, two = 2} = obj; | |
console.log({one, two}); // output: { one: undefined, two: 2 } |
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
/* ES5 equivalent (ignoring assignment of intended falsy values) | |
function foo(one, two) { | |
one = one || 1; | |
console.log({one, two}); | |
} | |
*/ | |
function foo(one = 1, two) { | |
console.log({one, two}); | |
} |
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
/* ES5 equivalent (ignoring assignment of intended falsy values) | |
var arr = []; | |
var one = arr[0] || 1; | |
var two = arr[1]; | |
*/ | |
let arr = []; | |
let [one = 1, two] = arr; | |
console.log({one, two}); // output: { one: 1, two: undefined } |
NewerOlder