I have also
read
http://tech.adroll.com/blog/web/2013/11/12/lazyloading-backbone-collection-with-promises.html
// View code
users.lookup(id).then(function() {
...
});
// Collection code
lookup: function(id) {
var model;
if (model = this.get(id)) {
return $.Deferred().resolveWith(this, model);
} else {
model = new Model({id: id});
return model.fetch();
}
}
On Thursday, 12 February 2015 11:27:54 UTC+5:30, Mohan Radhakrishnan wrote:
>
> Hi,
> We have services that return 'deferred.promise'. But we also have
> 'functional constructors' which constitute the domain model. Our
> controllers receive the promise directly. In order to break this dependency
> I want to return a JS functional constructor from the service.
>
> This functional constructor should be created and returned instead of
> 'deferred.promise'.
>
> What are the techniques available to do this ?
>
> return {
>
> asynchcall:function() {
> var deferred = $q.defer();
> Somecall().then(
> function(resp) {
> deferred.resolve(resp);
> },
> function(resp) {
> deferred.reject({
> status: resp.status
> });
> });
> return deferred.promise;
> }
> };
>
>
> Thanks,
> Mohan
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.