Created
December 29, 2015 19:22
-
-
Save glortho/63bcb26dd6c7ef5b2bbb to your computer and use it in GitHub Desktop.
Output useful debug info from Flux dispatch decorator
This file contains hidden or 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 groupStyle = 'font-weight: normal; color: gray'; | |
const stackStyle = 'color: gray'; | |
function dispatchDecoratorFactory( ACTION ) { | |
return function dispatchDecorator( target, key, descriptor ) { | |
const fn = descriptor.value; | |
descriptor.value = function decoratedMethod( ...args ) { | |
if ( myModeFlag === 'debug' ) { | |
console.groupCollapsed( `%c${target.constructor.name}.${key}(%O) -> ${ACTION}`, groupStyle, args ); | |
console.debug( `%c${( new Error() ).stack}`, stackStyle ); | |
console.groupEnd(); | |
} | |
// ...do the rest of your dispatch logic | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment