Communication between event design templates

event handlers are great if you have a view that references another view and listens for its events, which is ideal for decoupling and reuse.

the problem, although sometimes I have views that are not referenced, so I use the Event Aggregator, which is a global notification, to find out if something happened ... but it seems wrong when I just wanted to listen to children's views that I cannot reference, something like bubbling events in a DOM hierarchy.

but let me say that I have a view hierarchy, for example:

  • Parentview
    • Childview
      • Childview
        • Modalview

I wanted to know in ParentView when ModalView fires an event ... I cannot use the bubbling event because ModalView is not in the same DOM hierarchy, so should I use Event Agregator in this case or something else? I really wanted the event bubble to fit in my case.

+5
source share
1 answer

If you cannot use the DOM hierarchy and you do not want to use an event aggregator, my first instinct is that you need to create your own hierarchy in your views.

backbone.courier , .

Backbone.courier DOM , .

, DOM, , . DOM, .. , , : " ?".

ModalView ParentView parentView.listener(), ModalView. , ? ? , , , .

, . , :

modalView.container = parentView;

modalView.myEventHandler = function(e) {
    this.container.myEventHandler(e);
}
+2

All Articles