Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
https://leanpub.com/composingsoftware

Eric Elliott ericelliott

💭
https://leanpub.com/composingsoftware
View GitHub Profile
View pyramid-of-doom.jsx
import FeatureProvider from '../providers/feature-provider';
import EnvProvider from '../providers/env-provider';
import LoaderProvider from '../providers/loader-provider';
import CouponProvider from '../providers/coupon-provider';
import LayoutProvider from '../providers/layout-provider';
import AuthProvider from '../providers/auth-provider';
import RouterProvider from '../providers/RouterProvider';
import MagicLinkProvider from '../providers/magic-link-provider';
import PageComponent from './page-container';
@ericelliott
ericelliott / page-hoc.js
Created Aug 30, 2020
pageHOC for EricElliottJS.com
View page-hoc.js
import { compose } from 'lodash/fp';
import withFeatures from './with-features';
import withEnv from './with-env';
import withLoader from './with-loader';
import withCoupon from './with-coupon';
import withLayout from './with-layout';
import withAuth from './with-auth';
import { withRouter } from 'next/router';
import withMagicLink from '../features/ethereum-authentication/with-magic-link';
View jsx-example.jsx
const ItemList = ({ items }) => (
<ul>
{items.map((item) => (
<li key={item.id}>
<div>{item.name}</div>
</li>
))}
</ul>
);
View double-list-declarative.js
const doubleList = list => list.map(x => x * 2);
View double-list-imperative.js
const doubleList = list => {
const newList = [];
for (var i = 0; i < list.length; i++) {
newList[i] = list[i] * 2;
}
return newList;
};
View after-immer.js
import produce from 'immer';
const like = item => ({
type: like.type,
payload: item
});
like.type = 'user/like';
const initialState = {
name: 'Anonymous',
View before-immer.js
const like = item => ({
type: like.type,
payload: item
});
like.type = 'user/like';
const initialState = {
name: 'Anonymous',
avatar: 'Anonymous',
email: '',
View for-await-of-transducers.js
const compose = (...fns) => x => fns.reduceRight((y, f) => f(y), x);
function map(f) {
return async function*(values) {
for await (const x of values) {
yield f(x);
}
};
}
@ericelliott
ericelliott / parallel-fetch.js
Created Apr 13, 2020
Parallel requests example
View parallel-fetch.js
// setup
const wait = value => new Promise(resolve => {
setTimeout(() => resolve(value), 3000);
});
const fetchFoo = () => wait('foo');
const fetchBar = () => wait('bar');
const fetchBaz = () => wait('baz');
const fetchDataSlowly = async time => {
View page-hoc.js
import { compose } from 'lodash/fp';
import withFeatures from './with-features';
import withEnv from './with-env';
import withLoader from './with-loader';
import withCoupon from './with-coupon';
import withLayout from './with-layout';
import withAuth from './with-auth';
import { withRouter } from 'next/router';
import withMagicLink from '../features/ethereum-authentication/with-magic-link';
You can’t perform that action at this time.