sproutcore/sproutcore — pull request #1285 by mirion (2014-07-24 23:55:35+00:00)
Title: SC.Binding - Adds a transform that aggregates through a function the values at given paths.

Except the and/or transforms, the current version of SC.Binding supports only one source value. In many cases we need to be able to follow several properties and aggregate them into a single computed property that is derived from them. This can be done with observers but implementing it again and again is tedious and potentially a source of errors.

This pull request extends the mechanism implemented by dcporter to handle and/or transforms and converts it into a flexible system that is able to receive several sources of data and aggregate them through a provided function. The public entry point is a transform named "mix" (because it mixes several values to produce a new one). It receives a function (that effectively transform the source values) and several paths corresponding to each property that is followed. Each argument of the function corresponds to a target path. As any other transform it can be followed by another one to produce the final value.

To usage is very simple. For example, to calculate the sum of several values we should use a structure like this:
```javascript
label: SC.LabelView.extend({
valueBinding: SC.Binding.mix(function(v1, v2, v3)
{
return v1 + v2 + v3;
}, 'MyApp.controller1.value', 'MyApp.controller2.value', 'MyApp.controller3.value' )
})
```
Of course, the existing and/or transforms can be converted to this format. Into a future pull request we may extend them to accept more than 2 variables. Without changing the existing behavior to this new one (that accepts more than 2 source properties), writing the mix function for them is trivial.