Skip to content

Instantly share code, notes, and snippets.

View ctrlplusb's full-sized avatar
📢

Sean Matheson ctrlplusb

📢
View GitHub Profile
@toddgeist
toddgeist / start.js
Created June 7, 2016 17:14
Using dotenv to load vars when dploying to now. But still keep it out of your repo.
// load as early as possible
if(process.env.NOW){
require('dotenv').config({path:'./.envnow', silent:true});
}else{
require('dotenv').config({silent:true});
}
// now you can deploy with:
//$cp .env .envnow && now && rm -r .envnow

Notes

  • This code handles any JS runtime error during rendering React components. Without this handling, once an error occurs, whole component tree is damaged and can't be used at all. With this handling, nothing will be rendered in production environment (error span in dev env.) + in production the error is logged to Sentry (if you are not using it just delete related code)
  • This is basicaly a workaround for proposed feature in React core - described in Issue: facebook/react#2461
  • Works for all variants of Component creation - React.createClass, extending React.Component and also stateless functional components.
  • To get this work, just put this snippet into your entry js file. Then it will work in whole application.
  • Also supporting React Hot Reload!
  • If you find this useful, please retweet https://twitter.com/Aldredcz/status/744650159942995968 :)

Ideas

  • specify custom error renderer (global / per component, e.g. by implementing method renderOnError() in a comp
@mzgoddard
mzgoddard / 00.script-async-attr-support-plugin.js
Created November 16, 2016 19:34
Plugin brainstorm to support async attribute use on script tags with webpack.
function ScriptAsyncAttrSupportPlugin() {}
module.exports = ScriptAsyncAttrSupportPlugin;
ScriptAsyncAttrSupportPlugin.prototype.apply = function(compiler) {
compiler.plugin('this-compilation', function(compilation) {
compilation.mainTemplate.plugin('bootstrap', function(source) {
return this.asString([
source,
'',
@chrisui
chrisui / recon-stats.txt
Last active February 19, 2017 14:43
recon$ stats
These stats were made available from https://github.com/lystable/recon
Num modules parsed
How many modules did we explore?
1243
---
Num components
//https://gist.github.com/quelgar/4661081
const daggy = require('daggy');
const {range} = require('ramda');
// type to hold an index and the array
const Pointer = daggy.tagged('i', 'a')
// Comonad instance
Pointer.prototype.extract = function() { return this.a[this.i] }
@gcanti
gcanti / HOC.js
Created September 14, 2016 09:24
/* @flow */
import React from 'react'
import ReactDOM from 'react-dom'
type FunctionComponent<A> = (props: A) => ?React$Element<any>;
type ClassComponent<D, A, S> = Class<React$Component<D, A, S>>;
type Component<A> = FunctionComponent<A> | ClassComponent<any, A, any>;
@MoOx
MoOx / .flowconfig
Last active July 12, 2018 01:44
flow config webpack adjustements to avoid the "Required module not found" for png, css, svg etcc
# ...
[options]
# webpack loaders
module.name_mapper='.*\.css$' -> '<PROJECT_ROOT>/flow/stub/css-modules.js'
module.name_mapper='.*\.\(svg\|png\|jpg\|gif\)$' -> '<PROJECT_ROOT>/flow/stub/url-loader.js'
@jimfb
jimfb / wrapper.js
Last active November 6, 2018 04:41
class MyWrapper {
return React.Children.only(this.props.children);
}
class MyLibraryComponent {
render() {
return <div><span><whatever><MyWrapper ref=...>{this.props.statelessComponentThatIWantToReference}</MyWrapper></whatever></span></div>;
}
@lukeshumard
lukeshumard / helper.js
Created October 2, 2019 10:05
Getting @now/node helpers with tests
const micro = require('micro');
// taken directly from
// https://github.com/zeit/now-builders/blob/f67480a98ac461dc2fe6bb27e8a4ea86e9b6b60a/packages/now-node/src/helpers.ts#L47-L60
function queryParser({ url = '/' }) {
const { URL } = require('url');
// we provide a placeholder base url because we only want searchParams
const params = new URL(url, 'https://n').searchParams;
@ManasJayanth
ManasJayanth / canvas-immediate.js
Created April 19, 2017 05:50
Canvas Immediate mode rendering using React
import type { HostConfig, Reconciler } from 'react-fiber-types';
import type { ReactNodeList } from 'react-fiber-types/ReactTypes';
import DOMPropertyOperations from './DOMPropertyOperations';
import type {
Props,
Container,
Instance,
TextInstance,
OpaqueHandle,