-
-
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 `serializ…
…ableStateInvariantMiddleware` take too long
- Loading branch information
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 you are passing very large objects into your state, you might to disable the middleware as it might cause too much of a slowdown in development mode. | ||
It is disabled in production builds, so you don't need to worry about that.`) | ||
} | ||
} | ||
} | ||
} |