stash
stash is an angularjs-style dependency injection framework for JavaScript that makes it easy to define modules, singletons and constants. All dependencies are resolved on demand, freeing you from loading your code in any particular order.
This project was ported from "lukevenediger/dingu" to TypeScript as one of my side projects while learning TypeScript. It is a great framework!
Features
- Bring in dependencies simply by naming them as a function parameter
- Load your javascript files in any arbitrary order
- Store singleton instances
- Store constant values like settings and magic numbers
- Protects against circular dependencies
- Can be locked to prevent further changes at runtime.
How It Works
Example 1: ModuleA depends on ModuleB
rnStash; rnStash;
Next we'll ask stash for an instance of ModuleA and call the doSomething method.
var a = rnStash;console;
Example 2: Using Singletons
stash lets you define a module that will only initialise once, and always return the same instance back. Any dependencies it needs will be resolved and injected the first time it's created.
rnStash; console; // trueconsole; // true
Example 3: Storing Constant Values
Use stash to store settings, magic numbers and other common values and include them in your modules by name.
// Store a stringrnStashvalue'apiUrl' 'http://foo.com/api'; // or an object - stash isn't fussyrnStashvalue'systemInfo' apiVersion: '1.2' token: 'aab23510' ; // And then have them ready in your modulernStash;
Download and Install
There are many ways to get stash:
- Download stash.js
- Install it via npm -
npm install rn-stash
Project Information
Maintainers:
- Richard Niemand - niemand.richard@gmail.com
Original Code / Developer:
- Luke Venediger - lukev@lukev.net (original lukevenediger/dingu on GitHub)
License:
- MIT