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

Collection#set style (Backwards Compatible) #3663

Merged
merged 17 commits into from
Aug 18, 2015

Conversation

jridgewell
Copy link
Collaborator

This is a backwards compatible version of #3648.

Depending on how much performance is an issue, we can use an even faster splice algorithm (also included in the jsperfs), it's just a bit complicated.

@jridgewell jridgewell force-pushed the collection-set-style-compat branch from 84b8071 to 0052c2f Compare June 4, 2015 01:00
var singular = !_.isArray(models);
models = singular ? (models ? [models] : []) : models.slice();
var id, model, attrs, existing, sort;
models = singular ? [models] : _.clone(models);
Copy link
Collaborator

Choose a reason for hiding this comment

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

is clone faster here? Shouldn't it be quicker to avoid the logic branch in clone?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ha, didn't even notice I changed that.

@akre54
Copy link
Collaborator

akre54 commented Jun 4, 2015

👍

@jridgewell jridgewell mentioned this pull request Jul 21, 2015
@@ -1565,7 +1565,7 @@
collection.on('sort', function() {
ok(true);
});
collection.set([{id: 3}, {id: 2}, {id: 1}, {id: 0}]);
collection.set([{id: 1}, {id: 2}, {id: 3}, {id: 0}]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the reason for this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"Adding a model should trigger a sort". Seemed better to only add a model, as the mixed order case is handled in the test above.

Copy link
Collaborator

Choose a reason for hiding this comment

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

fair nuf. maybe split this out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Split it into what?

@jashkenas
Copy link
Owner

Changing set internals is always an adventure — I hope this doesn't break some unexpected things ... but — splice function unfortunate black magic aside, this looks pretty nice.

jashkenas added a commit that referenced this pull request Aug 18, 2015
Collection#set style (Backwards Compatible)
@jashkenas jashkenas merged commit 09fca1d into jashkenas:master Aug 18, 2015
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 this pull request may close these issues.

5 participants