Skip to content

Instantly share code, notes, and snippets.

View lemonmade's full-sized avatar

Chris Sauve lemonmade

View GitHub Profile
@lemonmade
lemonmade / sentry-init.ts
Created August 9, 2021 13:46
How to pass the `Fetch` transport to Sentry
import * as Sentry from '@sentry/browser';
Sentry.init({
transport: Sentry.Transports.FetchTransport,
});
!function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s="./src/index.js")}({"./src/index.js":function(e,n,t){"use strict";t.r(n),function(){var e;(e=self.shopify).extend.app
@lemonmade
lemonmade / server.ts
Last active February 4, 2019 23:22
Web DataDog metrics
import {StatsD} from 'hot-shots';
const statsd = new Client({
host: process.env.STATSD_HOST,
port: process.env.STATSD_PORT,
prefix: 'ShopifyWeb.',
});
// An array of objects with some details about browser events
// (time to first byte, first paint, etc)
// in @shopify/polaris-adapter
enum Action {
Replace,
Augment,
Ignore,
}
type Behavior<Props> =
| {action: Action.Ignore}
| {
export default app({
name: 'shopify-web',
kind: AppKind.Admin,
entries: [
browser({
polaris: true,
targets: [
BrowserTarget.Admin,
BrowserTarget.LatestEvergreen,
],
@lemonmade
lemonmade / Component.test.js
Created April 17, 2018 23:11
Partial Jest mock
import {utility} from './support';
jest.mock('./support', () => ({
...require.requireActual('./support'),
utility: jest.fn(),
}));
import {Component} from 'react';
const cache = new WeakMap<Component<any, any>, Map<string, any>>();
export function toggleState<S>(component: Component<any, S>, key: keyof S) {
const cachedToggles = cache.get(component) || new Map();
if (cachedToggles.has(key)) { return cachedToggles.get(key); }
const toggle = () => component.setState((state) => ({[key]: !state[key]}));
cachedToggles.set(key, toggle);
import {DataProxy} from 'apollo-client/data/proxy';
import {
ApolloClient,
} from 'apollo-client';
import {DocumentNode} from 'graphql';
import {get} from 'lodash';
import {Status} from '../network';
import stagedFileUploadMutation, {StagedFileUploadMutationData} from './StagedFileUploadMutation.graphql';
@lemonmade
lemonmade / FlowTester.js
Last active January 3, 2017 18:55
To type or not to type
// @flow
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
type TestDetails<T: HTMLElement> = {
node: HTMLElement,
};
type Props = {