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
// Compare two arrays(primary and secondary) and return all array items that are unique to the primary array | |
const getDiff = (primaryArray, secondaryArray) => { | |
return primaryArray.filter(item => secondaryArray.indexOf(item) === -1); | |
}; | |
// getDiff([1, 2, 3, 5], [1, 3, 4]) | |
// => [2, 5] |
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 { createRequest } from 'request-state-wrapper'; | |
const getRepoDetails = () => | |
fetch('https://api.github.com/repos/nodejs/node').then(response => response.json()); | |
// Create your request with request-state-wrapper | |
const request = createRequest({ | |
request: getRepoDetails, | |
stalledDelay: 1000, | |
onStalled: () => { /* handle stalled state */ }, |
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 getNodeRepoDetails = () => | |
fetch('https://api.github.com/repos/nodejs/node').then(response => response.json()); | |
const getGoRepoDetails = () => | |
fetch('https://api.github.com/repos/golang/go').then(response => response.json()); | |
Promise.all([getNodeRepoDetails(), getGoRepoDetails()]) | |
.then(response => { | |
const [ nodeResponse, goResponse ] = response; | |
/* handle request response */ |
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 { createRequest } from 'request-state-wrapper'; | |
const getNodeRepoDetails = () => | |
fetch('https://api.github.com/repos/nodejs/node').then(response => response.json()); | |
const getGoRepoDetails = () => | |
fetch('https://api.github.com/repos/golang/go').then(response => response.json()); | |
const request = createRequest({ | |
request: [getNodeRepoDetails, getGoRepoDetails], |
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 createURL = (baseURL, path) => { | |
const protocol = "https"; | |
return `${protocol}://${baseURL}/${path}`; | |
}; | |
// create URLs for our main site | |
const homeURL = createURL("mysite.com", ""); | |
const loginURL = createURL("mysite.com", "login"); | |
const productsURL = createURL("mysite.com", "products"); | |
const contactURL = createURL("mysite.com", "contact-us"); |
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 createURL = baseURL => { | |
const protocol = "https"; | |
// we now return a function, that accepts a 'path' as an argument | |
return path => { | |
return `${protocol}://${baseURL}/${path}`; | |
}; | |
}; | |
// we create a new functions with the baseURL value in it's closure scope |
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
// given a database of global parcels like this... | |
const allGlobalParcels = [ | |
{ | |
created: 576424800000, | |
location: "aus", | |
properties: { ... }, | |
}, | |
{ | |
created: 1558163267311, | |
location: "us", |
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
// given a database of global parcels like this... | |
const allGlobalParcels = [ | |
{ | |
created: 576424800000, | |
location: "aus", | |
properties: { ... }, | |
}, | |
{ | |
created: 1558163267311, | |
location: "us", |