toJS unmaps all properties of sub-objects
fromJS keeps a log of all properties that are mapped. toJS only unmaps properties that were tracked. But this seems to hold true only for the first level of properties in a tree of objects.
Example: see also http://jsfiddle.net/U4nDp/
var person = ko.mapping.fromJS({ firstname: "Knock", lastname: "McOut", address: { street: "Some Street", number: "123" } }), personJS;
person.fullName = ko.computed(function() { return person.firstname + ' ' + person.lastname; }); person.address.fullStreet = ko.computed(function() { return person.address.number + ' ' + person.address.street; });
personJS = ko.mapping.toJS(person);
personJS does NOT contain fullName (which is correct), but DOES contain person.address.fullStreet.
I'd expect that fullStreet is not unmapped by toJS either. Stepping through the fromJS implementation I can also watch the individual properties of address being added to the mappedProperties, but they seem to be ignored in the toJS implementation.
I found the same issue and I created a fiddle at http://jsfiddle.net/Ncx4w/2/ showing this. I love the plugin but I might have to go manual due to this inconsistency.
Unit test for it:
http://jsfiddle.net/DzenisevichK/tYuxA/