Skip to content

Instantly share code, notes, and snippets.

@kellyrmilligan
kellyrmilligan / start.js
Created December 13, 2017 21:01
start.js - adjusted
'use strict';
// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'development';
process.env.NODE_ENV = 'development';
// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
@kellyrmilligan
kellyrmilligan / webpackDevServer.config.js
Created December 13, 2017 20:54
webpackDevServer.config.js - adjusted
'use strict';
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
const path = require('path');
const config = require('./webpack.config.dev');
const paths = require('./paths');
const express = require('express');
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
@kellyrmilligan
kellyrmilligan / webpack.config.dev.js
Created December 13, 2017 20:45
webpack.config.dev.js - adjusted
'use strict';
const autoprefixer = require('autoprefixer');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
const eslintFormatter = require('react-dev-utils/eslintFormatter');
const List = ({ items, onClick }) => (
<ul>
{items.map(item => (
<ClickHandler key={item.id} data={item} onClick={onClick}>
{(handleClick) => (
<li onClick={handleClick}>
{item.text}
</li>
)}
</ClickHandler>
const List = ({ items, onClick }) => (
<ul>
{items.map(item => (
<li onClick={() => onClick(item)}>
{item.text}
</li>
))}
</ul>
)
const List = ({ items, onClick }) => (
<ul>
{items.map(item => (
<li>
{item.text}
</li>
))}
</ul>
)
@kellyrmilligan
kellyrmilligan / multiple calls from a loop with caching
Last active August 22, 2017 18:35
multiple calls with client side caching
import CacheClientPromise from 'cache-client-promise'
const myCache = new CacheClientPromise();
[{
id: 1234,
title: 'test',
view: 'two-column'
},
{
@kellyrmilligan
kellyrmilligan / multiple calls from a loop
Created August 22, 2017 17:00
multiple calls from a result - no caching
[{
id: 1234,
title: 'test',
view: 'two-column'
},
{
id: 1234,
title: 'test',
view: 'image-only'
}]
@kellyrmilligan
kellyrmilligan / flow type example
Last active July 6, 2017 14:44
flow type example
// @flow
import React from 'react'
import classnames from 'classnames'
import type { ButtonT } from './ButtonT'
const Button = ({ className, type = 'button', text, tabIndex, onClick = () => {}, disabled = false }: ButtonT) => (
<button
className={classnames('button', className)}
type={type}
@kellyrmilligan
kellyrmilligan / App-example.js
Created June 8, 2017 14:49
sending a notification when service worker is updated in top level component
componentWillReceiveProps (nextProps) {
// see if new content was found by the service worker
if (nextProps.serviceWorker.serviceWorkerUpdated) {
this.setState({
notifications: this.state.notifications.concat({
'The app has been updated! Hooray! Refresh your browser to enjoy the latest and greatest',
'some unique key',
action: 'Dismiss',
dismissAfter: 4000,
onClick: this.removeNotification