Skip to content

Instantly share code, notes, and snippets.

@glortho
Created December 29, 2015 19:22
Show Gist options
  • Save glortho/63bcb26dd6c7ef5b2bbb to your computer and use it in GitHub Desktop.
Save glortho/63bcb26dd6c7ef5b2bbb to your computer and use it in GitHub Desktop.
Output useful debug info from Flux dispatch decorator
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