Skip to content

Instantly share code, notes, and snippets.

// given a database of global parcels like this...
const allGlobalParcels = [
{
created: 576424800000,
location: "aus",
properties: { ... },
},
{
created: 1558163267311,
location: "us",
// given a database of global parcels like this...
const allGlobalParcels = [
{
created: 576424800000,
location: "aus",
properties: { ... },
},
{
created: 1558163267311,
location: "us",
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
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");
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],
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 */
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 */ },
// 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]