Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Jason Gretz jagretz

🎯
Focusing
View GitHub Profile
@jagretz
jagretz / reduceReducers.js
Created Apr 18, 2018
Reduce multiple reducer functions passing state and action through each in sequence.
View reduceReducers.js
/**
* Supply multiple reducer functions, as arguments, and return a new reducer function that pipes the
* state and action through each reducer in sequence.
* @param {...functions} reducers like (arg1, arg2, ...), as a serires of arguments.
* @return {function} a new reducer function that pipes the state and action through each reducer in sequence.
* Each successive reducer will receive the updated returned by the previous reducer.
*/
export default function reduceReducers(...reducers) {
return (currentState = {}, action = {}) =>
reducers.reduce((updatedState, red) => red(updatedState, action), currentState);
@jagretz
jagretz / EventEmitter.js
Created May 28, 2018
Custom EventEmitter for created for the purpose of learning and teaching others.
View EventEmitter.js
// Example on codepen https://codepen.io/jagretz/pen/aGeMoJ
// If you would like a production version, use complete, tested, performant, and
// well-supported version https://github.com/facebook/emitter
/**
* Subscribe to and control when events are emitted to subscribers.
*/
class EventEmitter {
constructor() {
// k,v store of events to subscribers.
View createActionType.js
export const APP = "r3";
export const createActionType = app => duck => type => `${app}/${duck}/${type}`;
export const createDuckType = createActionType(APP);
/**
* Constructs a new action with a required type and optional additional action properties supplied as
* optional argument(s*); *see `...rest` param below.
*
@jagretz
jagretz / intersperse.js
Created Dec 25, 2018
Create and return a new array with the separator interposed between elements; intersperse :: a -> [a] -> [a]
View intersperse.js
/**
* Create and return a new array with the separator interposed between elements.
*
* intersperse :: a -> [a] -> [a]
*
* Providing the separator as the first argument allows this method to be easily
* curried and composed with other functions; follows the "data last" approach.
*
* @param {*} separator
* @param {*} array
@jagretz
jagretz / cloudSettings
Last active Sep 2, 2020
vsCode Settings Sync Gist
View cloudSettings
{"lastUpload":"2020-09-02T18:13:37.885Z","extensionVersion":"v3.4.3"}
@jagretz
jagretz / cloudSettings
Last active Sep 28, 2020
Minimize reducer boilerplate by utilizing a function that searches a dictionary of action types mapped to corresponding action creators
View cloudSettings
{"lastUpload":"2020-09-28T14:06:24.326Z","extensionVersion":"v3.4.3"}