Created
February 3, 2014 08:23
-
-
Save andreypopp/8780442 to your computer and use it in GitHub Desktop.
Dependency injection DSL for JavaScript
This file contains 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
macro emitQuery { | |
case { _ $id:ident } => { | |
letstx $name = [makeValue(#{$id}[0].token.value, #{$id})]; | |
letstx $registry = [makeIdent('registry', #{$id})]; | |
return #{ var $id = $registry.query($name) } | |
} | |
} | |
macro inject { | |
case { _ $id:ident (,) ... { $body ...} } => { | |
return #{ | |
(function() { | |
$(emitQuery $id) (;) ... | |
$body ... | |
})() | |
} | |
} | |
} | |
var registry = require('registry'); | |
inject scope, http { | |
http.get('/', {query: scope.query}).then(render); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment