Browse files

Pass model as an argument to triggered events in the selectable mixin

  • Loading branch information...
1 parent 55f4b83 commit 91a2a486bb3ae8d03baa5a1a29cb7a3cf23a1682 @yethee yethee committed Nov 9, 2012
View
10 spec/javascripts/multiSelect.selectable.interaction.spec.js
@@ -86,16 +86,24 @@ describe("multi-select selectable interaction", function(){
m1 = new Model();
collection = new Collection([m1]);
- m1.select();
spyOn(collection, "trigger").andCallThrough();
+ m1.select();
m1.deselect();
});
it("should trigger 'none' selected event", function(){
expect(collection.trigger).toHaveBeenCalledWith("select:none", collection);
});
+ it("should trigger 'selected' event with the selected model", function(){
+ expect(collection.trigger).toHaveBeenCalledWith("selected", m1);
+ });
+
+ it("should trigger 'deselected' event with the deselected model", function(){
+ expect(collection.trigger).toHaveBeenCalledWith("deselected", m1);
+ });
+
it("should have a selected count of 0", function(){
expect(collection.selectedLength).toBe(0);
});
View
8 spec/javascripts/selectable.spec.js
@@ -21,7 +21,7 @@ describe("selectable model", function(){
});
it("should notify of selection", function(){
- expect(model.trigger).toHaveBeenCalledWith("selected");
+ expect(model.trigger).toHaveBeenCalledWith("selected", model);
});
});
@@ -41,7 +41,7 @@ describe("selectable model", function(){
});
it("should not notify of selection", function(){
- expect(model.trigger).not.toHaveBeenCalledWith("selected");
+ expect(model.trigger).not.toHaveBeenCalledWith("selected", model);
});
});
@@ -61,7 +61,7 @@ describe("selectable model", function(){
});
it("should notify of deselection", function(){
- expect(model.trigger).toHaveBeenCalledWith("deselected");
+ expect(model.trigger).toHaveBeenCalledWith("deselected", model);
});
});
@@ -80,7 +80,7 @@ describe("selectable model", function(){
});
it("should not notify of deselection", function(){
- expect(model.trigger).not.toHaveBeenCalledWith("deselected");
+ expect(model.trigger).not.toHaveBeenCalledWith("deselected", model);
});
});
View
6 src/backbone.picky.js
@@ -23,7 +23,6 @@ Backbone.Picky = (function (Backbone, _) {
this.selected = model;
this.selected.select();
- this.trigger("selected", model);
},
// Deselect a model, resulting in no model
@@ -35,7 +34,6 @@ Backbone.Picky = (function (Backbone, _) {
if (this.selected !== model){ return; }
this.selected.deselect();
- this.trigger("deselected", this.selected);
delete this.selected;
}
@@ -118,7 +116,7 @@ Backbone.Picky = (function (Backbone, _) {
if (this.selected) { return; }
this.selected = true;
- this.trigger("selected");
+ this.trigger("selected", this);
if (this.collection) {
this.collection.select(this);
@@ -131,7 +129,7 @@ Backbone.Picky = (function (Backbone, _) {
if (!this.selected) { return; }
this.selected = false;
- this.trigger("deselected");
+ this.trigger("deselected", this);
if (this.collection) {
this.collection.deselect(this);

0 comments on commit 91a2a48

Please sign in to comment.