Skip to content

stephenplusplus/pop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pop-it

Angular-style Dependency Injection for Node.js & the browser.

Angular-y DI is fun.

So, "inject" some fun into your app.

Node.js
$ npm install --save pop-it
var pop = require('pop-it');

pop('aPoppy', 'This is it!');

pop(function (aPoppy) {
  // aPoppy = 'This is it!'
})();
The Browser
<script src="pop-it/browser.js"></script>
pop('shoop', 'a-doop');

pop(function (shoop) {
  // shoop = 'a-doop'
})();

Register a dependency (internally known as a poppy)

A poppy can be any value.

// Num nums.
pop('num', 3);

// Stringilings.
pop('str', 'String!');

// Funkadunks.
pop('fn', function () {
  return this;
}, { optional: 'context' });

Execute a poppy

Assume we registered the above dependencies.

pop(function (num, str, fn) {
  // num = 3
  // str = 'String!'
  // fn() = { optional: 'context' }
})();

Poppies are executed lazily, so your ordering isn't super important. Watch how we register a popped function to a poppy.

// register "b" with the value of a lazily-executed popped function.
pop('b', pop(function (a) {
  return a;
}));

pop('a', 'a');

pop(function (b) {
  // b() = 'a'
})();

Pop to the It.

License

Copyright (c) 2014 Stephen Sawchuk. Licensed under the MIT license.

About

Angular-style Dependency Injection for Node.js & the browser. Somebody had to do it.

Resources

License

Stars

Watchers

Forks

Packages

No packages published