ericmbarnard/Knockout-Validation — pull request #223 by delixfe (2013-02-08 18:19:25+00:00)
Title: observable groups do not react to changes in observableArrays

If ```ko.validation.group``` is used with the option ```deep: true``` then it also adds elements of ```ko.observableArrays```. But even with using ```observable: true``` it adds only the elements which exist when creating the validation group. It does not react to:
* adding new entries
* or removing them
* or destroying them.

The pull request fixes that. To not break existing code I have added the option ```live``` to the grouping options. It is ```false``` per default.

When using deep, observable and live then ```traverse``` adds an subscription to each ```observableArray```:

``` javascript
if(options.live && utils.isObservableArray(obj)) {
subscribeToObservableArray(obj);
}
```

Each change in an observableArray triggers a new run of traverse.
``` javascript
var ...
observableArraySubscriptions = [], // we cache the subscripts here to dispose them later
subscribeToObservableArray = function(observableArray) {
observableArraySubscriptions.push(
observableArray.subscribe(traverseAndStoreInValidatables)
);
},
clearObservableArraySubscriptions = function () {
ko.utils.arrayForEach(observableArraySubscriptions, function (subscription) {
subscription.dispose();
});
observableArraySubscriptions = [];
},
traverseAndStoreInValidatables = function() {
clearObservableArraySubscriptions();
validatablesTemp = [];
traverse(obj);
validatables(validatablesTemp);
},

```
I cache the subscriptions to be able to dispose them when any changes happens.

I had to introduce ```validatablesTemp``` to cache the validatables because otherwise the performance was very poor (every change to validatables triggers all bindings and computeds subscribed to it).

The pull request #222 might be necessary for the tests to run correctly.