Skip to content
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

decision whether return collection or internal array of model should be a confiugration option #22

Open
stalniy opened this issue Feb 13, 2016 · 3 comments

Comments

@stalniy
Copy link

stalniy commented Feb 13, 2016

I know in order to iterate over backbone collection adapter returns internal array instead of collection. That really annoying for cases when you need collection, for example when you pass it as parameter to component (as attribute)

So, I suggest to move such decision to configuration option:

rivets.adapters[':'].returnCollection = true;

// and inside rivets-backbone.js
if (!rivets.adapters[':'].returnCollection && value instanceof Collection) {
  return value.models;
}

cc: @azproduction @der-On @generalov @StephanHoyer @Jmeyering @jeron-diovis

@stalniy
Copy link
Author

stalniy commented Feb 13, 2016

Also I created an issue in rivets repository. Fix of that will allow to iterate over backbone collections (and not only) mikeric/rivets#583

@stalniy
Copy link
Author

stalniy commented Feb 16, 2016

Or you could add something like this:

let eachBinderRoutine = rivets.binders['each-*'].routine;
rivets.binders['each-*'].routine = function(el, collection) {
    if (collection.models) {
        collection = collection.models;
    }

    return eachBinderRoutine.call(this, el, collection);
};

@sarim
Copy link

sarim commented Sep 7, 2016

The linked issue (mikeric/rivets#583) and linked issue there proposes some alternative ways to solve this problem. Still i don't really like those solutions :(

When adapter returns Collection.models, i loose access to attributes (builtin or custom) defined at my Collection.
So I did this,

        // rivets cant iterate over Backbone.Collection -> return Array
        if (value instanceof Collection) {
            value.models.parent = value;
            return value.models;
        }

This way i can check for it. obj.parent instanceof Backbone.Collection
And access attrs using obj.parent.attr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants