sukima / ember-cli-select-picker

An enhanced Boostrap styled select component addon for Ember CLI
https://sukima.github.io/ember-cli-select-picker
MIT License
23 stars 15 forks source link

handling of 'selection' does not work with promises #29

Closed Awem closed 8 years ago

Awem commented 9 years ago

select-picker seems to handle the selection attribute differently then view 'select' regarding promises. Reproducable with the following template:

{{select-picker content=items selection=selectedItem optionValuePath='content.id' optionLabelPath='content.name'}}
{{view 'select' content=items selection=selectedItem optionValuePath='content.id' optionLabelPath='content.name'}}

In my controller I set selectedItem to model.item. In my model, item is defined like this:

item: DS.belongsTo('item', {async: true}),

On first render, selectedItem is a DS.PromiseObject. Once that promise is resolved, only the {{view 'select'}} is updated, but {{select-picker}} remains on Nothing Selected. If I then choose an item on one of the select fields, the chosen item is directly loaded. Thus, it is a model:item and {{select-picker}} gets updated. IMHO, select-picker should handle promises correctly.

sukima commented 9 years ago

Hmm. Interesting edge case. I'll have to look into the view select source to see how they manage it. Funny, you'd think Ember.Objects would handle promises intrinsically.

fizz commented 9 years ago

The way ManyArray works has changed in Ember Data.

For example, {{select-picker content=model.items.content ...}} used to work, but now you have to invoke .toArray() on model.items. I just made a computed property in my component that returns model.items.toArray(), so I can just do {{select-picker content=items ...}}

See also https://github.com/emberjs/data/issues/3604#issuecomment-125782623

sukima commented 9 years ago

I ran into a gotcha with PromiseProxyMixin. If you pass the component as the value another promise resolves to the RSVP lib will resolve to the content of the component not the component itself. PromiseProxyMixin can be quite magical this way.

There be dragons here. :dragon:

sukima commented 8 years ago

Closing due to atrophy. Reopen if needed.

I think that resolving a promise should not be this addon's responsibility. The contract is that whatever is bound to content should be an array of select-picker objects. I recommend using a computed property that is dependent on the promise resolution.