Skip to content

Instantly share code, notes, and snippets.

View faceyspacey's full-sized avatar

James Gillmore faceyspacey

View GitHub Profile
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
const json = `{
"Status": "Success",
"Errors": [],
"Paging": [],
"Notices": [],
"Message": null,
"Data": {
"certifications": [
{
"name": "American Standard Certification",
const job1 = cb => setTimeout(() => cb('first'), 900)
const job2 = cb => setTimeout(() => cb('second'), 100)
const job3 = cb => setTimeout(() => cb('third'), 300)
const jobs = [job1, job2, job3]
const asyncMap = (jobs, callback) => {
const jobPromises = jobs.map(job => { // loop through jobs
return new Promise((resolve, reject) => { // return a promise for each item in the array
return job(resolve) // resolve each promise to the value passed to cb()
class MyComponent extends React.Component {
render() {
// <View> will expand to the dimensions of DropZone within it
return <View ref={view => { this.myComponent = view; }}><DropZone /></View>
}
componentDidMount() {
this.myComponent.measure((x, f, width, height, px, py) => {
console.log('MyComponent width is: ' + width)
console.log('MyComponent height is: ' + height)
'use strict';
module.exports = (arr, reducer, initVal) => new Promise((resolve, reject) => {
let i = 0;
const next = total => {
const item = arr[i];
if (!item) {
resolve(total);
@faceyspacey
faceyspacey / pathless-routes-with-redux-first-router.js
Last active June 3, 2020 00:26
Quick example showing how to use pathless routes in Redux-First Router
import api from './api'
const routesMap = {
HOME: '/', // path only route
LIST: { // route object (with a path)
path: '/list/:slug',
thunk: async (dispatch, getState) => {
const { slug } = getState().location.payload
const response = await fetch(`/api/items/${slug}`)
const items = await data.json()
const history = createHistory({
getUserConfirmation(message, callback) {
confirmationDialog(message, (res) => {
shouldChange = !!res
callback(res)
})
}
})
history.block((location, action) => {
const routesMap = {
ADMIN: {
path: '/admin',
role: 'admin'
}
}
const { ...theUsual, thunk, initialDispatch } = connectRoutes(
history,
routesMap, {
...options,
initialDispatch: isServer ? false : true
}
)
...
export default async (req, res) => {
const jwToken = req.cookies.jwToken
const preLoadedState = { jwToken }
const history = createHistory({ initialEntries: [req.path] })
const { store, thunk } = configureStore(history, preLoadedState)
...