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
- findForCurrentUser: function(user, success, error) {
- var models = this.models;
- return $.ajax("/some/user-specific/path", {
- dataType: "json",
- success: function(data){
- success(models(data))
- },
- error: error
- }
- }
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:
- findForCurrentUser: function(user, success, error) {
- var models = this.models;
- return $.ajax("/some/user-specific/path", { dataType: "json" })
- .pipe(function(data) {
- return models(data)
- })
- .done(success).fail(error)
- }
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