1 Reply Latest reply on May 28, 2007 4:34 PM by peterent

    Event Bubbling Between Components - the best approach?

    fuzzarooO Level 1
      Hi, Been doing some research and was wondering if event bubbling is in fact the best approach to communicating between two components? I notice that even though Bindable public variables in components may not be the best approach, it does get the job done. The only problem is components need to know about each other and that is a no-no. Components shouldn't know about each other.

      so if I'm event bubbling, I've seen it as going up and down the ladder such as:


      but what if my project is constructed like this?

      -B -C

      and I need component B to communicate to component C? How does the event bubbling work in terms of where does the meta data, function definition, and such belong?

      any links or advice to get me started on event bubbling would be very appreciated.
        • 1. Re: Event Bubbling Between Components - the best approach?
          peterent Level 2
          Suppose component B dispatches an event, "action". You could do this in component A since it knows about both B and C:

          <C id="compC" ... />
          <B action="compC.fromB(event)" ... />

          You write a public function (or property) on component C that accepts an event or value. You could also do this:

          <C id="compC" fromB="{compB.value}" />
          <B id="compB" />

          If B.value is a public and Bindable variable or property, compC can just bind its public property, fromB, to that. Both methods work fine and don't break any "rules" - B doesn't know about C and C just has a public property that can be set from any component.