3ae30db0 by Leonardo Andres Garcia Crespo Committed by Michael Richards

Fix unbind in rivets.binders. [Closes #86]

1 parent a7963f51
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 <script type="text/javascript" src="matchers.js"></script> 15 <script type="text/javascript" src="matchers.js"></script>
16 <script type="text/javascript" src="mock.data.js"></script> 16 <script type="text/javascript" src="mock.data.js"></script>
17 <script type="text/javascript" src="rivets/binding.js"></script> 17 <script type="text/javascript" src="rivets/binding.js"></script>
18 <script type="text/javascript" src="rivets/binders.js"></script>
18 <script type="text/javascript" src="rivets/routines.js"></script> 19 <script type="text/javascript" src="rivets/routines.js"></script>
19 <script type="text/javascript" src="rivets/functional.js"></script> 20 <script type="text/javascript" src="rivets/functional.js"></script>
20 21
......
1 describe("Rives.binders", function() {
2 var context;
3 beforeEach(function() {
4 context = {
5 publish: function() {}
6 }
7 });
8
9 describe("value", function() {
10 var el;
11 beforeEach(function() {
12 el = document.createElement('input');
13 });
14
15 it("unbinds the same bound function", function() {
16 var boundFn;
17 spyOn(el, 'addEventListener').andCallFake(function(event, fn) {
18 boundFn = fn;
19 });
20 rivets.binders.value.bind.call(context, el);
21
22 spyOn(el, 'removeEventListener').andCallFake(function(event, fn) {
23 expect(fn).toBe(boundFn);
24 });
25
26 rivets.binders.value.unbind.call(context, el);
27 });
28 });
29 });
...\ No newline at end of file ...\ No newline at end of file
...@@ -243,9 +243,9 @@ Rivets.binders = ...@@ -243,9 +243,9 @@ Rivets.binders =
243 checked: 243 checked:
244 publishes: true 244 publishes: true
245 bind: (el) -> 245 bind: (el) ->
246 bindEvent el, 'change', @publish 246 @currentListener = bindEvent el, 'change', @publish
247 unbind: (el) -> 247 unbind: (el) ->
248 unbindEvent el, 'change', @publish 248 unbindEvent el, 'change', @currentListener
249 routine: (el, value) -> 249 routine: (el, value) ->
250 if el.type is 'radio' 250 if el.type is 'radio'
251 el.checked = el.value is value 251 el.checked = el.value is value
...@@ -255,9 +255,9 @@ Rivets.binders = ...@@ -255,9 +255,9 @@ Rivets.binders =
255 unchecked: 255 unchecked:
256 publishes: true 256 publishes: true
257 bind: (el) -> 257 bind: (el) ->
258 bindEvent el, 'change', @publish 258 @currentListener = bindEvent el, 'change', @publish
259 unbind: (el) -> 259 unbind: (el) ->
260 unbindEvent el, 'change', @publish 260 unbindEvent el, 'change', @currentListener
261 routine: (el, value) -> 261 routine: (el, value) ->
262 if el.type is 'radio' 262 if el.type is 'radio'
263 el.checked = el.value isnt value 263 el.checked = el.value isnt value
...@@ -276,9 +276,9 @@ Rivets.binders = ...@@ -276,9 +276,9 @@ Rivets.binders =
276 value: 276 value:
277 publishes: true 277 publishes: true
278 bind: (el) -> 278 bind: (el) ->
279 bindEvent el, 'change', @publish 279 @currentListener = bindEvent el, 'change', @publish
280 unbind: (el) -> 280 unbind: (el) ->
281 unbindEvent el, 'change', @publish 281 unbindEvent el, 'change', @currentListener
282 routine: (el, value) -> 282 routine: (el, value) ->
283 if el.type is 'select-multiple' 283 if el.type is 'select-multiple'
284 o.selected = o.value in value for o in el if value? 284 o.selected = o.value in value for o in el if value?
......