Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Added Visible to unbind correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanpalmer committed Jul 19, 2012
1 parent 00c2be7 commit 4dd7d75
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
28 changes: 28 additions & 0 deletions spec/SpineDataBindSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,34 @@ describe("Spine.DataBind", function() {
var reset = $('#reset');
expect(reset.css('display')).toNotBe('none');
});

it("should unbind without destroying other bindings", function() {
if (Watch) {
Person.bind("update[phoneNumberCount]", function() { console.log("update"); });
expect(Person.constructor._callbacks["update[phoneNumberCount]"].length).toBe(2);
Person.trigger("destroy-bindings");
expect(Person.constructor._callbacks["update[phoneNumberCount]"].length).toBe(1);
} else {
Person.bind("update", function() { console.log("update"); });
expect(Person.constructor._callbacks["update"].length).toBe(2);
Person.trigger("destroy-bindings");
expect(Person.constructor._callbacks["update"].length).toBe(1);
}
});

it("should rebind without destroying other bindings", function() {
if (Watch) {
Person.bind("update[phoneNumberCount]", function() { console.log("update"); });
expect(Person.constructor._callbacks["update[phoneNumberCount]"].length).toBe(2);
Controller.refreshBindings(Person);
expect(Person.constructor._callbacks["update[phoneNumberCount]"].length).toBe(2);
} else {
Person.bind("update", function() { console.log("update"); });
expect(Person.constructor._callbacks["update"].length).toBe(2);
Controller.refreshBindings(Person);
expect(Person.constructor._callbacks["update"].length).toBe(2);
}
});
};

describe("with bindings", function() {
Expand Down
5 changes: 3 additions & 2 deletions src/spine.databind.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ class Visible extends Template

bind: (operators,model,el,options) ->
if options.watch
model.bind("update["+operator.property+"]", => @update([operator],model,el,options)) for operator in operators
@init([operator],model,el,options,"update["+operator.property+"]") for operator in operators
else
model.bind("update", => @update(operators,model,el,options))
@init(operators,model,el,options,"update")

@update(operators,model,el,options)

unbind: (operators,model,el,options) ->
Expand Down
11 changes: 3 additions & 8 deletions src/spine.databind.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4dd7d75

Please sign in to comment.