diff --git a/src/lib/bind/bind-effects.html b/src/lib/bind/bind-effects.html index d84e2e4af5..afeafd9271 100644 --- a/src/lib/bind/bind-effects.html +++ b/src/lib/bind/bind-effects.html @@ -16,10 +16,14 @@ var method = expression.slice(0, index); var args = expression.slice(index + 1, -1).replace(/ /g, '').split(','); //console.log('%c on [%s] compute [%s] via [%s]', 'color: green', args[0], name, method); - this.addPropertyEffect(model, args[0], 'compute', { + var effect = { property: name, - method: method - }); + method: method, + args: args + }; + for (var i = 0; i < args.length; i++){ + this.addPropertyEffect(model, args[i], 'compute', effect); + } }; Bind._notifyChange = function(property) { @@ -69,7 +73,7 @@ compute: function(model, source, effect) { return 'this.' + effect.property - + ' = this.' + effect.method + '(this._data.' + source + ');'; + + ' = this.' + effect.method + '(this._data.' + effect.args.join(',this._data.') + ');'; }, reflect: function(model, source) { diff --git a/test/unit/bind-elements.html b/test/unit/bind-elements.html index e2afa607e0..725cc54b5a 100644 --- a/test/unit/bind-elements.html +++ b/test/unit/bind-elements.html @@ -21,6 +21,7 @@ }, computed: { computedvalue: 'computeValue(value)', + computedvaluemultipledependencies: 'computedValueMultipleDependencies(value, bool)', computednotifyingvalue: 'computeNotifyingValue(notifyingvalue)' }, bind: { @@ -33,6 +34,9 @@ computeValue: function(val) { return val + 1; }, + computedValueMultipleDependencies: function(val1, val2) { + return val2 ? val1 : -val1; + }, computedvalueChanged: function() {}, notifyingvalueChanged: function() {}, readonlyvalueChanged: function() {}, diff --git a/test/unit/bind.html b/test/unit/bind.html index 9e5e85c2ff..2080599e49 100644 --- a/test/unit/bind.html +++ b/test/unit/bind.html @@ -57,6 +57,18 @@ el.value = 44; assert.equal(el.computedvalue, 45, 'Computed value not correct'); }); + + test('computed value updates with multiple dependencies', function() { + el.bool = true; + el.value = 44; + assert.equal(el.computedvaluemultipledependencies, 44, 'Computed value with multiple dependencies is not correct'); + + el.value = 45; + assert.equal(el.computedvaluemultipledependencies, 45, 'Computed value with multiple dependencies was not updated'); + + el.bool = false; + assert.equal(el.computedvaluemultipledependencies, -45, 'Computed value with multiple dependencies was not updated'); + }); test('notification sent', function() { var notified = false;