Skip to content

Instantly share code, notes, and snippets.

const React = require('react');
const PropTypes = React.PropTypes;
const { connect } = require('react-redux');
const Modal = require('react-modal');
const { closeModal } = require('actions/modal');
const MODAL_STYLE = {
content: {
const PRECACHE = 'precache-v1';
const RUNTIME = 'runtime';
// A list of local resources we always want to be cached.
const PRECACHE_URLS = [
'index.html',
'./', // Alias for index.html
'styles.css',
'../../styles/main.css',
'demo.js'
const makeServiceWorkerEnv = require('service-worker-mock');
describe('Service worker', () => {
beforeEach(() => {
Object.assign(global, makeServiceWorkerEnv());
jest.resetModules();
});
// ...
});
const makeServiceWorkerEnv = require('service-worker-mock');
describe('Service worker', () => {
beforeEach(() => {
Object.assign(global, makeServiceWorkerEnv());
jest.resetModules();
});
it('should delete old caches on activate', async () => {
require('../sw.js');
const makeServiceWorkerEnv = require('service-worker-mock');
const Response = () => ({ clone: jest.fn() });
const Request = () => ({ url: '/test' });
describe('Service worker', () => {
beforeEach(() => {
Object.assign(global, makeServiceWorkerEnv());
jest.resetModules();
});
{
caches: {
CACHE_V1: {}
},
clients: [],
notifications: [],
}
@zackargyle
zackargyle / DeferredMount.js
Last active March 28, 2017 18:47
React component for deferring rendering until post-mount.
/*
<DeferredMount ssr />
This component defers rendering of its children until after mounting, good
for below-the-fold content. If the content should be rendered syncronously
on the server you can set the `ssr` prop. If `ssr` is set to true, there
will be a client/server mismatch unless you can somehow determine that we
are hydrating from the server.
Is there a better way than the hack below?
*/
type Props = {
match: { params: { username: string } },
resource: { fetching: boolean },
user: User,
};
export default withResource({
name: 'UserResource',
key: 'resource',
options: ({ match }: Props) => ({
@zackargyle
zackargyle / Homefeed.jsx
Last active September 27, 2017 17:26
Home page layout
const Homefeed = createFeed({
feedKey: 'homefeed',
resourceName: 'UserHomefeedResource',
resourceOptions: () => ({
field_set_key: 'mobile_grid_item',
}),
pullToRefresh: true,
});
const HomePage = (props: Props) => (
@zackargyle
zackargyle / sample-codesplitting.js
Last active October 12, 2017 20:44
Sample of Pinterest Mweb code splitting
// Create a loader
const Closeup = () => import(/* webpackChunkName: "CloseupPage" */ 'app/mobile/routes/CloseupPage');
// Register it to the route
route('/pin/:pinId', routes.Closeup, { name: 'Closeup' }),
// Render a react-router-v4 Route with the route bundle loader
<Route exact key="matched-route" path={path} render={matchProps =>
<PageRoute
bundleLoader={loader}