Skip to content

andyhmltn/grape-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grape.JS

Dead simple dependency injection!

Getting started

First declare your modules / dependencies

// Example

var hello = function() { alert('hello') }
var world = function() { alert('world') }

// This won't be used
var unused = function() { return ':(' }

Then you can declare a new Grape instance. It takes an object as the only argument. The keys relate to the names of the parameters you want to use and the values are the dependency those parameters relate to:

dependency = new Grape({
  '$main':hello,
  '$secondary':world,
  '$unused':unused
})

Now you can declare the function you want to be injected:

var my_callback = function($secondary, $main) {
  $secondary() //=> alert: world
  $main() //=> alert: hello
}

Then, when you want to run that function you call Grape.inject on the dependency instance you created above:

dependency.inject(my_callback)

Contributing

First, make sure you have installed the node modules using npm install. Then, to test run npm test or to compile a new version of Grape run gulp scripts

About

Dead simple dependency injection

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published