Comparing version 1.5.0 to 1.6.0
declare class Bottle { | ||
static pop: (name?: string) => Bottle; | ||
static clear: (name?: string) => void; | ||
static list: (container?: Bottle.IContainer) => Array<string>; | ||
static config: Object; | ||
@@ -62,2 +63,7 @@ | ||
/** | ||
* Reset providers on the bottle instance. | ||
*/ | ||
resetProviders(): void; | ||
/** | ||
* Register a service, factory, provider, or value based on properties of the Obj. | ||
@@ -95,2 +101,3 @@ */ | ||
interface IContainer { | ||
$decorator(name: string|((service: any) => any), func?: (service: any) => any): this; | ||
$register(Obj: Bottle.IRegisterableObject): this; | ||
@@ -97,0 +104,0 @@ $list(container?: Bottle.IContainer): Array<string>; |
;(function(undefined) { | ||
'use strict'; | ||
/** | ||
* BottleJS v1.5.0 - 2016-10-14 | ||
* BottleJS v1.6.0 - 2017-02-22 | ||
* A powerful dependency injection micro container | ||
* | ||
* Copyright (c) 2016 Stephen Young | ||
* Copyright (c) 2017 Stephen Young | ||
* Licensed MIT | ||
@@ -169,3 +169,3 @@ */ | ||
var byMethod = function byMethod(name) { | ||
return !/^\$(?:register|list)$|Provider$/.test(name); | ||
return !/^\$(?:decorator|register|list)$|Provider$/.test(name); | ||
}; | ||
@@ -266,3 +266,3 @@ | ||
var instance; | ||
if (name) { | ||
if (typeof name === 'string') { | ||
instance = bottles[name]; | ||
@@ -282,3 +282,3 @@ if (!instance) { | ||
var clear = function clear(name) { | ||
if (name) { | ||
if (typeof name === 'string') { | ||
delete bottles[name]; | ||
@@ -314,2 +314,3 @@ } else { | ||
} | ||
this.originalProviders[fullname] = Provider; | ||
this.providerMap[fullname] = true; | ||
@@ -338,3 +339,2 @@ | ||
* | ||
* @param String fullname | ||
* @param String name | ||
@@ -425,4 +425,34 @@ * @param Function Provider | ||
/** | ||
* Deletes providers from the map and container. | ||
* | ||
* @param String name | ||
* @return void | ||
*/ | ||
var removeProviderMap = function resetProvider(name) { | ||
delete this.providerMap[name]; | ||
delete this.container[name]; | ||
delete this.container[name + 'Provider']; | ||
}; | ||
/** | ||
* Resets all providers on a bottle instance. | ||
* | ||
* @return void | ||
*/ | ||
var resetProviders = function resetProviders() { | ||
var providers = this.originalProviders; | ||
Object.keys(this.originalProviders).forEach(function resetPrvider(provider) { | ||
var parts = provider.split('.'); | ||
if (parts.length > 1) { | ||
removeProviderMap.call(this, parts[0]); | ||
parts.forEach(removeProviderMap, getNestedBottle.call(this, parts[0])); | ||
} | ||
removeProviderMap.call(this, provider); | ||
this.provider(provider, providers[provider]); | ||
}, this); | ||
}; | ||
/** | ||
* Execute any deferred functions | ||
@@ -525,4 +555,6 @@ * | ||
this.providerMap = {}; | ||
this.originalProviders = {}; | ||
this.deferred = []; | ||
this.container = { | ||
$decorator : decorator.bind(this), | ||
$register : register.bind(this), | ||
@@ -546,2 +578,3 @@ $list : list.bind(this) | ||
provider : provider, | ||
resetProviders : resetProviders, | ||
register : register, | ||
@@ -548,0 +581,0 @@ resolve : resolve, |
{ | ||
"name": "bottlejs", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "A powerful dependency injection micro container", | ||
@@ -32,3 +32,3 @@ "main": "dist/bottle.js", | ||
"grunt-contrib-concat": "^0.5.0", | ||
"grunt-contrib-jasmine": "^0.7.0", | ||
"grunt-contrib-jasmine": "^1.0.3", | ||
"grunt-contrib-jshint": "^0.10.0", | ||
@@ -35,0 +35,0 @@ "grunt-contrib-uglify": "^0.5.1", |
@@ -44,4 +44,5 @@ | ||
```html | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/bottlejs/1.4.0/bottle.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/bottlejs/VERSION/bottle.min.js"></script> | ||
``` | ||
Replace `VERSION` in the above URL with a valid BottleJS version, e.g. `https://cdnjs.cloudflare.com/ajax/libs/bottlejs/1.5.0/bottle.min.js` | ||
@@ -308,4 +309,5 @@ ## Simple Example | ||
#### decorator(name, func) | ||
#### container.$decorator(name, func) | ||
Used to register a decorator function that the provider will use to modify your services at creation time. | ||
Used to register a decorator function that the provider will use to modify your services at creation time. `bottle.container.$decorator` is an alias of `bottle.decorator`; this allows you to only add a decorator to a nested bottle. | ||
@@ -385,2 +387,6 @@ Param | Type | Details | ||
#### resetProviders() | ||
Used to reset all containers for the next reference to reinstantiate the provider. | ||
#### register(Obj) | ||
@@ -387,0 +393,0 @@ #### container.$register(Obj) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43698
680
430