This project uses BackboneJS with BackboneLayout.
There is a rather complex hierarchy of views - four to five levels deep in some cases.
I have a situation where I would like one view to trigger a change in another view, but listeners are not an option. (results in too many listeners, kills memory).
Top -> X -> Y
Top -> B -> C -> D -> E
Top
is the top level view, which has one X
view , which has multiple Y
views.
Top
view also contains one B
view, which contain multiple B
views, each of which contain multiple C
views, each of which contain multiple D
views, each of which contain multiple E
views.
A change in a Y
view needs to affect all E
views that are presently rendered. This would be perfect for listeners, if not for the problem mentioned earlier. Thus I am looking for an alternative way to accomplish the same thing.
I am thinking of getting the Top
view to find all of its children that are of type E
, or something along those lines. Other solutions are welcome too.
Thanks.
Yeah, I'd have
Top
maintain a list of allE
instances - this would just be something in application code, might be inE.initialize()
, or via your own methods for adding/removing nodes in your view heirarchy, if you have them - and it's own event handler that listens forchange
events on all Ys, and re-renders theE
s. If it's prohibitively expensive to listen toY
changes, trigger a customY-change
(or whatever) event on yourTop
from your application code inY
, and have Top listen to that event instead.It's very easy to have the list of E instances get out of sync, but, well, that's why listeners exist. Tread carefully and make sure Top has hooks into every point down the
B->C->D->E
tree and knows what changes to make to it's (essentially denormalized) list ofE
's when there is a change.