-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
display a warning if
immutableStateInvariantMiddleware
or `ser… (#427)
* display a warning if `immutableStateInvariantMiddleware` or `serializableStateInvariantMiddleware` take too long * Update src/utils.ts Co-authored-by: Mark Erikson <[email protected]>
- Loading branch information
1 parent
36b25fc
commit 5929c30
Showing
6 changed files
with
196 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export function getTimeMeasureUtils(maxDelay: number, fnName: string) { | ||
let elapsed = 0 | ||
return { | ||
measureTime<T>(fn: () => T): T { | ||
const started = Date.now() | ||
try { | ||
return fn() | ||
} finally { | ||
const finished = Date.now() | ||
elapsed += finished - started | ||
} | ||
}, | ||
warnIfExceeded() { | ||
if (elapsed > maxDelay) { | ||
console.warn(`${fnName} took ${elapsed}ms, which is more than the warning threshold of ${maxDelay}ms. | ||
If your state or actions are very large, you may want to disable the middleware as it might cause too much of a slowdown in development mode. See https://redux-toolkit.js.org/api/getDefaultMiddleware for instructions. | ||
It is disabled in production builds, so you don't need to worry about that.`) | ||
} | ||
} | ||
} | ||
} |