713507c2 by Michael Richards

Compile changes from #12 and #15.

1 parent 1fda314c
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
14 this.model = model; 14 this.model = model;
15 this.keypath = keypath; 15 this.keypath = keypath;
16 this.formatters = formatters != null ? formatters : []; 16 this.formatters = formatters != null ? formatters : [];
17 this.unbind = __bind(this.unbind, this);
18
19 this.publish = __bind(this.publish, this);
20
17 this.bind = __bind(this.bind, this); 21 this.bind = __bind(this.bind, this);
18 22
19 this.set = __bind(this.set, this); 23 this.set = __bind(this.set, this);
...@@ -32,20 +36,27 @@ ...@@ -32,20 +36,27 @@
32 }; 36 };
33 37
34 Binding.prototype.bind = function() { 38 Binding.prototype.bind = function() {
35 var _ref, 39 var _ref;
36 _this = this; 40 Rivets.config.adapter.subscribe(this.model, this.keypath, this.set);
37 Rivets.config.adapter.subscribe(this.model, this.keypath, function(value) {
38 return _this.set(value);
39 });
40 if (Rivets.config.preloadData) { 41 if (Rivets.config.preloadData) {
41 this.set(Rivets.config.adapter.read(this.model, this.keypath)); 42 this.set(Rivets.config.adapter.read(this.model, this.keypath));
42 } 43 }
43 if (_ref = this.type, __indexOf.call(bidirectionals, _ref) >= 0) { 44 if (_ref = this.type, __indexOf.call(bidirectionals, _ref) >= 0) {
44 return this.el.addEventListener('change', function(e) { 45 return this.el.addEventListener('change', this.publish);
45 var el; 46 }
46 el = e.target || e.srcElement; 47 };
47 return Rivets.config.adapter.publish(_this.model, _this.keypath, getInputValue(el)); 48
48 }); 49 Binding.prototype.publish = function(e) {
50 var el;
51 el = e.target || e.srcElement;
52 return Rivets.config.adapter.publish(this.model, this.keypath, getInputValue(el));
53 };
54
55 Binding.prototype.unbind = function() {
56 var _ref;
57 Rivets.config.adapter.unsubscribe(this.model, this.keypath, this.set);
58 if (_ref = this.type, __indexOf.call(bidirectionals, _ref) >= 0) {
59 return this.el.removeEventListener('change', this.publish);
49 } 60 }
50 }; 61 };
51 62
...@@ -78,8 +89,9 @@ ...@@ -78,8 +89,9 @@
78 }; 89 };
79 90
80 View.prototype.build = function() { 91 View.prototype.build = function() {
81 var attribute, keypath, model, node, path, pipes, type, _i, _len, _ref, _results; 92 var attribute, bindingRegExp, keypath, model, node, path, pipes, type, _i, _len, _ref, _results;
82 this.bindings = []; 93 this.bindings = [];
94 bindingRegExp = this.bindingRegExp();
83 _ref = this.el.getElementsByTagName('*'); 95 _ref = this.el.getElementsByTagName('*');
84 _results = []; 96 _results = [];
85 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 97 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
...@@ -90,8 +102,8 @@ ...@@ -90,8 +102,8 @@
90 _results1 = []; 102 _results1 = [];
91 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { 103 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
92 attribute = _ref1[_j]; 104 attribute = _ref1[_j];
93 if (this.bindingRegExp().test(attribute.name)) { 105 if (bindingRegExp.test(attribute.name)) {
94 type = attribute.name.replace(this.bindingRegExp(), ''); 106 type = attribute.name.replace(bindingRegExp, '');
95 pipes = attribute.value.split('|').map(function(pipe) { 107 pipes = attribute.value.split('|').map(function(pipe) {
96 return pipe.trim(); 108 return pipe.trim();
97 }); 109 });
......