I want my main module to offer an api which allows any directive, controller, factory, etc. to register a function to be called when a user resizes a div.
Right now I'm successfully doing this by using jQuery's resizable
callback to update x and y variables on scope then calling $apply()
. The problem, as you can imagine, is that when a user is dragging a div, it calls the resize callback very rapidly. Rapidly calling $apply() isn't ideal for performance reasons.
I thought about using a service/factory, but there's an indeterminate number of resizable divs/directives and I'm not sure a singleton makes sense here.
Is there a way I can create an "informal" API that doesn't use $scope, doesn't trigger digest cycles, and doesn't use additional libraries? Perhaps there's a way using controllers and require: ^myCtrl
? Do I need to store all the registered callback functions in an array?