-
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
One way binding #53
Comments
Either, really just want the select box to update if the value passed into it updates, but when user changes select box, just want it to send out an action (and not update either value or selection) |
That sounds exactly like the definition of "data down, actions up". We may need to do some slight changes to make this conform this paradigm. |
right. Maybe an opt-in to disable the two-way binding so it's backwards compatible. |
I'd say that, in the |
yah, again you can leave both on by default if you dont want to break bwds compatibility, but if |
it's going to be a bit more than that line. I commented it out locally, but there's still some wackiness going on |
Is your select multiple or single? |
single. I think it has to do with |
There are a couple of |
right. So it looks like I actually got what I want with this: // components/ember-selectize.js
import Component from 'ember-cli-selectize/components/ember-selectize';
Component.reopen({
_updateSelection: function(selection) {
// allow the observers and computed properties to run first
Ember.run.schedule('actions', this, function() {
var value = this.get('value');
this.sendAction('select-item', selection, value);
});
},
_valueDidChange: Ember.observer('value', function() {
}),
});
export default Component; This lets me pass in This didn't work when I just passed in |
Glad you made it work for now. I'll restructure the code a bit better so that we have a single point of updates. Meanwhile, let's keep this open. |
Would love a |
I would prefer to infer that by checking if actions are bound or not. This would of course break if people are using both actions and two-way bindings. But I kind of think of that as an anti-pattern. Thoughts? |
Agreed. I'm assuming this would work for |
From all the actions, maybe only if any of
|
@knownasilya I've also started wrapping selectize (and other libs) in my own component code and using variables local to that wrapper for the two-way binding, but only sending actions out. This is a short-term way to enforce one-way binding in your app. (Also, I think wrapping 3rd-party components in your application is generally a good pattern). |
@samselikoff feel like sharing your wrapper? I always get bit by when the final value needs to be an array of keys, but the input is an array of objects. Getting the saved items to show up by default is a big pain. |
@miguelcobain were you able to make those changes for the actions? |
I'm not sure what you mean by final value. I usually just have something like export default Ember.Component.extend({
_selection: Ember.computed.oneWay('selection');
emitActions: Ember.observer('_selection', function() {
if (this.get('_selection') !== this.get('selection') {
this.sendAction('on-select', this.get('_selection');
}
}
}); and then the component's template would be something like {{view 'select' content=content selection=_selection ...}} so then you can {{ted-select content=content
selection=selection
on-select='handleSelect'}} |
So input is |
output meaning, the parameter of the |
See https://gist.github.com/knownasilya/f200d462e6c3443f41ac, trying to get the selection to turn into and object, but having a hard time. It works on initial load if selection is an array of ids (internally it's replaced with object versions), but on-select it reverts back to the id version. I've tried a few things but keep running into stack overflows.. I can't wait for immutable by default. |
did you try |
Is there a way to do |
I dont think so, can't you just make sure your CP is only composed of other readonly properties? |
@miguelcobain is it true in the current version? |
Most people are using ember-power-select now a days. |
@knownasilya thanks for the tip |
We're having some trouble when binding value to a query param, with null/undefined. Is there any way to disable two-way binding? Ideally the change would only send out an action, rather than updating the
value
that was passed in.The text was updated successfully, but these errors were encountered: