Permalink
Browse files

merge select:one change from dznz

  • Loading branch information...
2 parents 7517ce6 + 3cfa864 commit 30f910b707fac1f6e93d35bc94330b8dbd50211a @derickbailey committed Jul 22, 2013
Showing with 28 additions and 18 deletions.
  1. +10 −7 readme.md
  2. +15 −10 spec/javascripts/singleSelect.spec.js
  3. +3 −1 src/backbone.picky.js
View
17 readme.md
@@ -185,11 +185,13 @@ The following events are triggered from Selectable models
#### "selected"
-Triggers when a model is selected.
+Triggers when a model is selected. Provides the selected model
+as the first parameter.
#### "deselected"
-Triggers when a model is deselected.
+Triggers when a model is deselected. Provides the selected model
+as the first parameter.
## Picky.SingleSelect
@@ -292,15 +294,15 @@ myCol.selected; //=> model
### SingleSelect Events
-The following events are triggered by the MultiSelect based on changes
+The following events are triggered by the SingleSelect based on changes
in selection:
-#### "selected"
+#### "select:one"
Triggered when a model has been selected. Provides the selected model
as the first parameter.
-#### "deselected"
+#### "deselect:one"
Triggered when a model has been deselected. Provides the deselected model
as the first parameter.
@@ -496,9 +498,10 @@ see all of the specs for Backbone.Picky
## Release Notes
-### v0.1.1
+### v0.2.0
-* Pass model as argument in selected / deselected events
+* Renamed `SingleSelect` events from "select" and "deselect" to "select:one" and "deselect:one"
+* Pass model as argument in select:one / deselect:one events
* Updated the build to use latest grunt and related tools
* Removed reliance on ruby for any part of this project
View
25 spec/javascripts/singleSelect.spec.js
@@ -23,6 +23,7 @@ describe("single select collection", function(){
model = new Model();
collection = new Collection([model]);
+ spyOn(model, "trigger").andCallThrough();
spyOn(collection, "trigger").andCallThrough();
model.select();
@@ -33,7 +34,11 @@ describe("single select collection", function(){
});
it("should trigger a selected event", function(){
- expect(collection.trigger).toHaveBeenCalledWith("selected", model);
+ expect(model.trigger).toHaveBeenCalledWith("selected", model);
+ });
+
+ it("should trigger a collection selected event", function(){
+ expect(collection.trigger).toHaveBeenCalledWith("select:one", model);
});
});
@@ -55,7 +60,7 @@ describe("single select collection", function(){
});
it("should trigger a selected event", function(){
- expect(collection.trigger).toHaveBeenCalledWith("selected", model);
+ expect(collection.trigger).toHaveBeenCalledWith("select:one", model);
});
it("should tell the model to select itself", function(){
@@ -78,7 +83,7 @@ describe("single select collection", function(){
});
it("should not trigger a selected event", function(){
- expect(collection.trigger).not.toHaveBeenCalledWith("selected", model);
+ expect(collection.trigger).not.toHaveBeenCalledWith("select:one", model);
});
});
@@ -102,15 +107,15 @@ describe("single select collection", function(){
});
it("should trigger a selected event", function(){
- expect(collection.trigger).toHaveBeenCalledWith("selected", m2);
+ expect(collection.trigger).toHaveBeenCalledWith("select:one", m2);
});
it("should deselect the first model", function(){
expect(m1.deselect).toHaveBeenCalled();
});
it("should fire a deselect event for the first model", function(){
- expect(collection.trigger).toHaveBeenCalledWith("deselected", m1);
+ expect(collection.trigger).toHaveBeenCalledWith("deselect:one", m1);
});
});
@@ -148,7 +153,7 @@ describe("single select collection", function(){
});
it("should trigger a deselected event", function(){
- expect(collection.trigger).toHaveBeenCalledWith("deselected", model);
+ expect(collection.trigger).toHaveBeenCalledWith("deselect:one", model);
});
});
@@ -180,11 +185,11 @@ describe("single select collection", function(){
});
it("should not trigger a deselected event for the selected model", function(){
- expect(collection.trigger).not.toHaveBeenCalledWith("deselected", m1);
+ expect(collection.trigger).not.toHaveBeenCalledWith("deselect:one", m1);
});
it("should not trigger a deselected event for the non-selected model", function(){
- expect(collection.trigger).not.toHaveBeenCalledWith("deselected", m2);
+ expect(collection.trigger).not.toHaveBeenCalledWith("deselect:one", m2);
});
});
@@ -216,11 +221,11 @@ describe("single select collection", function(){
});
it("should not trigger a deselected event for the selected model", function(){
- expect(collection.trigger).not.toHaveBeenCalledWith("deselected", m1);
+ expect(collection.trigger).not.toHaveBeenCalledWith("deselect:one", m1);
});
it("should not trigger a deselected event for the non-selected model", function(){
- expect(collection.trigger).not.toHaveBeenCalledWith("deselected", m2);
+ expect(collection.trigger).not.toHaveBeenCalledWith("deselect:one", m2);
});
});
View
4 src/backbone.picky.js
@@ -15,14 +15,15 @@ Backbone.Picky = (function (Backbone, _) {
_.extend(Picky.SingleSelect.prototype, {
// Select a model, deselecting any previously
- // select model
+ // selected model
select: function(model){
if (model && this.selected === model) { return; }
this.deselect();
this.selected = model;
this.selected.select();
+ this.trigger("select:one", model);
},
// Deselect a model, resulting in no model
@@ -34,6 +35,7 @@ Backbone.Picky = (function (Backbone, _) {
if (this.selected !== model){ return; }
this.selected.deselect();
+ this.trigger("deselect:one", this.selected);
delete this.selected;
}

0 comments on commit 30f910b

Please sign in to comment.