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.1.0 to 0.2.0

src/Bottle/middleware.js

2

bower.json
{
"name": "bottlejs",
"version": "0.1.0",
"version": "0.2.0",
"description": "A powerful, extensible dependency injection micro container",

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

;(function(undefined) {
'use strict';
/**
* BottleJS v0.1.0 - 2014-09-24
* BottleJS v0.2.0 - 2014-09-28
* A powerful, extensible dependency injection micro container

@@ -54,3 +54,3 @@ *

/**
* Map of middlewear by index => name
* Map of middleware by index => name
*

@@ -61,3 +61,3 @@ * @type Object

var getMiddlewear = function getMiddlewear(id, name) {
var getMiddleware = function getMiddleware(id, name) {
var group = middles[id];

@@ -74,3 +74,3 @@ if (!group) {

/**
* Register middlewear.
* Register middleware.
*

@@ -81,3 +81,3 @@ * @param String name

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

@@ -87,3 +87,3 @@ func = name;

}
getMiddlewear(this.id, name).push(func);
getMiddleware(this.id, name).push(func);
return this;

@@ -106,3 +106,3 @@ };

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

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

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

@@ -240,3 +240,3 @@

factory : factory,
middlewear : middlewear,
middleware : middleware,
provider : provider,

@@ -243,0 +243,0 @@ service : service,

/**
* BottleJS v0.1.0 - 2014-09-24
* BottleJS v0.2.0 - 2014-09-28
* A powerful, extensible dependency injection micro container

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

(function(){"use strict";var a=0,b=Array.prototype.slice,c=function(a,b){return Object.defineProperty(this.container,a,{configurable:!1,enumerable:!0,value:b,writable:!1}),this},d=function(a,b){return k.call(this,a,function(){this.$get=b})},e=[],f=function(a,b){var c=e[a];return c||(c=e[a]={}),c[b]||(c[b]=[]),c[b]},g=function(a,b){return"function"==typeof a&&(b=a,a="__global__"),f(this.id,a).push(b),this},h=[],i=function(a){return h[a]||(h[a]={}),h[a]},j=function(a,b){return b(a)},k=function(a,b){var c,d,e,g,h;return h=this.id,d=i(h),d[a]?void 0:(g=this.container,d[a]=b,c=a+"Provider",e=Object.create(null),e[c]={configurable:!0,enumerable:!0,get:function(){var b,e=d[a];return e&&(b=new e,delete g[c],g[c]=b),b}},e[a]={configurable:!0,enumerable:!0,get:function(){var b,d=g[c];return d&&(b=d.$get(g),b=f(h,"__global__").concat(f(h,a)).reduce(j,b),delete g[c],delete g[a],g[a]=b),b}},Object.defineProperties(g,e),this)},l=function(a){return this.container[a]},m=function(a,c){var e=arguments.length>2?b.call(arguments,1):null,f=this;return d.call(f,a,function(){return e&&(c=c.bind.apply(c,e.map(l,f))),new c})},n=function(a,b){return Object.defineProperty(this.container,a,{configurable:!0,enumerable:!0,value:b,writable:!0}),this},o=function q(){return this instanceof q?(this.id=a++,void(this.container={})):new q};o.prototype={constant:c,factory:d,middlewear:g,provider:k,service:m,value:n},o.pop=function(){return new o};var p={"function":!0,object:!0};!function(a){var b=p[typeof exports]&&exports&&!exports.nodeType&&exports,c=p[typeof module]&&module&&!module.nodeType&&module,d=c&&c.exports===b&&b,e=p[typeof global]&&global;!e||e.global!==e&&e.window!==e||(a=e),"function"==typeof define&&"object"==typeof define.amd&&define.amd?(a.Bottle=o,define(function(){return o})):b&&c?d?(c.exports=o).Bottle=o:b.Bottle=o:a.Bottle=o}(p[typeof window]&&window||this)}).call(this);
(function(){"use strict";var a=0,b=Array.prototype.slice,c=function(a,b){return Object.defineProperty(this.container,a,{configurable:!1,enumerable:!0,value:b,writable:!1}),this},d=function(a,b){return k.call(this,a,function(){this.$get=b})},e=[],f=function(a,b){var c=e[a];return c||(c=e[a]={}),c[b]||(c[b]=[]),c[b]},g=function(a,b){return"function"==typeof a&&(b=a,a="__global__"),f(this.id,a).push(b),this},h=[],i=function(a){return h[a]||(h[a]={}),h[a]},j=function(a,b){return b(a)},k=function(a,b){var c,d,e,g,h;return h=this.id,d=i(h),d[a]?void 0:(g=this.container,d[a]=b,c=a+"Provider",e=Object.create(null),e[c]={configurable:!0,enumerable:!0,get:function(){var b,e=d[a];return e&&(b=new e,delete g[c],g[c]=b),b}},e[a]={configurable:!0,enumerable:!0,get:function(){var b,d=g[c];return d&&(b=d.$get(g),b=f(h,"__global__").concat(f(h,a)).reduce(j,b),delete g[c],delete g[a],g[a]=b),b}},Object.defineProperties(g,e),this)},l=function(a){return this.container[a]},m=function(a,c){var e=arguments.length>2?b.call(arguments,1):null,f=this;return d.call(f,a,function(){return e&&(c=c.bind.apply(c,e.map(l,f))),new c})},n=function(a,b){return Object.defineProperty(this.container,a,{configurable:!0,enumerable:!0,value:b,writable:!0}),this},o=function q(){return this instanceof q?(this.id=a++,void(this.container={})):new q};o.prototype={constant:c,factory:d,middleware:g,provider:k,service:m,value:n},o.pop=function(){return new o};var p={"function":!0,object:!0};!function(a){var b=p[typeof exports]&&exports&&!exports.nodeType&&exports,c=p[typeof module]&&module&&!module.nodeType&&module,d=c&&c.exports===b&&b,e=p[typeof global]&&global;!e||e.global!==e&&e.window!==e||(a=e),"function"==typeof define&&"object"==typeof define.amd&&define.amd?(a.Bottle=o,define(function(){return o})):b&&c?d?(c.exports=o).Bottle=o:b.Bottle=o:a.Bottle=o}(p[typeof window]&&window||this)}).call(this);
//# sourceMappingURL=bottle.min.js.map
{
"name": "bottlejs",
"version": "0.1.0",
"version": "0.2.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, middlewear 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, 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:

@@ -24,2 +24,4 @@ * building a stack from components rather than a kitchen-sink framework.

BottleJS can be used in a browser or in a nodejs app. It can be installed via bower or npm:
```bash

@@ -29,2 +31,6 @@ $ bower install bottlejs

```bash
$ npm install bottlejs
```
## Simple Example

@@ -131,5 +137,5 @@

## Middlewear
## Middleware
Bottle supports injecting middlewear into the provider pipeline with the `Bottle#middlewear` method. Bottle middlewear 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 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.

@@ -140,4 +146,4 @@ ```js

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

@@ -147,4 +153,4 @@ return service;

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

@@ -175,9 +181,9 @@ return wine;

### middlewear(name, func)
### middleware(name, func)
Used to register a middlewear function that the provider will use to modify your services at creation time.
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 middlewear will affect. Will run for all services if not passed.
**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.

@@ -184,0 +190,0 @@

@@ -19,3 +19,3 @@

factory : factory,
middlewear : middlewear,
middleware : middleware,
provider : provider,

@@ -22,0 +22,0 @@ service : service,

@@ -16,3 +16,3 @@ /**

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

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

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

@@ -75,0 +75,0 @@

@@ -31,4 +31,4 @@ /* globals Bottle */

});
it("exposes middlewear", function() {
expect(Bottle.pop().middlewear).toBeDefined();
it("exposes middleware", function() {
expect(Bottle.pop().middleware).toBeDefined();
});

@@ -35,0 +35,0 @@ it("exposes provider", function() {

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