This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import EventEmitter from "events"; | |
import { useCallback, useEffect, useRef } from "react"; | |
export default function useListener(listener = () => {}) { | |
const emitter = useRef(new EventEmitter()); | |
useEffect(() => { | |
const currentEmitter = emitter.current; | |
currentEmitter.on("event", listener); | |
return () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const passBy = by => pass => { | |
by(pass) | |
return pass | |
} | |
/* | |
Example: | |
/////////////////// | |
const log = console.log | |
const get = (attribute, target) => target[attribute] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
curryN, | |
update, | |
nth | |
} from 'ramda' | |
// Getting an array, modify just one its elements allowing different pipes in a data structure | |
// Number -> Function -> Array -> Array | |
const path = curryN( | |
3, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createReducer = (initialState, actionMap) => (state = initialState, action) => { | |
const {signals} = action | |
if (signals) { | |
const signal = signals.find( | |
(stepAction) => actionMap[stepAction.type] | |
) | |
if (signal) { | |
const reducer = actionMap[signal.type] | |
return reducer(state, signal) | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Returns a valuable function: | |
x = add(2)(4) // x === 6 | |
y = x(1)(2) // x === 6 && y === 9 | |
z = y(10) // z === 19 | |
*/ | |
function add (n) { | |
var fn = function (m) { | |
return add(n+m); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import expect from 'expect' // using expect by @mjackson | |
export default (state) => { | |
const spy = expect.createSpy() | |
const getState = () => state | |
const dispatch = (action) => typeof action === 'function' | |
? action(dispatch, getState) | |
: spy(action) | |
return {spy, getState, dispatch} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Block | |
-- | |
Propagate any prop to the children but allowing className extension | |
Needs `babel-plugin-transform-object-rest-spread` | |
*/ | |
const Block = ({classes, className, ...rest}) => | |
<div {...rest} className={`${[classes, className].join(' ')}`} /> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const compose = (...fns) => (...args) => fns.reverse().reduce((acc, fn, index) => { | |
if (index) return fn(acc) | |
else return fn.apply(this, acc) | |
}, args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ImmutableArray (arr) { | |
arr.forEach((key, index) => { | |
Object.defineProperty(this, index, { | |
enumberable: true, | |
get: () => key, | |
set: () => { | |
throw new Error('cannot be mutated') | |
} | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
<div class="o-beside**"> | |
<div class="o-beside__wrapper"> | |
<div>content</div> | |
</div> | |
</div> | |
*/ | |
.o-beside | |
position: absolute | |
height: 0 |
NewerOlder