Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

knockout.mapping toJS does not seem to work in nodejs #195

Open
grofit opened this issue Jun 28, 2014 · 4 comments
Open

knockout.mapping toJS does not seem to work in nodejs #195

grofit opened this issue Jun 28, 2014 · 4 comments

Comments

@grofit
Copy link

grofit commented Jun 28, 2014

I was just testing out some stuff in nodejs and if I were to do:

var ko = require("knockout");
ko.mapping = require("knockout.mapping");

var somePojoWithObservables = new blah();
// populate above

var output = ko.mapping.toJS(somePojoWithObservables);
console.log(output);

It is outputting all the functions etc rather than just the raw object without observables. I notice that this project does not seem to have a package.json and other forks have added this, however it has Steve Sanderson's name on it so I thought it would be best to put down in here.

I have tried just using it without adding to the ko model i.e:

var ko = require("knockout");
var mapping = require("knockout.mapping");

and then using the mapping variable for the mapping jobs, but that gives same result. I am using one of the 11 versions of node, but everything else is working fine (validation and the custom ko.mapping.merge library).

@crissdev
Copy link

@grofit When it comes to plugins this is getting tricky. To get the dependency chain right peerDependencies must be used instead of asking the developer to install knockout separately. From you code example I guess that's something either old or due to aforementioned problem.

@grofit
Copy link
Author

grofit commented Feb 23, 2015

This is actually a double knockout issue, it was mentioned and diagnosed elsewhere but there was no simple fix: knockout/knockout#1624

@crissdev
Copy link

Thanks for the details. If I were to agree on using 2 instances of KO in (i.e.) nodejs then ko.hasPrototype would need to change to use a string based type check. That would fix this issue. But I still believe that plugins should use peerDependencies, as it's the case for Grunt, for instance.

@grofit
Copy link
Author

grofit commented Feb 23, 2015

Yeah I use peerDependencies to sidestep the issue in my scenario

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants