-
Notifications
You must be signed in to change notification settings - Fork 80
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
Improved flow type #12
Conversation
Codecov Report
@@ Coverage Diff @@
## master #12 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 1 1
Lines 15 16 +1
=====================================
+ Hits 15 16 +1
Continue to review full report at Codecov.
|
src/index.js
Outdated
let lastThis: any; | ||
let lastArgs: Array<any> = []; | ||
let lastResult: any; | ||
export default function <ResultFn: Function>(resultFn: ResultFn, isEqual?: EqualityFn = simpleIsEqual): ResultFn { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thejameskyle I was unable to get a better check than:
<ResultFn: Function>
I tried to use this:
<ResultFn: () => mixed>
but flow complained when I tried to memoize functions that had arguments. I also tried this with no success.
<ResultFn: (...args: Array<mixed>)>
ResultFn: (...args: Array<mixed>) => mixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, weird... that used to work. Maybe recent changes to arity have changed that.
You could make it a little bit stronger by using:
(...Array<any>) => mixed
9a3a2ca
to
746309b
Compare
… type as the function passed in
746309b
to
d219433
Compare
.flowconfig
Outdated
@@ -6,6 +6,8 @@ | |||
|
|||
[options] | |||
|
|||
experimental.strict_call_arity=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had added this also to ensure that memoizeOne will work with the upcoming flow version
src/index.js
Outdated
let lastThis: any; | ||
let lastArgs: Array<any> = []; | ||
let lastResult: any; | ||
export default function <ResultFn: (...Array<any>) => mixed>(resultFn: ResultFn, isEqual?: EqualityFn = simpleIsEqual): ResultFn { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thejameskyle <ResultFn: (...Array<any>) => mixed>
seemed to work fine. I am still a little confused as to what this is communicating. Here is my current understanding:
ResultFn
is a type of function (as communicated by the syntax() => {}
) that can accept any length of arguments ((...Array<any>)
) and returns a mixed
(which means that you must check the result type before you can do type specific operations on it).
Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that's right. While you're not enforcing inputs, you can at least be sure that you aren't handling the output incorrectly.
This PR brings the flow coverage up from 64% to 90.6% |
hardening up the flow types so that the memoized function is the same type as the function passed in