mxriverlynn / backbone.picky

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

Attribute vs member #7

Open paultyng opened 11 years ago

paultyng commented 11 years ago

The docs for this seem to say it will change a "selected" attribute on the model but it seems to only set a member on that instance instead of in the attributes collection via set.

On Backbone.Picky.Selectable:

    select: function () {
      if (this.selected) { return; }

      **this.selected = true;**
      this.trigger("selected");

      if (this.collection) {
        this.collection.select(this);
      }
    },

Is this intentional? I have to override my view serialization to render to pass this every time, so seems undesirable, but maybe I'm missing something?

Is this so that a change event isn't also fired or something? I guess on a fetch you would lose the selection state as well, but that could be handled.

AdrianRossouw commented 11 years ago

it seems that this is by design. it might also be a bit much of an assumption to make, that the model is automatically selected for anybody who loads it.

perhaps you can just subscribe to the 'select' event to set an attribute on the model, and on fetch or reset of the model, trigger the relevant select on the collection.