1.0.3 • Published 10 years ago

pop-it v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
10 years ago

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.

npm.io

License

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

1.0.3

10 years ago

1.0.2

10 years ago

1.0.0

10 years ago