-
Notifications
You must be signed in to change notification settings - Fork 104
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
Select helper fixes #148
Select helper fixes #148
Conversation
427d0f4
to
80b0eb3
Compare
@@ -217,19 +217,17 @@ export default class Select extends Component { | |||
let focusedOptionValue; | |||
|
|||
if (has(properties, 'valueLink')) { | |||
selectedValue = properties.valueLink.value; | |||
focusedOptionValue = selectedValue; | |||
focusedOptionValue = selectedValue = properties.valueLink.value; |
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.
Multiple left-hand assignments have the strange side-effect in JS that they are then in the global scope. From what I learned it's best to avoid them at all. see http://stackoverflow.com/a/1758912/837709
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.
Agreed, I was not sure of this change. Just got motivated from underscore's code, They used it so much. Let me revert this :)
@jpuri I'm bit worried about updating all the helpers. There are a lot of things that can go wrong in various browsers and underscore is heavily used & tested. Also the further we move away from underscore the harder it will be to apply bug-fixes they do. Would it have been possible to just fix the whole issue by doing this?
If we then always use this.sanitizedChildren we should be pretty much save? |
Hey Nik, My implementation of helpers is not underscore, underscore takes care of a hell lot of edge cases and ECMA versions. I want to keep implementation minimal and tailored specifically to our need. It definitely can be handled the way you are mentioning. But if we change helpers it will be change in one centralized place (it will not be ideal to need to do this for all props of type array :( ). I want to have clear expectation set from helper methods and all helper methods should behave in that way. By moving away from underscore we definitely are losing advantage of battle tested code. But reverse engineering a helpers for us from underscore is crazy plus we might still be left with unexpected behaviors and doing some of the handling in components code itself. |
My brain is kind of loaded with thoughts about what would be the best way out for this. I do not want to have some black box code in my app which I just trust. The reason So there are trade-offs, loosing the advantage of some battle tested code (which is no small in itself) vs loosing the advantage of having a helper perfectly suited to what I need (this will need that we have exact knowledge of underscore method when we use it and we tailor our input to the expectations of the method). Lets discuss this and the other PR more in call today. |
32a43bc
to
cf1d7bf
Compare
Hey Nik, I have updated the PR, but still there is one issue - if there is no placeholder(which is not highly probable) and no option then select gets broken on the page as |
cf1d7bf
to
79f7965
Compare
Hey@jpuri - I finally found some time to review and work on this PR in detail. I looked at it not only from the perspective of providing one single option, but also combining a single placeholder with an array of options (see #161). Rather than cover all possible edge cases in the helpers I propose we move towards sanitising the props.children before using them. Let me know what you think. |
Hey @nikgraf , Changes in select look great 👍 (I will spend some time testing those today). I agree with you about helpers we should use more of native methods. There are many in ES5 which can greatly help us (I will create a issue for this). I still want to keep mapObject method because otherwise map method handling both array and object becomes inconsistent from what other methods do. Let me add a commit for that. |
…f cases when user passes < 2 options
@jpuri sounds good 👍 on mapObject |
56dfeb4
to
b4c8c5e
Compare
…heck is props are not null
Hey Nik, In case select has no children. its hight become 0. Which looks bad, this can be fixed by giving a min-height. I am yet to do that mapObject changes - planning to do it tomorrow. |
@jpuri no children also bugged me when working on this. I figured a Select without Options or a Placeholder doesn't make sense to me and it should be mandatory. Thoughts? |
Yes, its very unlikely to have such scenario (I think of scenario where options are dynamically and there is no option in some scenario). Lets leave it as is :) |
Hey @nikgraf ,
This PR has changes in helper methods. If I pass a non-iterable object to any helper method expecting an array, it should treat it like array of single object. Its different from underscore which typically in such cases iterate over each field of object.
The reason for doing this change is select's typical case:
When select has single option react does not makes and array but single object which was breaking when we passed it to helper.filter. I did change in all methods as I wanted behavior to be consistent.
Changes look good now, can be merged.