Backbone.Model silence "fetch"

Is there any way to ask Backbone.Model to get quiet? the option {silent: true} does not work for fetching a model. Basically, I wanted to disable the synchronization event that is already being listened to by the current view.

ListenTo:

self.listenTo(self.model, 'sync', self.subscriberParameterSyncSuccesfully);

Fetch:

self.model.fetch({
    success: function() {
        self.bindEventsToModel();
        self.renderDetailsBody(false);
    },
    error: self.handleRouteError
}, {silent: true});
+4
source share
1 answer

No, you can’t. The trunk always fires a sync event in response to success. However, you can make a wrapper and fire another event. therefore you avoid depending on the synchronization event.

self.listenTo(self.model, 'mysync', self.subscriberParameterSyncSuccesfully);

Model:

myfetch: function (option) {
    this.fetch.call(this, option);
    this.trigger('mysync', this);
}

self.model.myfetch(option);
+3
source

Source: https://habr.com/ru/post/1540042/


All Articles