Skip to content

Instantly share code, notes, and snippets.

@mmazzarolo
Created April 18, 2016 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmazzarolo/b26dd45e6fe16fa1f2c1e814a1221301 to your computer and use it in GitHub Desktop.
Save mmazzarolo/b26dd45e6fe16fa1f2c1e814a1221301 to your computer and use it in GitHub Desktop.
Cleaning up the messy seamless-immutable functions in redux-logger
import createLogger from 'redux-logger'
// Seamless-Immutable logger cleanup
const stateTransformer = (state) => {
if (typeof state === 'object' && state !== null && Object.keys(state).length) {
let newState = {}
for (var i of Object.keys(state)) {
if (state[i].asMutable) newState[i] = state[i].asMutable({ deep: true })
else newState[i] = state[i]
}
return newState
} else {
return state
}
}
// Create the logger
const loggerMiddleware = createLogger({
collapsed: true,
stateTransformer
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment