-
Notifications
You must be signed in to change notification settings - Fork 27
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
props, derived, session for ampersand-collection #10
Comments
Not really, but you can easily do that on your own, here's the working PoC: |
Thanks! On Jul 23, 2014, at 11:08 AM, Kamil Ogórek notifications@github.com wrote:
|
this is almost exactly how we've solved this problem in the past, just remember to include add and remove events in your listenTo |
We've talked about supporting this. Then you'd be able to directly listen to change:length for example. That seems to be the most common use case, but it's be cool to support this out of the box. Trick is, with stuff like filtered sets is that it starts getting pretty inefficient as the collection size increases. You might look at ampersand-sub-collection too. It's meant for this type of use, but has less docs/tests. it's simply not as polished. |
going to close this for now, not sure we've got enough impetus to add this. |
Currently facing a problem where I have a simple collection and I want to show the amount of items in the collection in the template. I cannot use bindings {} because the collection cannot have properties. How would one solve this? |
I think it would be cool of a collection inherited from state. |
If there is not a simple solution for the collection/show length use case then I think something has to change. This could be limited to derived properties, but currently it seems you cannot have non-property dependencies for derived properties. |
One potential approach. initialize: function () {
this.on('add remove reset', function () {
this.trigger('change:length', this.length);
}, this);
} Then from a view, you could bind it like: bindings: {
'collection.length': {
selector: '.collection-length'
}
} |
Was wondering if there was a way to have properties (props, derived, session) for ampersand-collection. Would be particularly useful to have a derived properties that can return values based on the collection's array.
For example, say you have a collection called
products
filled withproduct
models. Eachproduct
model has aprice
property. It would be nice to define a derived property onproducts
that could map/reduce theproduct
prices into atotal
property. Thistotal
would trigger event listeners bound to it (as ampersand-state does with its properties).Is this possible?
The text was updated successfully, but these errors were encountered: