Add separate options for memoize and argMemoize, and merge together #608
+147
−22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR:
createSelectorCreator
to accept either the existing signature of(memoizeFunction, ...memoizeOptions)
, or the new signature of(options: CreateSelectorOptions)
(which includes{memoize, memoizeOptions, argMemoize, argMemoizeOptions}
)createSelector
to merge together the options provided tocreateSelectorCreator
, with whatever options were passed in directly as an argumentThe initial logic appears to work okay at the JS level, as the tests pass. But, the types aren't right. As soon as I do this:
a
andb
lose their types and it yells at me.Details
I strongly suspect that what I want to do runtime-wise is just too dynamic to express in TS very well.
The general idea is:
memoize
function given tocreateSelectorCreator
. This accepts some kind ofmemoizeOptions
(like an equality function), so allow passing in{memoize, memoizeOptions}
createSelector
would later allow overriding those on a per-call basis, like:createSelector(in1, in2, output, {memoize: lodashMemoize, memoizeOptions: lodashMemoizeOptionsHere})
.where it gets even screwer is that maybe you'd pass in
memoizeOptions
by itself and have that apply to the existing memoize function, or pass in both{memoize, memoizeOptions}
and have it apply to the new memoize functionRuntime-wise, this is basically just an
{...createSelectorCreatorOptions, ...createSelectorDirectOptions}
.And then to make it even more complicated, I want to allow doing the same thing for argMemoize and argMemoizeOptions. (although I imagine if I could get the types right for one function I can get it right for both)
I have a vague feeling that I somehow need to allow for passing multiple generics for, say,
MemoizeFunction1
andMemoizeFunction2
and doing something liketype FinalMemoizeFunction = MemoizeFunction2 extends unknown ? MemoizeFunction2 : MemoizeFunction1
. But there's enough complexity here my brain is shutting down trying to think about it.