Add always callback option on methods that trigger ajax.
cengebretson opened this issue · comments
Right now we can supply an options map with either done
or fail
callbacks when calling methods that will trigger ajax behind the scenes. We should add always
as an option to complete the promise api.
Also would be nice if the ajax calls that deal with collections had the same callbacks.
I think this would further go in the wrong direction. When I did the work on issue #328 it was with the intention that we could deprecate the done
and fail
options and just always return promise objects.
Appreciate the feedback. So when you say return the promise object do you mean when using just the AjaxQueue or with any ajax call, such as when calling save
on a model.
Its been a while since I was looking at this but I think the direction I was going was looking at the methods that trigger ajax behind the scenes like model.save
. Right now its possible to supply a done
or fail
command to with an options parameter. I was looking to add always
to the mix. I am not sure if it would be possible to have model.save
return a promise, unless some call back method is provided that will receive the xhr/promise as a parameter.
thanks!
Well, my tests covered collection stuff like refresh. It would be super nice if save()
and others like destroy()
returned the promise. I believe it was Spine's intention to look into this but it would mean the base implementation be concerned with ajax. I've made a comment in #434 about this.
BTW, with the current design, you can always get to those promise objects when needed since you can use the ajax.create()
, ajax.update()
, or ajax.destroy()
functions as needed in your models. This is what I do.
It does seem like that would be the cleanest way to do it, have any type of record changing method return a promise object. It would be great to be able to do that regardless of the storage system (ajax, local storage, etc..); but not sure how easy that will be. I just don't have the brain power this weekend to think about :o) but definitely something worth exploring.
I think I am going to close this issue, I'd rather put the energy into something that returns promise objects vs having to pass them in by parameters.
as always appreciate the input!