Skip to content

Instantly share code, notes, and snippets.

View TheBox193's full-sized avatar
:shipit:
Shipping code.

Sir.Nathan (Jonathan Stassen) TheBox193

:shipit:
Shipping code.
View GitHub Profile
@TheBox193
TheBox193 / redux-error-log-middleware.js
Created May 17, 2017 17:41
Redux Middleware that tracks a history of dispatched actions for debugging.
const redux_log = [];
const errorLogMiddleware = (store) => (next) => (action) => {
const type = (action && action.type) || 'unknown action';
if ( type === 'LOG_ERROR' ) {
const log_str = redux_log.join(' -> ');
const error_str = (action && action.payload && action.payload.error) || 'Redux Error';
console.error(error_str + ': ' + log_str);
} else {
@TheBox193
TheBox193 / get-and-getIn.js
Last active October 10, 2017 13:32
Immutable get helper
const get = function(state, arrayPath, defaultValue) {
if (arrayPath.length === 1) {
return state.get(arrayPath[0], defaultValue);
} else {
return state.getIn(arrayPath, defaultValue);
}
}