Skip to content

Instantly share code, notes, and snippets.

@97jaz
Last active August 29, 2015 14:00
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 97jaz/11010512 to your computer and use it in GitHub Desktop.
Save 97jaz/11010512 to your computer and use it in GitHub Desktop.
# So, ideally I would replace boilerplate like:
$scope = $ctrl = null
beforeEach inject ($injector) ->
$scope = $injector.get("$rootScope")
$ctrl = $injector.get("$controller")
# ... with something like:
beforeEach injected("$rootScope", "$controller")
##################
## Ah, no -- sorry. The results here need to be bound outside of the beforeEach scope,
## so it would actually be something like:
injectBefore "$rootScope", "$controller"
##################
# However, since the output needs to be bound locally, this is impossible without (unhygienic) macros or
# lexical eval. (Lexical eval is evil, but it might actually work here...)
# Alternatively, I would replace the boilerplate with:
beforeEach -> [$scope, $ctrl] = injected("$rootScope", "$controller")
# ... where the issue is getting `injected` into the lexical environment.
# That requires either lexical eval or taking advantage of the fact that the
# global object (window) rather unfortunately serves as a kind of catch-all
# for the top of the lexical scope chain.
# Anyhow, it's clear that I *can* get at least the second of these two work,
# but I'm fairly convinced that it will require one of two unsavory options.
# The better way to do this would be to use a module system.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment