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

Commit

Permalink
Added Attribute to unbind correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanpalmer committed Jul 19, 2012
1 parent 4dd7d75 commit e664e05
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
28 changes: 28 additions & 0 deletions spec/SpineDataBindSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,34 @@ describe("Spine.DataBind", function() {
var a = $('#homepage');
expect(a.attr('href')).toBe('http://www.example.com');
});

it("should unbind without destroying other bindings", function() {
if (Watch) {
Person.bind("update[homepage]", function() { console.log("update"); });
expect(Person.constructor._callbacks["update[homepage]"].length).toBe(2);
Person.trigger("destroy-bindings");
expect(Person.constructor._callbacks["update[homepage]"].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[homepage]", function() { console.log("update"); });
expect(Person.constructor._callbacks["update[homepage]"].length).toBe(2);
Controller.refreshBindings(Person);
expect(Person.constructor._callbacks["update[homepage]"].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
2 changes: 1 addition & 1 deletion src/spine.databind.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class Attribute extends Template
keys: [ "attr" ]

bind: (operators,model,el,options) ->
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
5 changes: 1 addition & 4 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 e664e05

Please sign in to comment.