SteveSanderson / knockout.mapping

Object mapping plugin for KnockoutJS
Other
545 stars 767 forks source link

mapping causes excessive updates to arrays on existing view models #110

Open estrizhok opened 12 years ago

estrizhok commented 12 years ago

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.

marcofranssen commented 12 years ago

See issue https://github.com/SteveSanderson/knockout.mapping/issues/115 for a small workarround. I have some issue the observable array is replaced, but I want the new items pushed to it.