Build 0.6.4.
Showing
4 changed files
with
44 additions
and
27 deletions
... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
2 | "name": "rivets", | 2 | "name": "rivets", |
3 | "repo": "mikeric/rivets", | 3 | "repo": "mikeric/rivets", |
4 | "description": "Declarative data binding + templating solution.", | 4 | "description": "Declarative data binding + templating solution.", |
5 | "version": "0.6.3", | 5 | "version": "0.6.4", |
6 | "keywords": ["data binding", "templating"], | 6 | "keywords": ["data binding", "templating"], |
7 | "scripts": ["dist/rivets.js"], | 7 | "scripts": ["dist/rivets.js"], |
8 | "main": "dist/rivets.js", | 8 | "main": "dist/rivets.js", | ... | ... |
1 | // Rivets.js | 1 | // Rivets.js |
2 | // version: 0.6.3 | 2 | // version: 0.6.4 |
3 | // author: Michael Richards | 3 | // author: Michael Richards |
4 | // license: MIT | 4 | // license: MIT |
5 | (function() { | 5 | (function() { |
6 | var KeypathObserver, Rivets, | 6 | var Rivets, |
7 | __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | 7 | __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, |
8 | __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, | 8 | __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, |
9 | __slice = [].slice, | 9 | __slice = [].slice, |
... | @@ -389,7 +389,7 @@ | ... | @@ -389,7 +389,7 @@ |
389 | 389 | ||
390 | Binding.prototype.setObserver = function() { | 390 | Binding.prototype.setObserver = function() { |
391 | var _this = this; | 391 | var _this = this; |
392 | this.observer = new KeypathObserver(this.view, this.view.models, this.keypath, function(obs) { | 392 | this.observer = new Rivets.KeypathObserver(this.view, this.view.models, this.keypath, function(obs) { |
393 | if (_this.key) { | 393 | if (_this.key) { |
394 | _this.unbind(true); | 394 | _this.unbind(true); |
395 | } | 395 | } |
... | @@ -475,7 +475,7 @@ | ... | @@ -475,7 +475,7 @@ |
475 | _results = []; | 475 | _results = []; |
476 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | 476 | for (_i = 0, _len = _ref2.length; _i < _len; _i++) { |
477 | dependency = _ref2[_i]; | 477 | dependency = _ref2[_i]; |
478 | observer = new KeypathObserver(this.view, this.model, dependency, function(obs, prev) { | 478 | observer = new Rivets.KeypathObserver(this.view, this.model, dependency, function(obs, prev) { |
479 | var key; | 479 | var key; |
480 | key = obs.key; | 480 | key = obs.key; |
481 | _this.view.adapters[key["interface"]].unsubscribe(prev, key.path, _this.sync); | 481 | _this.view.adapters[key["interface"]].unsubscribe(prev, key.path, _this.sync); |
... | @@ -499,6 +499,7 @@ | ... | @@ -499,6 +499,7 @@ |
499 | if ((_ref = this.binder.unbind) != null) { | 499 | if ((_ref = this.binder.unbind) != null) { |
500 | _ref.call(this, this.el); | 500 | _ref.call(this, this.el); |
501 | } | 501 | } |
502 | this.observer.unobserve(); | ||
502 | } | 503 | } |
503 | if (this.key) { | 504 | if (this.key) { |
504 | this.view.adapters[this.key["interface"]].unsubscribe(this.model, this.key.path, this.sync); | 505 | this.view.adapters[this.key["interface"]].unsubscribe(this.model, this.key.path, this.sync); |
... | @@ -721,12 +722,13 @@ | ... | @@ -721,12 +722,13 @@ |
721 | 722 | ||
722 | })(); | 723 | })(); |
723 | 724 | ||
724 | KeypathObserver = (function() { | 725 | Rivets.KeypathObserver = (function() { |
725 | function KeypathObserver(view, model, keypath, callback) { | 726 | function KeypathObserver(view, model, keypath, callback) { |
726 | this.view = view; | 727 | this.view = view; |
727 | this.model = model; | 728 | this.model = model; |
728 | this.keypath = keypath; | 729 | this.keypath = keypath; |
729 | this.callback = callback; | 730 | this.callback = callback; |
731 | this.unobserve = __bind(this.unobserve, this); | ||
730 | this.realize = __bind(this.realize, this); | 732 | this.realize = __bind(this.realize, this); |
731 | this.update = __bind(this.update, this); | 733 | this.update = __bind(this.update, this); |
732 | this.parse = __bind(this.parse, this); | 734 | this.parse = __bind(this.parse, this); |
... | @@ -788,10 +790,45 @@ | ... | @@ -788,10 +790,45 @@ |
788 | return current; | 790 | return current; |
789 | }; | 791 | }; |
790 | 792 | ||
793 | KeypathObserver.prototype.unobserve = function() { | ||
794 | var index, obj, token, _i, _len, _ref, _results; | ||
795 | _ref = this.tokens; | ||
796 | _results = []; | ||
797 | for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) { | ||
798 | token = _ref[index]; | ||
799 | if (obj = this.objectPath[index]) { | ||
800 | _results.push(this.view.adapters[token["interface"]].unsubscribe(obj, token.path, this.update)); | ||
801 | } else { | ||
802 | _results.push(void 0); | ||
803 | } | ||
804 | } | ||
805 | return _results; | ||
806 | }; | ||
807 | |||
791 | return KeypathObserver; | 808 | return KeypathObserver; |
792 | 809 | ||
793 | })(); | 810 | })(); |
794 | 811 | ||
812 | Rivets.binders.text = function(el, value) { | ||
813 | if (el.textContent != null) { | ||
814 | return el.textContent = value != null ? value : ''; | ||
815 | } else { | ||
816 | return el.innerText = value != null ? value : ''; | ||
817 | } | ||
818 | }; | ||
819 | |||
820 | Rivets.binders.html = function(el, value) { | ||
821 | return el.innerHTML = value != null ? value : ''; | ||
822 | }; | ||
823 | |||
824 | Rivets.binders.show = function(el, value) { | ||
825 | return el.style.display = value ? '' : 'none'; | ||
826 | }; | ||
827 | |||
828 | Rivets.binders.hide = function(el, value) { | ||
829 | return el.style.display = value ? 'none' : ''; | ||
830 | }; | ||
831 | |||
795 | Rivets.binders.enabled = function(el, value) { | 832 | Rivets.binders.enabled = function(el, value) { |
796 | return el.disabled = !value; | 833 | return el.disabled = !value; |
797 | }; | 834 | }; |
... | @@ -836,18 +873,6 @@ | ... | @@ -836,18 +873,6 @@ |
836 | } | 873 | } |
837 | }; | 874 | }; |
838 | 875 | ||
839 | Rivets.binders.show = function(el, value) { | ||
840 | return el.style.display = value ? '' : 'none'; | ||
841 | }; | ||
842 | |||
843 | Rivets.binders.hide = function(el, value) { | ||
844 | return el.style.display = value ? 'none' : ''; | ||
845 | }; | ||
846 | |||
847 | Rivets.binders.html = function(el, value) { | ||
848 | return el.innerHTML = value != null ? value : ''; | ||
849 | }; | ||
850 | |||
851 | Rivets.binders.value = { | 876 | Rivets.binders.value = { |
852 | publishes: true, | 877 | publishes: true, |
853 | bind: function(el) { | 878 | bind: function(el) { |
... | @@ -880,14 +905,6 @@ | ... | @@ -880,14 +905,6 @@ |
880 | } | 905 | } |
881 | }; | 906 | }; |
882 | 907 | ||
883 | Rivets.binders.text = function(el, value) { | ||
884 | if (el.textContent != null) { | ||
885 | return el.textContent = value != null ? value : ''; | ||
886 | } else { | ||
887 | return el.innerText = value != null ? value : ''; | ||
888 | } | ||
889 | }; | ||
890 | |||
891 | Rivets.binders["if"] = { | 908 | Rivets.binders["if"] = { |
892 | block: true, | 909 | block: true, |
893 | bind: function(el) { | 910 | bind: function(el) { | ... | ... |
This diff is collapsed.
Click to expand it.
1 | { | 1 | { |
2 | "name": "rivets", | 2 | "name": "rivets", |
3 | "description": "Declarative data binding + templating solution.", | 3 | "description": "Declarative data binding + templating solution.", |
4 | "version": "0.6.3", | 4 | "version": "0.6.4", |
5 | "author": "Michael Richards", | 5 | "author": "Michael Richards", |
6 | "url": "http://rivetsjs.com", | 6 | "url": "http://rivetsjs.com", |
7 | "main": "./dist/rivets.js", | 7 | "main": "./dist/rivets.js", | ... | ... |
-
Please register or sign in to post a comment