Permalink
Browse files

Modified so watched spine objects still behave properly with the prot…

…otype

Have to layer on another watch whenever it gets cloned so we keep the
prototype intact
  • Loading branch information...
1 parent 704bc8b commit 089ad722b3cb4c5c101204e7423970eb7a396946 @nathanpalmer nathanpalmer committed Jul 30, 2012
Showing with 26 additions and 4 deletions.
  1. +14 −3 spec/SpineWatchSpec.js
  2. +6 −1 src/spine.watch.coffee
  3. +6 −0 src/spine.watch.js
View
@@ -13,7 +13,7 @@ describe("Spine.Watch", function() {
beforeEach(function() {
spy1 = sinon.spy();
spy2 = sinon.spy();
- obj = Model.create();
+ obj = new Model();
Model.bind("update[prop1]", spy1);
Model.bind("update[prop2]", spy2);
@@ -44,7 +44,7 @@ describe("Spine.Watch", function() {
beforeEach(function() {
spy = sinon.spy();
- obj = Model.create();
+ obj = new Model();
obj.bind("update[prop1]", spy);
});
@@ -72,6 +72,17 @@ describe("Spine.Watch", function() {
runs(function() {
expect(obj.prop1).toBe("Test");
}, 250);
- })
+ });
+
+ it("only changes current model", function() {
+ obj.prop1 = "base";
+
+ var obj1 = obj.clone();
+ var obj2 = obj.clone();
+
+ obj1.prop1 = "Test";
+ expect(obj2.prop1).toBe("base")
+ });
+
});
});
View
@@ -53,4 +53,9 @@ Watch =
Watch.activators = [ "prepareWatch" ] if Spine.Activator
-@Spine.Watch = Watch
+@Spine.Watch = Watch
+
+# Duck punching Spine's clone method so we can add another watch layer
+@Spine.Model::clone = ->
+ o = Object.create(@)
+ o.prepareWatch();
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 089ad72

Please sign in to comment.