-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cancel args memorization if func throws exception #144
Conversation
The issue is when func throws exception the last args already saved and next calling of memoized func will return null instead of recalculating func again. If we save args after calling of func we save args only for "good" result and don't for exceptions.
Current coverage is 100%@@ master #144 diff @@
====================================
Files 1 1
Lines 13 13
Methods 0 0
Messages 0 0
Branches 0 0
====================================
Hits 13 13
Misses 0 0
Partials 0 0
|
Hey @zandroid, would it be possible to add a test case that fails on the current version and passes with your fix please? |
@ellbee, sure, have added two tests. |
Thanks @zandroid. I've checked the test out, but I'm not sure I fully understand the problem this is trying to fix. Is it that it doesn't throw an exception the second time it receives the same set of arguments consecutively? What problem does that cause you? You mention above the return value being |
It's exactly the issue that I have in my code. But anyway I think selector should not memoize (default or previous) result for current args when There may be other issue, not for default const selector = createSelector(state => state.a, (a) {
if (a > 1) throw new Error()
return a;
})
selector({ a: 1 }) // => 1 - OK
try {
selector({ a: 2 }) // => throw error - As expected
} catch (e) {}
selector({ a: 2 }) // => 1 - What?! |
Ok, thanks! So the problem is that it doesn't throw the second time—the return value being |
@zandroid Released in v2.5.2. Thanks for the PR! |
A lot of thanks. I agree that throwing exceptions from selector is not usual case, but we use it in our selectors to detect incorrect id of requested entity and show 404, 403 or 401 pages. |
The issue is when
func
throws exception the lastargs
already saved and next calling of memoized func will returnnull
instead of recalculatingfunc
again. If we saveargs
after calling offunc
we saveargs
only for "good" result and don't for exceptions.