Controller is really an event manager, it lets you listen to objects and when destroyed, automatically unbinds all event handlers.
It lets you listen to events on objects in the window like:
Foo.Bar = new SomethingThatMakesEvents();
$.Controller('FooListener',{
"{Foo.Bar} eventName" : function(){
}
})
The problem is that with AMD-style loading, you are getting passed Foo.Bar
, it's not somewhere we can look up, so the following is impossible:
steal('foo/bar', function(Bar){
$.Controller('FooListener',{
"{Bar} eventName" : function(){
}
})
})
Leaving users to do:
steal('foo/bar', function(Bar){
$.Controller('FooListener',{
init : function(){
this.bind(Bar, "eventName", "onEventName")
},
onEventName : function(){ ... }
})
})
I'd like to get rid of that, but it's impossible without accessing a function's closure 'stack' and within each stack, the variables present.
Granted, calling bind isn't hard or unnatural, it just seems like something I should be able to do.