Skip to content
This repository has been archived by the owner on May 17, 2018. It is now read-only.

initialize() method only supports the "models" parameter as an array #76

Merged
merged 2 commits into from
May 1, 2013

Conversation

gbedardsice
Copy link
Contributor

In the initialize method, the "models" parameter is considered an array. The thing is, in a plain backbone collection, I can do something like:

var collection = new Backbone.Collection({hello: 'world'})

and it will instantiate the collection with a single model in it.

But if I do this with a pageable collection, I get errors because an object is not expected.

@wyuenho
Copy link
Member

wyuenho commented May 1, 2013

This isn't actually advertised or documented. In fact there isn't a test case that guarantees this behavior in Backbone. It's just a side effect that Backbone.Collection's constructor delegates to reset which delegates to add. I don't have anything against supporting this tho, it should be fairly easy. PR welcome.

@@ -303,6 +303,8 @@
state.firstPage :
state.currentPage;

if (!_.isArray(models)) models = models ? [models] : [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change _.isArray to _isArray to help the minifier with name mangling.

wyuenho added a commit that referenced this pull request May 1, 2013
Support non-array elements in the constructor
@wyuenho wyuenho merged commit 4f4ad59 into backbone-paginator:master May 1, 2013
@wyuenho
Copy link
Member

wyuenho commented May 1, 2013

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants