mxriverlynn / backbone.picky

selectable entities as mixins for Backbone.Model and Backbone.Collection
129 stars 29 forks source link

`applyTo` class method for setting up mixins #30

Open hashchange opened 10 years ago

hashchange commented 10 years ago

With this (minor) change, Picky mixins can be applied with a single statement:

SelectableModel = Backbone.Model.extend({
  initialize: function(){
    Backbone.Picky.Selectable.applyTo(this);
  }
});

SingleSelect and MultiSelect mixins work along the same lines. It is a little simpler and more readable than the previous procedure.

Also, I have removed support for creating Picky objects solely with the constructor, like this:

var singleSelect = new Backbone.Picky.SingleSelect(myCollection);

It didn't work any more (don't know exactly when it broke). It would have been tedious to fix reliably, and seemed - to me at least - to to against the grain of how Backbone entities are usually created (based on types, with extend). My "fix" was to remove it from the documentation - no change in code.