Skip to content

Commit 41daea0

Browse files
authored
Merge pull request #66 from young-steveo/release-1.5.0
Release 1.5.0
2 parents b39172a + c6efbea commit 41daea0

7 files changed

Lines changed: 155 additions & 156 deletions

File tree

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ $ bower install bottlejs
3838
$ npm install bottlejs
3939
```
4040

41+
BottleJS is also available on cdnjs:
42+
43+
```html
44+
<script src="https://cdnjs.cloudflare.com/ajax/libs/bottlejs/1.4.0/bottle.min.js"></script>
45+
```
46+
4147
## Simple Example
4248

4349
The simplest recipe to get started with is `Bottle#service`. Say you have a constructor for a service object:
@@ -196,14 +202,32 @@ bottle.middleware('Beer', function(beer, next) {
196202
```
197203

198204
## Nested Bottles
199-
Bottle will generate nested containers if dot notation is used in the service name. A sub container will be created for you based on the name given:
205+
Bottle will generate nested containers if dot notation is used in the service name. An isolated sub container will be created for you based on the name given:
200206

201207
```js
202208
var bottle = new Bottle();
203209
var IPA = function() {};
204210
bottle.service('Beer.IPA', IPA);
205211
bottle.container.Beer; // this is a new Bottle.container object
206212
bottle.container.Beer.IPA; // the service
213+
bottle.factory('Beer.DoubleIPA', function (container) {
214+
var IPA = container.IPA; // note the container in here is the nearest parent.
215+
})
216+
```
217+
218+
### Nested Containers Are Isolated
219+
Nested containers are designed to provide isolation between different packages. This means that you cannot access a nested container from a different parent when you are writing a factory.
220+
221+
```js
222+
var bottle = new Bottle();
223+
var IPA = function() {};
224+
var Wort = function() {};
225+
bottle.service('Ingredients.Wort', Wort);
226+
bottle.factory('Beer.IPA', function(container) {
227+
// container is `Beer`, not the root, so:
228+
container.Wort; // undefined
229+
container.Ingredients.Wort; // undefined
230+
});
207231
```
208232

209233
## API
@@ -250,6 +274,26 @@ Property | Type | Default | Details
250274

251275
### Bottle.prototype
252276

277+
#### decorators
278+
279+
A collection of decorators registered by the bottle instance. See `decorator(name, func)` below
280+
281+
#### middlewares
282+
283+
A collection of middleware registered by the bottle instance. See `middleware(name, func)` below.
284+
285+
#### nested
286+
287+
A collection of nested bottles registered by the parent bottle instance when dot notation is used to define a service. See "Nested Bottles" section in the documentation above.
288+
289+
#### providerMap
290+
291+
A collection of registered provider names. Bottle uses this internally to determine whether a provider has already instantiated it's instance. See `provider(name, Provider)` below.
292+
293+
#### deferred
294+
295+
An array of deferred functions registered for this bottle instance. See `defer(func)` below.
296+
253297
#### constant(name, value)
254298

255299
Used to add a read only value to the container.

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bottlejs",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"description": "A powerful dependency injection micro container",
55
"main": "dist/bottle.min.js",
66
"license": "MIT",
@@ -38,4 +38,4 @@
3838
"private": false,
3939
"dependencies": {},
4040
"devDependencies": {}
41-
}
41+
}

dist/bottle.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
declare class Bottle {
2-
static pop: (name?: string) => Bottle
2+
static pop: (name?: string) => Bottle;
3+
static clear: (name?: string) => void;
34
static config: Object;
45

56
public container: Bottle.IContainer;
7+
public decorators: Object;
8+
public middlewares: Object;
9+
public nested: Object;
10+
public providerMap: Object;
11+
public deferred: Array<(data: any) => any>;
612

713
constructor(name?: string);
814

@@ -39,7 +45,7 @@ declare class Bottle {
3945
/**
4046
* List the services registered on the container
4147
*/
42-
list(container?: Bottle.IContainer): Array<string>;
48+
list(container?: Bottle.IContainer): Array<string>;
4349

4450
/**
4551
* Register a middleware function. This function will be executed every time the service is accessed.
@@ -86,5 +92,6 @@ declare module Bottle {
8692

8793
interface IContainer {
8894
$register(Obj: Bottle.IRegisterableObject): this;
95+
$list(container?: Bottle.IContainer): Array<string>;
8996
}
9097
}

0 commit comments

Comments
 (0)