test('Should update array only once when updating view model', function() {
var viewModel = { items: ko.observableArray([]) };
var data = { items: ['1', '2'] };
var count = 0;
Observable arrays get updated two times: first at the end of updateViewModel section for arrays, and then in property visitor for parent object to that array. I tried to fix it myself, but couldn't due to very entangled logic of updates.
Here is the test.
test('Should update array only once when updating view model', function() { var viewModel = { items: ko.observableArray([]) }; var data = { items: ['1', '2'] }; var count = 0;
viewModel.items.subscribe(function() { count++; });
ko.mapping.fromJS(data, null, viewModel);
equal(count, 1); });
Observable arrays get updated two times: first at the end of updateViewModel section for arrays, and then in property visitor for parent object to that array. I tried to fix it myself, but couldn't due to very entangled logic of updates.