-
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
Tracking collection state. #48
Comments
One other option would be a mixin, however it would require the end-user to initialize the mixin code as part of the collection's setup. |
I like the sound of a state object on the collection. I think this could be really useful. 👍 |
dont |
@cdaringe reset changes length too |
on new idea. perhaps we pass more than just the model to event handler--pass a |
@wraithgar Before diving in, I'm guessing there's some history and discussion of why |
I've discussed this a bunch with @HenrikJoreteg and others in the past, and even got as far as getting something working in a branch: https://github.com/AmpersandJS/ampersand-collection/compare/based-on-state The last time I thought about this where I think got to was:
The outstanding questions were:
|
I'm trying to wrap my head around this whole situation and it seems to me that extending from state adds a lot of extra stuff to collection that we don't really need, also it seems like having a state object ask whether it has actually become a collection is a bad programming practice (I can't explain why, and I could very well be wrong!). What about if we had another dataType in state which was 'collection' instead of having collections as its own separate thing. That way you could have deps refer to a property of type 'collection' to know when to recalculate and cache the derived property? Could it work like an array? It just bubbles up a change when something in the collection changes? |
@latentflip thanks! Still chewing on this a bit. Here's an example (using a gnarly "what if there was an internal _state that proxied?" method) which is what first got me into this topic. |
@latentflip the direction your branch is heading seems promising. in my use-case, a collection has to have information about pagination, sorting and verbose filtering of items - so extending from At the moment, i'm simply adding additional Models as properties of the collection. |
+1 on extending &-state. |
+1 on adding properties to collection. A lot of boilerplate is generated without it. However, I also agree with @erd0s, seems like by extending from state we'd be inviting a whole lot of weirdness. Collections could then have Perhaps we would want to lift only certain parts out of state, @latentflip, I noticed that in your branch you have a Would 99% of desire-ments for this be solved with an evented property for My two cents... |
I just realized I could be wrong about my comment about the code not responding to change of model |
A collection emits events that are bubbled up from the models it contains. This is the current behavior and expectation from even pre-ampersand (i.e. backbone).
It would be nice if there were a way to event on collection state events, specifically the length. Unfortunately you can't just start emitting change:length events because everything listening to events coming out of the collection would have to start paying attention to the type of object emitting the change event, because it could now either be the collection itself or a model it contains.
There are two ways to potentially solve this.
change
collectionChange
collection.state
The latter feels more properly separated but this is something a lot of people have asked for (i.e. being able to derive an empty attribute) and I don't see any discussion happening lately so I'd like to get this out there.
The text was updated successfully, but these errors were encountered: