Skip to content

Commit

Permalink
Merge pull request #66 from young-steveo/release-1.5.0
Browse files Browse the repository at this point in the history
Release 1.5.0
  • Loading branch information
young-steveo committed Oct 15, 2016
2 parents b39172a + c6efbea commit 41daea0
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 156 deletions.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ $ bower install bottlejs
$ npm install bottlejs
```

BottleJS is also available on cdnjs:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/bottlejs/1.4.0/bottle.min.js"></script>
```

## Simple Example

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

## Nested Bottles
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:
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:

```js
var bottle = new Bottle();
var IPA = function() {};
bottle.service('Beer.IPA', IPA);
bottle.container.Beer; // this is a new Bottle.container object
bottle.container.Beer.IPA; // the service
bottle.factory('Beer.DoubleIPA', function (container) {
var IPA = container.IPA; // note the container in here is the nearest parent.
})
```

### Nested Containers Are Isolated
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.

```js
var bottle = new Bottle();
var IPA = function() {};
var Wort = function() {};
bottle.service('Ingredients.Wort', Wort);
bottle.factory('Beer.IPA', function(container) {
// container is `Beer`, not the root, so:
container.Wort; // undefined
container.Ingredients.Wort; // undefined
});
```

## API
Expand Down Expand Up @@ -250,6 +274,26 @@ Property | Type | Default | Details

### Bottle.prototype

#### decorators

A collection of decorators registered by the bottle instance. See `decorator(name, func)` below

#### middlewares

A collection of middleware registered by the bottle instance. See `middleware(name, func)` below.

#### nested

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.

#### providerMap

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.

#### deferred

An array of deferred functions registered for this bottle instance. See `defer(func)` below.

#### constant(name, value)

Used to add a read only value to the container.
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bottlejs",
"version": "1.4.0",
"version": "1.5.0",
"description": "A powerful dependency injection micro container",
"main": "dist/bottle.min.js",
"license": "MIT",
Expand Down Expand Up @@ -38,4 +38,4 @@
"private": false,
"dependencies": {},
"devDependencies": {}
}
}
11 changes: 9 additions & 2 deletions dist/bottle.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
declare class Bottle {
static pop: (name?: string) => Bottle
static pop: (name?: string) => Bottle;
static clear: (name?: string) => void;
static config: Object;

public container: Bottle.IContainer;
public decorators: Object;
public middlewares: Object;
public nested: Object;
public providerMap: Object;
public deferred: Array<(data: any) => any>;

constructor(name?: string);

Expand Down Expand Up @@ -39,7 +45,7 @@ declare class Bottle {
/**
* List the services registered on the container
*/
list(container?: Bottle.IContainer): Array<string>;
list(container?: Bottle.IContainer): Array<string>;

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

interface IContainer {
$register(Obj: Bottle.IRegisterableObject): this;
$list(container?: Bottle.IContainer): Array<string>;
}
}
Loading

0 comments on commit 41daea0

Please sign in to comment.