pop

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

Module License: MIT

Added by: Sam Deering

GitHub

Repository

stephenplusplus/pop

Stats

Stars: 36

Watchers: 36

Forks: 2

Module Description

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.

Module stats last updated: 2017-06-15 16:00:06

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!