Skip to content

Instantly share code, notes, and snippets.

@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
@kellyrmilligan
kellyrmilligan / index-example.js
Created June 8, 2017 14:39
integration example for redux and cra
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { updateServiceworker } from 'service-worker-redux'
import configureStore from 'store/configure-store'
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
const store = configureStore()
@kellyrmilligan
kellyrmilligan / service-worker-redux.js
Created June 8, 2017 14:32
redux example for service worker notification
import { createSelector } from 'reselect'
// CONSTANTS
export const UPDATE_SERVICEWORKER = 'UPDATE_SERVICEWORKER'
export function updateServiceworker () {
return {
type: UPDATE_SERVICEWORKER
}
}
@kellyrmilligan
kellyrmilligan / circle-deployment-example.yml
Created June 8, 2017 13:42
circle config file example for calling shell script from deployment section
deployment:
prod:
branch: master
commands:
- NODE_ENV=production yarn run build
- ./bin/s3Sync.sh [s3 bucket name]
staging:
branch: staging
commands:
@kellyrmilligan
kellyrmilligan / bucket-policy-s3-example
Last active June 8, 2017 13:24
bucket policy example for deploying to s3 with circleci
{
"Version": "2012-10-17",
"Id": "Policy1489770524467",
"Statement": [
{
"Sid": "Stmt1489770487230",
"Effect": "Allow",
"Principal": {
"AWS": "[arn of iam user you created for circleci]"
},
@kellyrmilligan
kellyrmilligan / fetchUtils.js
Last active May 10, 2017 13:53
reduce boilerplate in handling fetch responses and errors in redux actions
function isJson (response) {
const contentType = response.headers.get('content-type')
return contentType && contentType.indexOf('application/json') !== -1
}
export function handleResponse (response) {
if (response.ok) {
if (isJson(response)) {
return response.json()
} else {
<% if (process.env.NODE_ENV !== 'development') { %>
<script>
var _rollbarConfig = {
accessToken: '%REACT_APP_ROLLBAR_TOKEN%',
captureUncaught: true,
captureUnhandledRejections: true,
payload: {
environment: '%NODE_ENV%',
client: {
javascript: {
@kellyrmilligan
kellyrmilligan / circle-example.yml
Last active April 27, 2017 15:45
example circle ci yml
deployment:
prod:
branch: master
commands:
- NODE_ENV=production REACT_APP_GIT_SHA=$CIRCLE_SHA1 REACT_APP_ROLLBAR_TOKEN=$ROLLBAR_TOKEN yarn run build