Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bottlejs

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bottlejs - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

LICENSE

52

dist/bottle.js
;(function(undefined) {
'use strict';
/**
* BottleJS v0.2.0 - 2014-09-28
* BottleJS v0.3.0 - 2014-10-01
* A powerful, extensible dependency injection micro container

@@ -42,24 +42,12 @@ *

/**
* Register a factory inside a generic provider.
* Map of decorator by index => name
*
* @param String name
* @param Function Factory
* @return Bottle
*/
var factory = function factory(name, Factory) {
return provider.call(this, name, function GenericProvider() {
this.$get = Factory;
});
};
/**
* Map of middleware by index => name
*
* @type Object
*/
var middles = [];
var decorators = [];
var getMiddleware = function getMiddleware(id, name) {
var group = middles[id];
var getDecorators = function getDecorators(id, name) {
var group = decorators[id];
if (!group) {
group = middles[id] = {};
group = decorators[id] = {};
}

@@ -73,3 +61,3 @@ if (!group[name]) {

/**
* Register middleware.
* Register decorator.
*

@@ -80,3 +68,3 @@ * @param String name

*/
var middleware = function middleware(name, func) {
var decorator = function decorator(name, func) {
if (typeof name === 'function') {

@@ -86,6 +74,18 @@ func = name;

}
getMiddleware(this.id, name).push(func);
getDecorators(this.id, name).push(func);
return this;
};
/**
* Register a factory inside a generic provider.
*
* @param String name
* @param Function Factory
* @return Bottle
*/
var factory = function factory(name, Factory) {
return provider.call(this, name, function GenericProvider() {
this.$get = Factory;
});
};
/**
* Map of provider constructors by index => name

@@ -105,3 +105,3 @@ *

/**
* Used to process middleware in the provider
* Used to process decorators in the provider
*

@@ -159,5 +159,5 @@ * @param Object instance

// filter through middleware
instance = getMiddleware(id, '__global__')
.concat(getMiddleware(id, name))
// filter through decorators
instance = getDecorators(id, '__global__')
.concat(getDecorators(id, name))
.reduce(reducer, instance);

@@ -239,3 +239,3 @@

factory : factory,
middleware : middleware,
decorator : decorator,
provider : provider,

@@ -242,0 +242,0 @@ service : service,

{
"name": "bottlejs",
"version": "0.2.0",
"version": "0.3.0",
"description": "A powerful, extensible dependency injection micro container",

@@ -5,0 +5,0 @@ "main": "dist/bottle.js",

@@ -9,3 +9,3 @@

BottleJS is a tiny yet powerful dependency injection container. It features lazy loading, middleware hooks, and a clean api inspired by the [AngularJS Module API](https://docs.angularjs.org/api/ng/type/angular.Module) and the simple PHP library [Pimple](http://pimple.sensiolabs.org/). You'll like BottleJS if you enjoy:
BottleJS is a tiny yet powerful dependency injection container. It features lazy loading, middleware hooks, decorators and a clean api inspired by the [AngularJS Module API](https://docs.angularjs.org/api/ng/type/angular.Module) and the simple PHP library [Pimple](http://pimple.sensiolabs.org/). You'll like BottleJS if you enjoy:

@@ -135,5 +135,5 @@ * building a stack from components rather than a kitchen-sink framework.

## Middleware
## Decorators
Bottle supports injecting middleware into the provider pipeline with the `Bottle#middleware` method. Bottle middleware are just simple functions that intercept a service in the provider phase after it has been created, but before it is accessed for the first time. The function should return the service, or another object to be used as the service instead.
Bottle supports injecting decorators into the provider pipeline with the `Bottle#decorator` method. Bottle decorators are just simple functions that intercept a service in the provider phase after it has been created, but before it is accessed for the first time. The function should return the service, or another object to be used as the service instead.

@@ -144,4 +144,4 @@ ```js

bottle.service('Wine', Wine);
bottle.middleware(function(service) {
// this middleware will be run for both Beer and Wine services.
bottle.decorator(function(service) {
// this decorator will be run for both Beer and Wine services.
service.stayCold();

@@ -151,4 +151,4 @@ return service;

bottle.middleware('Wine', function(wine) {
// this middleware will only affect the Wine service.
bottle.decorator('Wine', function(wine) {
// this decorator will only affect the Wine service.
wine.unCork();

@@ -170,2 +170,11 @@ return wine;

### decorator(name, func)
Used to register a decorator function that the provider will use to modify your services at creation time.
Param | Type | Details
:--------------------------|:-----------|:--------
**name**<br />*(optional)* | *String* | The name of the service this decorator will affect. Will run for all services if not passed.
**func** | *Function* | A function that will accept the service as the first parameter. Should return the service, or a new object to be used as the service.
### factory(name, Factory)

@@ -180,11 +189,2 @@

### middleware(name, func)
Used to register a middleware function that the provider will use to modify your services at creation time.
Param | Type | Details
:--------------------------|:-----------|:--------
**name**<br />*(optional)* | *String* | The name of the service this middleware will affect. Will run for all services if not passed.
**func** | *Function* | A function that will accept the service as the first parameter. Should return the service, or a new object to be used as the service.
### provider(name, Provider)

@@ -191,0 +191,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc