-
Notifications
You must be signed in to change notification settings - Fork 0
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
Modella 0.2 support #7
Comments
My initial reaction is to have Modella-Ajax emit events that allow modifying of the data, much like Modella 0.2.0 emits |
@rschmukler Can you give an example of how this might look? It's not obvious to me how the event callback would modify the response data. |
Sure, so maybe it'd be something like: User.on('ajaxParseGetBody', function(res) {
res.body.registeredAt = new Date(res.body.registeredAt);
}); Or perhaps more fitting to your exact example. User.on('ajaxParseAllBody', function(res) {
var users = res.body.results;
// Convert JSON string dates into actual dates
users.forEach(u) {
u.registeredAt = new Date(u.registeredAt);
}
res.body = users;
}); And then, basically the code in Modella-ajax would look something like this: request.get(url, function(res) {
Model.emit('ajaxParseAllBody', res);
var instances = new Model(res.body);
...
}); And then |
@rschmukler Yeah, that looks great. |
Closed w/ [#8] |
Since the static sync methods were removed from Modella this plugin needs to instantiate model instances from the result data before returning it from
all
andget
.One additional area that I think needs addressing is some sort of hook for parsing the data returned from the server. For example, a GET to /myresource might return something like:
And would need a corresponding function to parse out those results:
There'd probably need to be 2 parse functions for
get
andall
respectively. What are your thoughts here?The text was updated successfully, but these errors were encountered: