-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Add multiple selection feature #7
Conversation
This replaces the array every time a change happens. We could use something like setObjects. AFAIK there isn't any way to know which option was selected/deselected in a change event, right? |
I don't believe there is, although it might be worth investigating if there is Since the philosophy of this component is to hue as closely to "what would html do", I think that the answer is to completely replace the array, and raise the action with the new array as its argument. This is how multiselect works on native selects and file inputs, so it should be the default. That said, there are going to be people who want to bind their ember-data relationships directly to an In any case, it looks like the native The action then, would always pass the https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement |
This is obviously your call, but I'll leave here my point of view on this. I think that, more importantly than what HTML does, is what Ember does. That being said:
I think of this addon as the way to use native selects in Ember. Maybe we could even have this to replace the current Ember.Select or inspire someone who does its refactor. I also think that we should have both a block and blockless version. The blockless version would provide an API similar to Ember.Select and ember-cli-selectize: {{x-select content=items
value=model.item
optionLabelPath="content.name" }} This way I think we would cover all the use cases a user might want for a native select. {{#x-select value=bob action="selectPerson"}}
{{#x-option value=fred}}Fred Flintstone{{/x-option}}
{{#x-option value=bob}}Bob Newhart{{/x-option}}
{{/x-select}} To a full blown multiple select with actions {{x-select content=items
value=model.item
optionLabelPath="content.name"
multiple=true
disabled=isDisabled
... }} If our POVs are in sync, I can work on making this PR reflect what I said here. |
You make a convincing case. I think we can agree on the principle that we want to do what surprises the developer least. In my case, I have always found the ember select view interface confusing and brittle, and so we wrote this component because it aligns very cleanly with the resulting HTML... what you see is what you get. None of the things you propose conflict with that in principle, I just want to make sure that we don't lose sight of that happy path with any addittions to the feature set.
I am ok with overloading the
What I meant to say was that the array that is passed in be treated as immutable and left untouched by default. Then, a new array, containing a snapshot of the fully realized changes is passed every time in the action. To me, this seems the most compatible with "data down, actions up". The in-place option would permit the component to mutate the array... basically equivalent to Mutating the array in place also gives me pause from a practical standpoint. I don't think I've ever not regretted editing an ember-data I'm going to inquire further about what immutability by default actually means in 2.0 means w.r.t. arrays. Thoughts?
I agree whole-heartedly, just think it might make sense to put it in as a separate PR.
I was initially opposed to this for the reasons I stated above. However, we recently converted a project over from using |
Regarding mutability of the Also, "data down, actions up" is not something "written in stone". Please see my comment here miguelcobain/ember-cli-selectize#34 (comment) So, what's missing in this PR? Actions? |
There are, I think, good arguments for why you would not want that by default, and it basically follows the same logic as those put forth in the 2.0 RFC. It boils down to the fact that if you are changing the state of your routes's models outside the routes themselves, you run a far greater risk of introducing non-determinism into your application. That's why mutability is becoming a simple, yet explicit opt-in. Something I'd forgotten though: 2.0 is not here yet, and as you point out, it is not set in stone, and is subject to change. The current expectation under 1.x rules is that all bindings are both ways by default. This component in it's 1.x incarnation should abide by 1.x rules, which are well-known. We can cross the 2.0 bridge when we come to it. As an aside: When handling form input, we've found that the best way to maintain sanity is to make a copy of our model into memory as a simple
|
Notice that if the user never writes
I think this PR included that other PR. I started from that point. Is that enough?
I also think that is the most appropriate. We could wrap the value in an array, and then when a selection changes we would need to set an array. But that could lead to silent bugs for us overwriting data this way.
Not really sure how to tackle the add/remove actions here... |
Honestly, the more I think about it, the less I think I know what "one-way" means in ember 2.0, and I think any speculation is not helping us move forward. I have a sneaking suspicion that the answer to my question is that
That's odd. Those changes shouldn't then be showing in the diff, maybe it won't be a problem. Let's go ahead and add the exception, and I'll add the tests for it as well as the multi-select
On |
I've updated the tests, added a section to the readme, and release |
Great! ⛵ In the example there's an error on the closing Regarding your "heads up" in the readme, I remind you that we no longer change the array, we use setObjects: https://github.com/thefrontside/emberx-select/blob/master/addon%2Fcomponents%2Fx-select.js#L120 I'm not having any trouble with ember-data's relationships here. :) Also
Perhaps there's a duplicade "using" there. :) |
Thanks for catching those typos. We use The reason I still included the warning is this: The biggest problem with using ED |
Alright. 👍 |
I think I nailed it! Example in the dummy app.
I'm not very familiar with mocha. Maybe you could write the needed tests.
Otherwise I can certainly look into it later.
This PR includes #6.