54ae655a by Michael Richards

Merge branch 'master' into text-templates

2 parents f7c291b5 dba47367
...@@ -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 facility.", 4 "description": "Declarative data binding facility.",
5 "version": "0.5.7", 5 "version": "0.5.8",
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.5.7 2 // version: 0.5.8
3 // author: Michael Richards 3 // author: Michael Richards
4 // license: MIT 4 // license: MIT
5 (function() { 5 (function() {
...@@ -173,10 +173,31 @@ ...@@ -173,10 +173,31 @@
173 } 173 }
174 }; 174 };
175 175
176 Binding.prototype.update = function() { 176 Binding.prototype.update = function(models) {
177 this.unbind(); 177 var _ref;
178 this.model = this.key ? this.view.models[this.key] : this.view.models; 178
179 return this.bind(); 179 if (models == null) {
180 models = {};
181 }
182 if (this.key) {
183 if (models[this.key]) {
184 if (!this.options.bypass) {
185 this.view.config.adapter.unsubscribe(this.model, this.keypath, this.sync);
186 }
187 this.model = models[this.key];
188 if (this.options.bypass) {
189 this.sync();
190 } else {
191 this.view.config.adapter.subscribe(this.model, this.keypath, this.sync);
192 if (this.view.config.preloadData) {
193 this.sync();
194 }
195 }
196 }
197 } else {
198 this.sync();
199 }
200 return (_ref = this.binder.update) != null ? _ref.call(this, models) : void 0;
180 }; 201 };
181 202
182 return Binding; 203 return Binding;
...@@ -404,28 +425,20 @@ ...@@ -404,28 +425,20 @@
404 }; 425 };
405 426
406 View.prototype.update = function(models) { 427 View.prototype.update = function(models) {
407 var binding, key, model, _results; 428 var binding, key, model, _i, _len, _ref, _results;
408 429
409 if (models == null) { 430 if (models == null) {
410 models = {}; 431 models = {};
411 } 432 }
412 _results = [];
413 for (key in models) { 433 for (key in models) {
414 model = models[key]; 434 model = models[key];
415 this.models[key] = model; 435 this.models[key] = model;
416 _results.push((function() { 436 }
417 var _i, _len, _ref, _results1; 437 _ref = this.bindings;
418 438 _results = [];
419 _ref = this.select(function(b) { 439 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
420 return b.key === key; 440 binding = _ref[_i];
421 }); 441 _results.push(binding.update(models));
422 _results1 = [];
423 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
424 binding = _ref[_i];
425 _results1.push(binding.update());
426 }
427 return _results1;
428 }).call(this));
429 } 442 }
430 return _results; 443 return _results;
431 }; 444 };
...@@ -631,6 +644,9 @@ ...@@ -631,6 +644,9 @@
631 return delete this.nested; 644 return delete this.nested;
632 } 645 }
633 } 646 }
647 },
648 update: function(models) {
649 return this.nested.update(models);
634 } 650 }
635 }, 651 },
636 unless: { 652 unless: {
...@@ -643,6 +659,9 @@ ...@@ -643,6 +659,9 @@
643 }, 659 },
644 routine: function(el, value) { 660 routine: function(el, value) {
645 return Rivets.binders["if"].routine.call(this, el, !value); 661 return Rivets.binders["if"].routine.call(this, el, !value);
662 },
663 update: function(models) {
664 return Rivets.binders["if"].update.call(this, models);
646 } 665 }
647 }, 666 },
648 "on-*": { 667 "on-*": {
...@@ -737,6 +756,24 @@ ...@@ -737,6 +756,24 @@
737 } 756 }
738 } 757 }
739 return _results; 758 return _results;
759 },
760 update: function(models) {
761 var data, key, model, view, _i, _len, _ref, _results;
762
763 data = {};
764 for (key in models) {
765 model = models[key];
766 if (key !== this.args[0]) {
767 data[key] = model;
768 }
769 }
770 _ref = this.iterated;
771 _results = [];
772 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
773 view = _ref[_i];
774 _results.push(view.update(data));
775 }
776 return _results;
740 } 777 }
741 }, 778 },
742 "class-*": function(el, value) { 779 "class-*": function(el, value) {
......
1 { 1 {
2 "name": "rivets", 2 "name": "rivets",
3 "description": "Declarative data binding facility.", 3 "description": "Declarative data binding facility.",
4 "version": "0.5.7", 4 "version": "0.5.8",
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",
......
1 # Rivets.js 1 # Rivets.js
2 # ========= 2 # =========
3 3
4 # > version: 0.5.7 4 # > version: 0.5.8
5 # > author: Michael Richards 5 # > author: Michael Richards
6 # > license: MIT 6 # > license: MIT
7 # > 7 # >
...@@ -137,10 +137,23 @@ class Rivets.Binding ...@@ -137,10 +137,23 @@ class Rivets.Binding
137 137
138 # Updates the binding's model from what is currently set on the view. Unbinds 138 # Updates the binding's model from what is currently set on the view. Unbinds
139 # the old model first and then re-binds with the new model. 139 # the old model first and then re-binds with the new model.
140 update: => 140 update: (models = {}) =>
141 @unbind() 141 if @key
142 @model = if @key then @view.models[@key] else @view.models 142 if models[@key]
143 @bind() 143 unless @options.bypass
144 @view.config.adapter.unsubscribe @model, @keypath, @sync
145
146 @model = models[@key]
147
148 if @options.bypass
149 @sync()
150 else
151 @view.config.adapter.subscribe @model, @keypath, @sync
152 @sync() if @view.config.preloadData
153 else
154 @sync()
155
156 @binder.update?.call @, models
144 157
145 # Rivets.View 158 # Rivets.View
146 # ----------- 159 # -----------
...@@ -263,9 +276,8 @@ class Rivets.View ...@@ -263,9 +276,8 @@ class Rivets.View
263 276
264 # Updates the view's models along with any affected bindings. 277 # Updates the view's models along with any affected bindings.
265 update: (models = {}) => 278 update: (models = {}) =>
266 for key, model of models 279 @models[key] = model for key, model of models
267 @models[key] = model 280 binding.update models for binding in @bindings
268 binding.update() for binding in @select (b) -> b.key is key
269 281
270 # Rivets.TextTemplateParser 282 # Rivets.TextTemplateParser
271 # ------------------------- 283 # -------------------------
...@@ -461,6 +473,9 @@ Rivets.binders = ...@@ -461,6 +473,9 @@ Rivets.binders =
461 @nested.unbind() 473 @nested.unbind()
462 delete @nested 474 delete @nested
463 475
476 update: (models) ->
477 @nested.update models
478
464 unless: 479 unless:
465 block: true 480 block: true
466 481
...@@ -473,6 +488,9 @@ Rivets.binders = ...@@ -473,6 +488,9 @@ Rivets.binders =
473 routine: (el, value) -> 488 routine: (el, value) ->
474 Rivets.binders.if.routine.call @, el, not value 489 Rivets.binders.if.routine.call @, el, not value
475 490
491 update: (models) ->
492 Rivets.binders.if.update.call @, models
493
476 "on-*": 494 "on-*":
477 function: true 495 function: true
478 496
...@@ -539,6 +557,14 @@ Rivets.binders = ...@@ -539,6 +557,14 @@ Rivets.binders =
539 else if @iterated[index].models[modelName] isnt model 557 else if @iterated[index].models[modelName] isnt model
540 @iterated[index].update data 558 @iterated[index].update data
541 559
560 update: (models) ->
561 data = {}
562
563 for key, model of models
564 data[key] = model unless key is @args[0]
565
566 view.update data for view in @iterated
567
542 "class-*": (el, value) -> 568 "class-*": (el, value) ->
543 elClass = " #{el.className} " 569 elClass = " #{el.className} "
544 570
......