coderenaissance / knockout.viewmodel

The knockout viewmodel plugin is the fastest, smallest, cleanest, most flexible way to create a knockout viewmodel.
http://coderenaissance.github.com/knockout.viewmodel
106 stars 28 forks source link

toModel excluding computed observables #56

Open ielcoro opened 10 years ago

ielcoro commented 10 years ago

When using a viewModel with computed observables, updatingFromModel works fine, but when mapping back to the model, using toModel, ko.viewmodel omits all computed observables.

When using ko is usual that some extenders replace the current observable with a computed one, so in that case ko.viewmodel becomes unusable.

It appears to be a explicit filter on the recrusiveTo function, excluding all the computed observables:

   if (!ko.isComputed(child) && !((temp = unwrap(child)) && temp.constructor ===       Function)) {

                        recursiveResult = recrusiveTo(child, {
                            name: p,
                            parent: (context.name === "[i]" ? context.parent : context.name) + "." + p,
                            full: context.full + "." + p
                        });

                        //if badResult wasn't returned then add property
                        if (recursiveResult !== badResult) {
                            result[p] = recursiveResult;
                        }
                    }

I did eliminated that filter and now is working as expected.

 if (!((temp = unwrap(child)) && temp.constructor === Function)) {

Can I submit the change?

olavorn commented 8 years ago

Agreed! Must apply patch

cblaze22 commented 8 years ago

Is this applied? This plugin is unusable if not. Nuget seems to still have old version.