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
createChainedFunction improvements #821
Conversation
return funcs | ||
.filter(f => f != null) | ||
.reduce((acc, f) => { | ||
if ({}.toString.call(f) !== '[object Function]') { |
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.
bit of a nitpick, I am a bit confused about the toString
call? what is it protecting against that typeof
doesn't catch? it seems very unlikely that anyone is using new Function
to create a callback. Only mentioning because it strikes me as harder to understand, and React itself doesn't make this check, so I am not sure there is any big need to support such an edge case.
LGTM |
072bf62
to
a97a29b
Compare
Since we're already pulling in |
Lodash is just a dev dependency right now. On Sat, Jun 13, 2015, 10:59 Jimmy Jia notifications@github.com wrote:
|
My bad - misread the dependency listing. I know |
Sounds reasonable to me! Looks like they are accounting for browser specific differences I haven't considered, even though there is a performance cost. |
I still think its a bunch of extra code that isn't needed, I don't know how often someone is going to be confusing a callback with a U8IntArray (looking through the code) in practice, lodash can accidentally bring a lot of code in even with the modular builds, if we aren't careful. In this instance its like 1 line vs 10 so it might not matter that much. |
ahh it looks like the default build in lodash 3 is the modern one, so it is probably trimmer than I thought |
The issue that got me was when I was looking through the lodash sort I say that they were accounting for:
I'm not a huge browser version specific person but it seems as though they will handle those quirks better than we can over time. |
I agree that it defiantely is better at cross compat then we probably are :) my thought was only that in this specific case the likelihood of any of those bugs biting us is very small, given that it is an undocumented util, that will almost always be fed functions pre validated by proptypes or class methods. I am probably being too nitpicky here tho, I get a get a bit weird about byte counts :P |
a97a29b
to
eb1e1c9
Compare
We can check how much code from Lodash gets pulled in, but my thought here is just to make it easier to tell what's going on. |
FWIW I don't think there should be much of a benefit to using |
in fact the main lodash package will dedupe better for users or if we use more than just this function, b/c the common code will all be the same. also the individual packages can create really long paths that us poor windows users can handle (though its mostly better in 3.0) |
This is turning out to be a larger discussion, I propose to take it out for now and open an issue targeted at discussing it. Thoughts? |
I propose to do as var isFunction = typeof property === 'function'; src/isomorphic/classic/class/ReactClass.js#L488 var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; src/shared/utils/getIteratorFn.js#L16 typeof typeDef[propName] === 'function' src/isomorphic/classic/class/ReactClass.js#L396 and so on many such in the |
That's a really good point. I see that PropTypes does the same thing. We probably don't need to handle edge cases that React itself doesn't care about. |
I'll toast to that! I'll update the PR. |
… if non-functions are provided.
eb1e1c9
to
c5855d2
Compare
Alright. As a person who has used I had no idea you guys had access to lodash at the time. PLEASE USE In fact, please use the following call to get your array of functions. Then use a reduce. |
@jtenner The discussion about adding lodash as a dependency is partly what tripped this up. Currently lodash is just a dev dependency as a convenience in testing and build/release scripts. There are pros a cons to adding it as a direct dependency which I'm fine with discussing, but it should happen in it's own issue and not detract from this PR. |
Hmm.. windowsCI gives a lot of eslint warnings: |
As for the code: LGTM
|
I've found the culprit. Creating the issue. |
Update: It is already addressed by jsx-eslint/eslint-plugin-react#110 |
Then I merge it. |
…improvements createChainedFunction improvements
By the way |
nice 😄 |
Changes
createChainedFunction
to chain many functions, and to throw if non-functions are provided.Reasons I'm proposing this to master and not
v0.24.0-rc
:@jtenner
this introduces that improved function type check you proposed on gitterThere is a test proving this wasn't necessary.@taion it's going to throw now when something other than a func is provided, as you proposed on gitter.