Skip to content

Instantly share code, notes, and snippets.

View meChrisReed's full-sized avatar

Chris Reed meChrisReed

View GitHub Profile
@meChrisReed
meChrisReed / recur.js
Last active June 16, 2017 19:08 — forked from CreaturePhil/recur.js
A Million Ways to Fold in JS Notes
// from http://forwardjs.com/university/a-million-ways-to-fold-in-js
'use strict'
const first = xs => xs[0]
const rest = xs => xs.slice(1)
const concat = (xs1, xs2) => [ ...xs1, ...xs2 ]
// recursion
const sum = xs => xs.length === 0 ?
// define action types... IDK why peeps do this
export const REPLACE_THINGS = "REPLACE_THINGS"
export const REMOVE_THING = "REMOVE_THING"
export const ADD_THING = "ADD_THING"
export const RESET_THINGS = "RESET_THINGS"
export const CLICKED_A_THING = "CLICKED_A_THING"
export const UI_THING_ON = "UI_THING_ON"
export const UI_THING_OFF = "UI_THING_OFF"
@meChrisReed
meChrisReed / CoolComponent.jsx
Created March 17, 2018 17:28
for a Medium article
// To connect to a component
const enhance = connect(["things", "things.reset"])
const CoolComponent = ({ things }) => (
<Fragment>
<button onClick={things.reset}> Reset </button>
{things.i.map(i => <span>{i}</span>)}
</Fragment>
)
enhance(CoolComponent)
@meChrisReed
meChrisReed / CoolComponent.jsx
Created March 18, 2018 11:38
redux normal; for an article
import { RESET_THINGS } from "./actions"
const enhance = connect(({ things }) => ({ things }), {
resetThings: things => ({
type: RESET_THINGS,
things
})
})
const CoolComponent = ({ things, resetThings }) => (
<Fragment>