optimistic model.destroy() #1347

Closed
killanaca opened this Issue May 25, 2012 · 4 comments

Comments

Projects
None yet
2 participants

Hi

there's a way (without rewrite the model.destroy() method) to prevent the destroy event bubbles up to collection that contains the model istance?

I want to check the server response(the json content not the HTTP code) on HTTP DELETE response and in some case (for example when the server's response contains 'error_messege' inside the json) do not remove the model from collection.

I know there's success callback inside the model.destroy(), but when it's call, the destroy event was already triggered and bubbles up to collection

thanks

Owner

jashkenas commented May 25, 2012

How about:

model.destroy({wait: true});

?

jashkenas closed this May 25, 2012

Sure, i know the behaviour of {wait: true}, but my question is different.
When HTTP DELETE returns, the destroy's success callback is call, but i cant prevent (if for example the server response contains an error message) that the destroy event bubbles up till the collection.

from Backbone.destroy():

options.success = function(resp) {
        if (options.wait) triggerDestroy();
        if (success) {
          success(model, resp);
        } else {
          model.trigger('sync', model, resp, options);
        }
      };
Owner

jashkenas commented May 25, 2012

If your server has an error, then return your error message with a non-200 HTTP status code, and the success callback won't be triggered.

So either in destroy() either in create(), all the non-200 http return code invoke error callback instead of success?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment