, , Pub/Sub.
, View, .
For example, PubSub.subscribe("EVENT NAME", EVENT ACTIONS, CONDITION);in the condition function, you can check if everything is in the DOM.
i.e.
var unsubscribe = function() {
return (this.$el.closest("body").length === 0);
};
PubSub.subscribe("addSomething",_.bind(this.addSomething, this), unsubscribe);
Then you can call pub / sub through PubSub.pub("addSomething");in other places and not worry about duplicate actions.
There are trade-offs, of course, but it doesn't seem to be that difficult.
source
share