Skip to content

Instantly share code, notes, and snippets.

@artalar
Created March 12, 2019 16:49
Show Gist options
  • Select an option

  • Save artalar/b21f13aa784e1bcd287249ccd6083d92 to your computer and use it in GitHub Desktop.

Select an option

Save artalar/b21f13aa784e1bcd287249ccd6083d92 to your computer and use it in GitHub Desktop.
Debug where action was called for redux-act
function getStack() {
// Save original Error.prepareStackTrace
const origPrepareStackTrace = Error.prepareStackTrace;
// Override with function that just returns `stack`
Error.prepareStackTrace = (_, stack) => stack;
// Create a new `Error`, which automatically gets `stack`
// Evaluate `err.stack`, which calls our new `Error.prepareStackTrace`
const { stack } = new Error();
// Restore original `Error.prepareStackTrace`
Error.prepareStackTrace = origPrepareStackTrace;
// Remove superfluous function call on stack
stack.shift(); // getStack --> Error
return stack;
}
export function getCallers() {
const stack = getStack();
stack.shift(); // getStack
stack.shift(); // getCaller
// Return caller's caller
return Array.prototype.map.call(stack, v => v.toString());
}
import { createAction } from 'redux-act';
export const action = createAction(
'description',
null, // payload mapper
getCallers, // meta mapper
);
@artalar

artalar commented Mar 12, 2019

Copy link
Copy Markdown
Author

Example

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment