https://github.com/nerdbeere/simpledi-async
https://github.com/nerdbeere/simpledi-async
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nerdbeere/simpledi-async
- Owner: nerdbeere
- Created: 2015-09-04T06:36:58.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-09-04T07:19:58.000Z (almost 11 years ago)
- Last Synced: 2025-10-04T23:34:56.920Z (8 months ago)
- Size: 258 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# simpledi-async
## API
### `di.get(name)`
Synchronously resolves dependencies.
**Warning:** There can't be any async dependencies in the chain. If an async dependency is detected it will throw an error.
#### Example:
```javascript
var myConfig = di.get('myConfig');
```
### `di.get(name, callback)`
Asynchronously resolves dependencies.
#### Example:
```javascript
di.get('myConfigFromCdn', function(error, config) {
// do something with config
});
```
### `di.register(name, function)`
### `di.registerAsync(name, function)`
#### Example:
```javascript
// Example: sync
di.register('myConfig', function() {
return {
config: true
}
});
// Example: async
di.registerAsync('myConfig', function(done) {
xhr('http//config.js', done)
});
```
### `di.register(name, dependencies, function)`
### `di.registerAsync(name, dependencies, function)`
#### Example:
```javascript
// Example: sync
di.register('myConfig', ['otherConfig'], function(otherConfig) {
return {
otherConfig: otherConfig
config: true
}
});
// Example: async
di.registerAsync('myConfig', ['cdnUrl'], function(cdnUrl, done) {
xhr(cdnUrl + '/config.js', done)
});
```