Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Automatic conversion for methods in static part of model

$
0
0
Sorry for not answering that long after those great responses. I imagined it would take me longer than a few minutes.

I think I was not clear in my first point. I'll try to improve that:

Alex suggested
  1. findForCurrentUser: function(user, success, error) {
  2.   var models = this.models;
  3.   return $.ajax("/some/user-specific/path", {
  4.     dataType: "json",
  5.     success: function(data){
  6.       success(models(data))
  7.     },
  8.     error: error
  9.   }
  10. }
But this does not correctly do the conversion for the returned deferred, so I assumed it should be piped and argued whether this was an elegant solution:
  1. findForCurrentUser: function(user, success, error) {
  2.   var models = this.models;
  3.   return $.ajax("/some/user-specific/path", { dataType: "json" })
  4.   .pipe(function(data) {
  5.     return models(data)
  6.   })
  7.   .done(success).fail(error)
  8. }
I just wanted to ask whether this was the recommended way of doing things.


Regarding Justin's first valid point on just overloading findAll: this is actually the way I had done it, but I fear that introducing magic parameters like this leads to less maintainable code. That's why I asked this question. Sorry for not having made that clearer.

On the second two points Justin made on adapting the service: I think this is a very valid, but different discussion. I like it very much when things are laid out in a clear, clever and intuitive way. However, there are two things you may want to consider
  • It may not always be possible to change the service
  • It may not always be a good idea to expose potentially expensive operations (read: joins, sub-selects, aggregate functions, projections) to interact with the service layer for the sake of re-usability and genericity.

Back to the original topic: thank you for the answers. I'll go the pipe way for now.

Kariem

Viewing all articles
Browse latest Browse all 3491

Trending Articles