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

Map does not have parseModel (ajax convert) #18

Open
justinbmeyer opened this issue Apr 12, 2017 · 0 comments
Open

Map does not have parseModel (ajax convert) #18

justinbmeyer opened this issue Apr 12, 2017 · 0 comments

Comments

@justinbmeyer
Copy link
Contributor

@lewismoten commented on Wed Oct 12 2016

I'm having a bug pop up. this.parseModel is undefined. This happens when an ajax request completes in jQuery, and CanJS has a proxy to convert the response to a model. In this case, "this" represents the CanJS "Map"

jquery.js - Callback for a completed ajax request...

complete( // complete === jquery.js done
  xhrSuccessStatus[ xhr.status ] || xhr.status, // 200
  xhr.statusText, // "OK"
  ( xhr.responseType || "text" ) !== "text"  ||
  typeof xhr.responseText !== "string" ?
    { binary: xhr.response } :
    { text: xhr.responseText }, // {text: '{"name": "value"}'}
  xhr.getAllResponseHeaders() // Pragma: no-cache, etc.
);                          

jquery.js - done

response = ajaxConvert( s, response, jqXHR, isSuccess );
// ajaxConvert === jquery.js ajaxConvert
// s === (ajax options)
// response === {error: "SyntaxError: Unexpected token o in JSON", state: "parsererror"}
// jqXHR === jqXHR...
// isSuccess === true

jquery.js - ajaxConvert:

response = conv( response ); 
// response ==={error: "..."}
// conv === can/proxy.js class_cb

can/construct/proxy/proxy.js - class_cb

cur = (isString ? self[func] : func).apply(self, cur || []);
// self = Map
// func = "model"
// cur = [{error: "..."}]

Which essentially translates to:

Map.model.call(Map, {error: "..."})

can/model/model.js - model

attributes = this.parseModel(attributes, xhr);
// this === Map
// attributes === {error: "..."}
// xhr === undefined
// this.parseModel === undefined

How can I get "Map" to have "parseModel"?

It appears that this may be a work-around...

attributes = function(attributes){
    return function (attributes) {
        return prop ? can.getObject(prop, attributes) : attributes;
    };
};
//attributes = this.parseModel(attributes, xhr);

@justinbmeyer commented on Tue Apr 11 2017

@lewismoten Anyway you can create an example? Moving to can-model.

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

1 participant