Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

fullCollection missing if collection has its own constructor or initialize method #174

Closed
mastef opened this issue May 11, 2013 · 4 comments
Labels

Comments

@mastef
Copy link

mastef commented May 11, 2013

In my case I'm creating the URL through an options parameter, which I'm defining in the initialize / constructor method :

var myCollection = PageableCollection.extend({
    model: myModel,
    mode: 'client',
    constructor: function(models, options) {
        this.id = options.id;
    },
    url: function(){
        return 'URL/LIST/' + this.id;
    }
});

However, this removes the .fullCollection function ( and maybe more )

Is this expected behaviour and is there a work around?

@wyuenho
Copy link
Contributor

wyuenho commented May 12, 2013

Like any OOP language, anytime you inherit a JS class and extend a method, you should call the superclass' version also unless you reimplement all the functionality's of the superclass' method. So it you do this, it should work as expected:

initialize: function (models, options) {
  this.constructor.__super__.initialize.apply(this, arguments);
}

Overriding the constructor of PageableCollection is not recommended because you'll wipe Backbone.Collection's constructor that way as well.

@wyuenho wyuenho closed this as completed May 12, 2013
@mastef
Copy link
Author

mastef commented May 12, 2013

Thanks Jimmy,

so regarding the logic : backbone.collection handles it by first using this.initialize.apply(this, arguments); when creating the function, and then when extending with Underscore making an empty initialize method available:

    // Initialize is an empty function by default. Override it with your own
    // initialization logic.
    initialize: function(){},

so you don't have to call the superclass version. This way backbone.collection gives you full power over the initialize / constructor methods.

Whereas backbone-pageable then takes possession of that method which breaks pageable functionality if overridden.

I think it would be good then to have a point about this in the documentation as this is a ( small ) caveat which doesn't make it 100% compatible with existing code in itself if you get my meaning.

@wyuenho
Copy link
Contributor

wyuenho commented May 12, 2013

Fixed in backbone-paginator/backbone-pageable#83 and released at 1.2.4.

@mastef
Copy link
Author

mastef commented May 12, 2013

Thanks Jimmy, it was also my mistake to assume constructor === initialize method

I should have written my example with the initialize method instead

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

No branches or pull requests

2 participants