Comparing version 1.0.1 to 1.1.0
;(function(undefined) { | ||
'use strict'; | ||
/** | ||
* BottleJS v1.0.1 - 2015-10-05 | ||
* BottleJS v1.1.0 - 2015-11-09 | ||
* A powerful dependency injection micro container | ||
@@ -233,3 +233,6 @@ * | ||
var index = 0; | ||
var next = function nextMiddleware() { | ||
var next = function nextMiddleware(err) { | ||
if (err) { | ||
throw err; | ||
} | ||
if (middleware[index]) { | ||
@@ -425,2 +428,6 @@ middleware[index++](instance, next); | ||
* * Obj.$inject Mixed optional only useful with $type 'service' name or array of names | ||
* * Obj.$value Mixed optional Normally Obj is registered on the container. However, if this | ||
* property is included, it's value will be registered on the container | ||
* instead of the object itsself. Useful for registering objects on the | ||
* bottle container without modifying those objects with bottle specific keys. | ||
* | ||
@@ -431,3 +438,4 @@ * @param Function Obj | ||
var register = function register(Obj) { | ||
return this[Obj.$type || 'service'].apply(this, [Obj.$name, Obj].concat(Obj.$inject || [])); | ||
var value = Obj.$value === undefined ? Obj : Obj.$value; | ||
return this[Obj.$type || 'service'].apply(this, [Obj.$name, value].concat(Obj.$inject || [])); | ||
}; | ||
@@ -434,0 +442,0 @@ |
{ | ||
"name": "bottlejs", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A powerful dependency injection micro container", | ||
@@ -5,0 +5,0 @@ "main": "dist/bottle.js", |
@@ -175,2 +175,17 @@ | ||
Middleware can pass an error object to the `next` function, and bottle will throw the error: | ||
```js | ||
var bottle = new Bottle(); | ||
bottle.service('Beer', Beer); | ||
bottle.middleware('Beer', function(beer, next) { | ||
if (beer.hasGoneBad()) { | ||
return next(new Error('The Beer has gone bad!')); | ||
} | ||
next(); | ||
}); | ||
// results in Uncaught Error: The Beer has gone bad!(…) | ||
``` | ||
## Nested Bottles | ||
@@ -252,3 +267,3 @@ 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: | ||
**name**<br />*(optional)* | *String* | The name of the service for which this middleware will be called. Will run for all services if not passed. | ||
**func** | *Function* | A function that will accept the service as the first parameter, and a `next` function as the second parameter. Should execute `next()` to allow other middleware in the stack to execute. | ||
**func** | *Function* | A function that will accept the service as the first parameter, and a `next` function as the second parameter. Should execute `next()` to allow other middleware in the stack to execute. Bottle will throw anything passed to the `next` function, i.e. `next(new Error('error msg'))`. | ||
@@ -271,3 +286,3 @@ #### provider(name, Provider) | ||
:-------|:-----------|:-------- | ||
**Obj** | *Object*\|*Function* | An object or constructor with one of several properties:<br /><ul><li>**Obj.$name** — *required* — the name used to register the object</li><li>**Obj.$type** — *optional* — the method used to register the object. Defaults to `'service'` in which case the Obj will be treated as a constructor. Valid types are: `'service'`, `'factory'`, `'provider'`, `'value'`</li><li>**Obj.$inject** — *optional* — If `Obj.$type` is `'service'`, this property can be a string name or an array of names of dependencies to inject into the constructor.<br />E.g. `Obj.$inject = ['dep1', 'dep2'];`</li></ul> | ||
**Obj** | *Object*\|*Function* | An object or constructor with one of several properties:<br /><ul><li>**Obj.$name** — *required* — the name used to register the object</li><li>**Obj.$type** — *optional* — the method used to register the object. Defaults to `'service'` in which case the Obj will be treated as a constructor. Valid types are: `'service'`, `'factory'`, `'provider'`, `'value'`</li><li>**Obj.$inject** — *optional* — If `Obj.$type` is `'service'`, this property can be a string name or an array of names of dependencies to inject into the constructor.<br />E.g. `Obj.$inject = ['dep1', 'dep2'];`</li><li>**Obj.$value** — *optional* — Normally Obj is registered on the container. However, if this property is included, it's value will be registered on the container instead of the object itself. Useful for registering objects on the bottle container without modifying those objects with bottle specific keys.</li></ul> | ||
@@ -274,0 +289,0 @@ #### resolve(data) |
32610
556
312