Skip to content

Instantly share code, notes, and snippets.

@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 / registerServiceWorker.js
Last active April 10, 2018 11:29
modified service worker registration from create react app
// In production, we register a service worker to serve assets from local cache.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on the "N+1" visit to a page, since previously
// cached resources are updated in the background.
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
// This link also includes instructions on opting out of this behavior.
@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 / s3Sync.sh
Created June 8, 2017 13:38
Sync files to s3 and set cache control headers
#!/bin/bash
if [[ "$1" != "" ]]; then
S3BUCKETNAME="$1"
else
echo ERROR: Failed to supply S3 bucket name
exit 1
fi
aws s3 sync build s3://$S3BUCKETNAME --delete --cache-control max-age=31536000,public
@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
import React, { Component } from 'react'
import { withRouter } from 'react-router'
import reactRouterFetch from 'react-router-fetch'
class App extends Component {
state = {
isAppFetching: false,
appFetchingError: null
}
reactRouterFetch(routeConfig, location, { dispatch })
.then((results) => {
this.setState({
isAppFetching: false
})
})
.catch((err) => {
this.setState({
isAppFetching: false,
appFetchingError: err