Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephan Meijer smeijer

View GitHub Profile
@smeijer
smeijer / post-install.js
Last active Nov 7, 2019
Post install script to make node_modules IE compatible again
View post-install.js
const fs = require('fs');
const getModules = projectDir =>
fs
.readdirSync(`${projectDir}/node_modules`)
.map(ns => {
if (ns[0] === '@') {
return fs
.readdirSync(`${projectDir}/node_modules/${ns}`)
.map(name => `${projectDir}/node_modules/${ns}/${name}/package.json`);
@smeijer
smeijer / transpile-3.js
Created Aug 2, 2019
medium-costs-of-optional-chaining-6
View transpile-3.js
var can = user && user.can || {};
var canEdit = can.edit;
var canDelete = can.delete;
// transpiles to:
"use strict";
var can = (user && user.can) || {};
var canEdit = can.edit;
var canDelete = can.delete;
@smeijer
smeijer / transpile-2.js
Created Aug 2, 2019
medium-costs-of-optional-chaining-5
View transpile-2.js
var can = user?.can || {};
var canEdit = can.edit;
var canDelete = can.delete;
// transpiles to:
"use strict";
var _user;
var can =
@smeijer
smeijer / transpile-1.js
Created Aug 2, 2019
medium-costs-of-optional-chaining-4
View transpile-1.js
var canEdit = user?.can?.edit;
var canDelete = user?.can?.delete;
// transpiles to:
"use strict";
var _user, _user$can, _user2, _user2$can;
var canEdit =
(_user = user) === null || _user === void 0
@smeijer
smeijer / commentButtons.jsx
Created Aug 2, 2019
medium-costs-of-optional-chaining-3
View commentButtons.jsx
function CommentButtons({ user }) {
const can = user ? user.can : {};
return (
<div>
<Button disabled={can.edit}>edit</Button>
<Button disabled={can.delete}>delete</Button>
<Button disabled={can.reply}>reply</Button>
</div>
)
@smeijer
smeijer / render-function.jsx
Last active Aug 2, 2019
medium-costs-of-optional-chaining-2
View render-function.jsx
function CommentButtons({ user }) {
return (
<div>
<Button disabled={user?.can?.edit}>edit</Button>
<Button disabled={user?.can?.delete}>delete</Button>
<Button disabled={user?.can?.reply}>reply</Button>
</div>
)
}
@smeijer
smeijer / component-did-update.js
Created Aug 2, 2019
medium-costs-of-optional-chaining-1
View component-did-update.js
componentDidUpdate(prevProps) {
if (
this.props.image?.type !== prevProps.image?.type ||
this.props.image?.orientation !== prevProps.image?.orientation
) {
// ...
}
}
View handleRequest
import bodyParser from 'body-parser';
import url from 'url';
const handleRequest = (method, path, cb) => {
WebApp.rawConnectHandlers.use(path, (req, res, next) => {
if (req.method !== method) {
next();
return;
}
@smeijer
smeijer / L.TopoJSON.js
Created Nov 17, 2017 — forked from brendanvinson/L.TopoJSON.js
TopoJSON Leaflet plugin
View L.TopoJSON.js
/*
First run npm install topojson --save and then link "node_modules/topojson/build/topojson.min.js"
above this snippet in your html.
Usage: http://leafletjs.com/reference.html#geojson
*/
L.TopoJSON = L.GeoJSON.extend({
addData: function (data) {
var geojson, key;
View ReactGallery.js
import React, { PropTypes } from 'react';
import Lightbox from 'react-images';
import styled from 'styled-components';
const Container = styled.div`
display: flex;
justify-content: flex-start;
flex-flow: row wrap;
width: ${p => p.width}px;
`;
You can’t perform that action at this time.