Skip to content

Commit

Permalink
Merge pull request #45 from young-steveo/release-1.2.2
Browse files Browse the repository at this point in the history
Release 1.2.2
  • Loading branch information
young-steveo committed Feb 12, 2016
2 parents 9ee40b7 + 88910cc commit 6f0ac0a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ Param | Type | Details
:--------------------------|:-----------|:--------
**name**<br />*(optional)* | *String* | The name of the bottle. If passed, bottle will store the instance internally and return the same instance if `Bottle.pop` is subsequently called with the same name.

#### config

A global configuration object.

Property | Type | Default | Details
:----------|:----------|:--------|:--------
**strict** | *Boolean* | `false` | Enables strict mode. Currently only verifies that automatically injected dependencies are not undefined.

### Bottle.prototype

#### constant(name, value)
Expand Down Expand Up @@ -279,6 +287,8 @@ Param | Type | Details

Used to register a service, factory, provider, or value based on properties of the Obj. `bottle.container.$register` is an alias of `bottle.register`; this allows factories and providers to register multiple services on the container without needing access to the bottle instance itself.

If `Bottle.config.strict` is set to `true`, this method will throw an error if an injected dependency is `undefined`.

Param | Type | Details
:-------|:-----------|:--------
**Obj** | *Object*\|*Function* | An object or constructor with one of several properties:<br /><ul><li>**Obj.$name** &mdash; *required* &mdash; the name used to register the object</li><li>**Obj.$type** &mdash; *optional* &mdash; 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** &mdash; *optional* &mdash; 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** &mdash; *optional* &mdash; 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>
Expand All @@ -293,7 +303,7 @@ Param | Type | Details

#### service(name, Constructor [, dependency [, ...]])

Used to register a service constructor
Used to register a service constructor. If `Bottle.config.strict` is set to `true`, this method will throw an error if an injected dependency is `undefined`.

Param | Type | Details
:--------------------------------|:-----------|:--------
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.2.1",
"version": "1.2.2",
"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": {}
}
}
21 changes: 18 additions & 3 deletions dist/bottle.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
;(function(undefined) {
'use strict';
/**
* BottleJS v1.2.1 - 2015-12-14
* BottleJS v1.2.2 - 2016-02-12
* A powerful dependency injection micro container
*
* Copyright (c) 2015 Stephen Young
* Copyright (c) 2016 Stephen Young
* Licensed MIT
*/

Expand Down Expand Up @@ -88,12 +88,20 @@
/**
* Iterator used to walk down a nested object.
*
* If Bottle.config.strict is true, this method will throw an exception if it encounters an
* undefined path
*
* @param Object obj
* @param String prop
* @return mixed
* @throws
*/
var getNested = function getNested(obj, prop) {
return obj[prop];
var service = obj[prop];
if (service === undefined && globalConfig.strict) {
throw new Error('Bottle was unable to resolve a service. `' + prop + '` is undefined.');
}
return service;
};

/**
Expand Down Expand Up @@ -554,6 +562,13 @@
*/
Bottle.pop = pop;

/**
* Global config
*/
var globalConfig = Bottle.config = {
strict : false
};

/**
* Exports script adapted from lodash v2.4.1 Modern Build
*
Expand Down
6 changes: 3 additions & 3 deletions dist/bottle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6f0ac0a

Please sign in to comment.