angular-ui / AngularJS-StyleGuide

Example of scalable architecture for my NG-Conf 2014 talk
http://www.youtube.com/watch?v=Iw-3qgG_ipU
284 stars 53 forks source link

Common downStream Bus #7

Closed thomasstevens89 closed 9 years ago

thomasstevens89 commented 10 years ago

At the moment, new objects create their own upstream bus in the construct function which then gets merged/plugged in to the parent upstream bus. However all objects share the same downstream bus (initiated in the socket object and then passed along down through the collections).

Should we be creating a new downstream bus in the construct function of new objects also? That would allow us to filter only the relevant events and pass them into the child's own downstream bus.

ProLoser commented 10 years ago

Actually what I envisioned was that you would pass in a filtered version of the previous bus which is narrowed down to the events only relevant to that object. However, this would mean you'd be doing a filter check for each child in a collection of children, which is not very performant, even though the events would only continue down 1 of these children.

Refer to my recent thread here: https://groups.google.com/forum/#!topic/baconjs/uJg2U9xo20A

As you can see from that discussion, there is no current feature in bacon to handle checks and delegation in 1 place so as to reduce the redundant number of checks. With that in mind (and after talking to a coworker) a new solution was proposed that is closer to what you're describing:

Every object would create a new bus/stream and the parent object would perform a check in their stream and would push onto the relevant child stream.

marcfallows commented 10 years ago

With that approach, would you not plug the downStream (and therefore not pass it as a parameter to constructor), but instead specifically call the child's downStream.push()?

ProLoser commented 10 years ago

Actually YES! I started to recode my existing version based on that whole premise, but I got bored and stopped before I ended up committing it lol.

The best thing to do would add a whole lot of abstraction to the BaseObject that does it automagically but then you have to start doing like keeping track of what a class's children are, etc. But at the same time, you would no longer need to pass in the downstream during construction (except for maybe the socket to AppObject due to a circular dependency issue).

Feel free to submit a PR though lol.

ProLoser commented 9 years ago

Removed the socket stuff