ViewController companions
Opened this issue · 4 comments
Allow view controllers to share behavior with other view controllers.
This looks implemented in DeftJS5?
The logic I was building for Deft 0.9.x is there in the Deft 5 code, but I don't think it's going to work due to the way Ext 5 locates event listeners. Listeners are located by finding the "nearest" referenceHolder for the component (which would typically be the ViewController). That means additional handlers defined on the companion VCs would never be fired. I don't think there's a way around this without some serious mucking around with the underlying Ext 5 event system.
I noticed your implementation trying to understand how Deft integrates with the new Ext VCs. Was the idea that each controller would handle a behavior—like an EmailInputController
to apply uniform validation logic across more complicated views? I built PureMVC and RL extensions like that a few years ago that were very useful. I thought I saw an old PR for accepting multiple VCs though. How would companions differ?
The way I had it working in my 0.9.x feature branch was that you could basically associate additional view controllers with the "primary" view controller for a view. So additional logic and view event listeners could be attached, allowing common/cross-cutting logic to be shared. Since they remain encapsulated as separate view controllers, there was no danger of method names or anything else conflicting. It also meant that any view controller could act as either a primary VC or be attached as a companion VC.
It was actually a pretty cool design if I do say so myself. ;-)
Unfortunately, as I said, with the change to how listeners are handled in Ext 5, I think the whole idea has to be jettisoned. When we were actually setting up listeners on the view to trigger VC handler methods, this was fine. Now that Ext 5 uses event handlers that are located at the time the event fires by looking only for the first reference holder, I don't see any way to get event handler methods defined in the companion VCs to be invoked. :-/