I was just about to offer my thoughts and they were very similar. With “eventing” the parent now has to listen for the event. But I think I like that. This allows parent components to subscribe to “inserted type” events of the subcomponents that it cares about. This does create a coupling in the fact that unless bit-tabs is listening for bit-panel’s inserted event, it won’t know anything about them. However, on the flip side, calling “addPanel” from bit-panel requires bit-panel to know that there is (or should be) a parent component that exposes the “addPanel” interface. Either way, one component needs to be aware in some sense the other should be out there.
“addPanel” would still be on the viewModel keeping it easy to test. The only part in the “events” object is listening for the event and calling addPanel.
Here’s a quick example of walking the parent viewModels:
var findParentViewModelWithFn = function(el, fnName) { while(el.parent().length) { if(el.parent().viewModel && el.parent().viewModel()[fnName]) { return el.parent().viewModel(); } el = el.parent(); } return undefined; };