Created
March 12, 2019 16:49
-
-
Save artalar/b21f13aa784e1bcd287249ccd6083d92 to your computer and use it in GitHub Desktop.
Debug where action was called for redux-act
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
| 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 | |
| ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example