Code Monkey home page Code Monkey logo

grape-js's Introduction

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

grape-js's People

Contributors

andyhmltn avatar

Stargazers

Matt avatar April Johnson avatar jigsaw avatar Boris Serdiuk avatar  avatar Bobbie Tables avatar Marius avatar  avatar  avatar Octavio Turra avatar Jonas Hartmann avatar Pawel Kasperek avatar Carsten Woelk avatar Cem Turan avatar Stephen Rhyne avatar  avatar  avatar Thomas Gibson avatar Olivier Philippon avatar Shant Parseghian avatar Alexey Okhrimenko avatar Dmytro Voronianski avatar Akash Agrawal avatar Serge avatar  avatar Roger Mattos avatar Francisco Contel-Martins avatar Viktor Bezdek avatar Maciej Winnicki avatar Nina Kitsu avatar Fabrizio Fortunato avatar 김대근 avatar Aster Haven avatar Lucas avatar Flynn Martin avatar azu avatar Kemal Dağ avatar Michael avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.