Created
December 3, 2013 21:16
-
-
Save jasonkarns/7777633 to your computer and use it in GitHub Desktop.
Inverse _.partial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# we have an event aggregator that is treated as an adapter to hide | |
# whatever eventing lib/framework/utility we decide to use | |
# | |
# originally, it was backed by Backbone.Events. Now it's Angular's $rootScope | |
# | |
# `on` accepts a callback that expects to be given event args. (as backbone.events does) | |
# | |
# Angular's $on, on the other hand, accepts a callback that expects | |
# $scope as the first param, followed by event args. | |
# Below, our implementation just works around it by essentially wrapping the | |
# callback in another function that separates `scope` from the rest of the event args. | |
# | |
# This is done by splatting args[1]..args[n], and then just apply-ing them to the original handler | |
# | |
# This could probably be wrapped up as a utility function implemented using _.wrap | |
class Dispatcher | |
on: (eventName, handler, context) -> | |
@scope.$on eventName, (scope, args...) -> | |
handler.apply context, args | |
#... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment