ember-power-select icon indicating copy to clipboard operation
ember-power-select copied to clipboard

Add identification for the trigger display yield

Open monovertex opened this issue 9 years ago • 2 comments

This PR adds information in the yielded block whether the block is rendered in the trigger or in the dropdown, to allow for different logic in those places.

My use case: I implemented a lazy rendering component and I want to wrap the dropdown options in it, but I don't want the trigger block to have the lazy loading behavior as well. I feel like this could be used in many other situations.

monovertex avatar Feb 03 '17 09:02 monovertex

The say I prefer people to make the trigger and the options diverge is by using the selectedItemComponent (see http://www.ember-power-select.com/docs/the-trigger)

While slightly more inconvenient (you have to create a template-only component) it is more powerful and generally faster, because adding and if/else in the block forces you to evaluate that if else N number of times, one per each item of the collection. With 10 items doens't matter, with 150 it does.

cibernox avatar Feb 03 '17 10:02 cibernox

The problem with this approach is that it requires multiple selectedItemComponents if different EPS instances have different displays. This overhead becomes even bigger if your trigger display and option display are really similar, because then you probably need a new component to use in both the selectedItemComponent and the yielded block of the EPS, to avoid duplicate code.

Performance is, however, more important I think. I'll think about it, maybe we can find a better way. I feel like the scenario described by me earlier can become pretty performance-intensive as well, because component instantiation is also expensive, same as evaluating if/else constructs.

monovertex avatar Feb 03 '17 10:02 monovertex