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
// this helper function takes as argument the function that will be curried | |
function curry(func) { | |
return function accumulator() { | |
var args = [].slice.call(arguments); | |
return args.length < func.length ? accumulator.bind.apply(accumulator, [null].concat(args)) : func.apply(null, args); | |
}; | |
} | |
// Use it: first create two function that will be curried | |
function add(a,b,c) { |
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
// select an element to style | |
const container = document.querySelector('#container'); | |
// this is not ideal... | |
container.style.width = '400px;'; | |
container.style.height = '300px'; | |
container.style.top = '0'; | |
container.style.left = '50%'; | |
// let's assign all styles in one go! |
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
// HasKey checks whether the given object has the specified key 'K' | |
type HasKey<K extends string, V = unknown> = {[_ in K]: V}; | |
// curried getter | |
const get = <K extends string, O extends HasKey<K>>(key: K) => (obj: O): O[K] => obj[key]; | |
// the object to check | |
const Person = {name: 'Danny', age: '47'}; | |
const getAge = get('age'); |
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
// give your cache a name | |
const cacheName = 'my-cache'; | |
// put the static assets and routes you want to cache here | |
const filesToCache = [ | |
'/', | |
'/about', | |
'/index.html', | |
'/about.html', | |
'/css/styles.css', |
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 version = 1; | |
const cacheName = `our_awesome_cache` | |
// the static files we want to cache | |
const staticFiles = [ | |
'index.html', | |
'src/css/styles.css', | |
'src/img/logo.png', | |
'src/js/app.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
console.log('foo') |