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

Marionette 2.0 - isEmpty doesn't use the collection it is passed #1566

Closed
MeoMix opened this issue Jul 3, 2014 · 15 comments
Closed

Marionette 2.0 - isEmpty doesn't use the collection it is passed #1566

MeoMix opened this issue Jul 3, 2014 · 15 comments

Comments

@MeoMix
Copy link
Member

MeoMix commented Jul 3, 2014

    // check if the collection is empty
    isEmpty: function (collection) {
        return !this.collection || this.collection.length === 0;
    }

line 2071

@samccone samccone added the bug label Jul 3, 2014
@joshbedo
Copy link

joshbedo commented Jul 8, 2014

👍
I didn't even know you could pass the collection into the isEmpty() method. I use it mainly like view.isEmpty() I'm not sure when you would want to do view.isEmpty(collection)

@samccone
Copy link
Member

samccone commented Jul 8, 2014

Me either @joshbedo alas need to fix this one

@samccone samccone added this to the v2.0.2 milestone Jul 8, 2014
@jamesplease
Copy link
Member

Just fyi there are tons of methods like this in Marionette. I chose not to change it in v2 because it's potentially breaking, and affects so much of the codebase.

We should make a single issue to track all of them.

@MeoMix
Copy link
Member Author

MeoMix commented Jul 8, 2014

I made a quick scan of Marionette (visual studio highlights unused JavaScript variables) and created issues for the ones I saw. There weren't tons, only a handful, but perhaps others using variables but not correctly.

@samccone
Copy link
Member

samccone commented Jul 8, 2014

"Fixing" this method would be breaking if someone is passing random data to the method and all of a sudden we start returning the correct value.

Currently the implementation contract and the documentation are out of sync.

The fix could be simply to X the argument

@joshbedo
Copy link

joshbedo commented Jul 8, 2014

Couldn't something like this potentially be done? That way the old way and correct way both work. I personally don't think anyone should ever pass a collection as an argument.. thats what utility methods are for. If it was _.isEmpty() that would be understandable.

    isEmpty: function (collection) {
      col = collection || this.collection  
      return !col || col.length === 0;
    }

@cmaher
Copy link
Member

cmaher commented Jul 8, 2014

+1 to removing the argument. I don't see any benefit to implementing new behavior just because the signature is weird.

@samccone
Copy link
Member

samccone commented Jul 8, 2014

👍

@joshbedo
Copy link

joshbedo commented Jul 8, 2014

@cmaher agreed, nobody uses collection as an argument anyway and if they do they should stop :)

@jamesplease
Copy link
Member

Related: #930

@jamiebuilds
Copy link
Member

👍

@samccone
Copy link
Member

The fix for these is to add Documentation around why the argument is there.

@samccone samccone removed this from the v2.0.2 milestone Jul 10, 2014
cmaher added a commit to cmaher/backbone.marionette that referenced this issue Jul 11, 2014
@cmaher
Copy link
Member

cmaher commented Jul 11, 2014

Every time this is called, the CollectionView passes this.collection to it. Is this something that should be removed in v3/4 and documented for now?

@samccone
Copy link
Member

yep @cmaher totally!

PS not sure if we ever want to actually remove it because it is useful if you are overriding the method

@jamesplease
Copy link
Member

PS not sure if we ever want to actually remove it because it is useful if you are overriding the method

I think @cmaher's point is that the method will always be called from the collection view itself, so you will have access to this.collection and every other property from within the method. No need to pass it in.

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

No branches or pull requests

7 participants