Concept of "Active" Controller


#1

Hi, Taking the same abstraction from Desktop framework, I’m wondering if there’s a thought about modeling “Activeness”.

For example, say I have a composite application with these views, sketched as a hierarchical tree here to represent the view hierarchy:

  • Main container
    • Post
      • Search Area
        • Search Box
        • Search Results
    • Navbar
      • Site search

Now, obviously, when I set the Search Area as active, I want the Search Box to get focus.

When I set the Post as active, I want the Search Box to be active again.

When I set the main app as active, I want Site search to get focus.

So, there’s a concept of hierarchical ‘Activeness’ here, that determines who in the current sub-hierarchy should get focus once a parent is selected.

I’m doing this manually at the moment by maintaining an “isActive” flag in every controller, and the couple of methods “controller#activate”, “controller#deactivate”. The view hierarchy will resolve itself because I will manually set a function to observe this, in every view that I think needs the focus (this view will also be responsible to deactivate the controller - yuck).

But it does scream abstraction for me.

Any insights? anyone already doing this?

Thanks