When I listen to events within a view it gets trig...
# suitecommerce
m
When I listen to events within a view it gets triggered 3 times. Is there any way to prevent this? When I move the event listener to the Entry Point it triggers only once. But I need a way to tell the view that information has changed. At first I had something like the following in the view.
Copy code
cart.on("afterAddLine", function() {
    // do something
});
Then I tried moving it to the entry point and it triggers once, but then I try to pass an event to the view and again it is triggered 3 times. In the Entry Point I have the following.
Copy code
cart.on("afterAddLine", function() {
    Backbone.trigger("change:total_weight");
});
Then in the view I have the following.
Copy code
Backbone.on("change:total_weight", function() {
    self.calculateTotalWeight();
});
s
Typically either with something like _.debounce(), a promise or some of sort global flag that gets set to true after the first call
1
IIRC something like _.once() doesn’t work, but you could try that too
m
I did try
Backbone.once
and it still triggers 3 times, but not
_.once()
.