Skip to content

Instantly share code, notes, and snippets.

@justinbmeyer
Created October 14, 2011 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinbmeyer/1286230 to your computer and use it in GitHub Desktop.
Save justinbmeyer/1286230 to your computer and use it in GitHub Desktop.
What I would like

Background

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment