Skip to content

Instantly share code, notes, and snippets.

View jagretz's full-sized avatar
🎯
Focusing

Jason Gretz jagretz

🎯
Focusing
View GitHub Profile
@jagretz
jagretz / intersperse.js
Created December 25, 2018 14:48
Create and return a new array with the separator interposed between elements; intersperse :: a -> [a] -> [a]
/**
* 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
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 / cloudSettings
Last active September 28, 2020 14:06
Minimize reducer boilerplate by utilizing a function that searches a dictionary of action types mapped to corresponding action creators
{"lastUpload":"2020-09-28T14:06:24.326Z","extensionVersion":"v3.4.3"}
@jagretz
jagretz / EventEmitter.js
Created May 28, 2018 15:11
Custom EventEmitter for created for the purpose of learning and teaching others.
// 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.
@jagretz
jagretz / reduceReducers.js
Created April 18, 2018 00:43
Reduce multiple reducer functions passing state and action through each in sequence.
/**
* 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);