When you create a Backbone model and attach a change event, it will listen for it. And event if you change them at the same time (in the same set call) it will fire the change event the number of changes you have in your model.
So imagine I have a view which is like a grid with filters and it has to refresh every time I change a filter.
My default model looks like this:
defaults: {
filters: {
from: '2016-01-01',
to: today.format(format),
limit: 25,
page: 1,
cycle: 'all'
}
},
I have a listener for the model in the view:
this.listenTo(this.model, 'change:filters', this.onShow);
And every time I change a filter I do:
this.model.set('filters', {
from: '2016-07-01',
to: '2016-07-31',
limit: 25,
page: 1,
cycle: 'currentMonth'
});
As you see I've changed 3 properties of this model. What happen is that it will fire the change event 3 times. What I want to achieve is that it only change once, even if I have 3 changes on the model.
Is that doable?
Thanks in advance