Comparing version 0.0.1 to 0.0.2
// Generated by CoffeeScript 1.4.0 | ||
var argsOf; | ||
var Defer, argsOf; | ||
argsOf = require('../util').argsOf; | ||
module.exports = function(signatureFn, fn) { | ||
return function() { | ||
var arg, context, original; | ||
context = void 0; | ||
original = (function() { | ||
var _i, _len, _results; | ||
_results = []; | ||
Defer = require('when').defer; | ||
module.exports = function(Preparator, decoratedFn) { | ||
if (typeof Preparator !== 'object' || Preparator instanceof Array) { | ||
throw new Error('also.inject.async(Preparator, decoratedFn) requires Preparator as object'); | ||
} | ||
return (function(context, beforeAll) { | ||
context.signature = argsOf(decoratedFn); | ||
context.first = []; | ||
context.last = []; | ||
if ((Preparator.beforeAll != null) && typeof Preparator.beforeAll === 'function') { | ||
Preparator.beforeAll(function(result) { | ||
if (result instanceof Error) { | ||
return beforeAll.reject(result); | ||
} | ||
return beforeAll.resolve(result); | ||
}, context); | ||
} else { | ||
beforeAll.resolve(); | ||
} | ||
return function() { | ||
var arg, rejected, resolved, _i, _len; | ||
context.inject = []; | ||
if (Preparator.beforeEach != null) { | ||
Preparator.beforeEach(context); | ||
} | ||
for (_i = 0, _len = arguments.length; _i < _len; _i++) { | ||
arg = arguments[_i]; | ||
_results.push(arg); | ||
context.inject.push(arg); | ||
} | ||
return _results; | ||
}).apply(this, arguments); | ||
if (typeof signatureFn === 'function') { | ||
signatureFn(argsOf(fn).slice(1), function(error, result) { | ||
return fn.apply(null, [error].concat(result).concat(original)); | ||
return beforeAll.promise.then(resolved = function() { | ||
var result; | ||
result = decoratedFn.apply(null, context.first.concat(context.inject).concat(context.last)); | ||
if (Preparator.afterEach != null) { | ||
Preparator.afterEach(context, result); | ||
} | ||
return result; | ||
}, rejected = function(error) { | ||
if (Preparator.error instanceof Function) { | ||
return Preparator.error(error); | ||
} | ||
}); | ||
} else if (signatureFn instanceof Array) { | ||
fn.apply(null, signatureFn.concat(original)); | ||
} else if (signatureFn instanceof Object) { | ||
context = { | ||
config: signatureFn | ||
}; | ||
} else { | ||
fn.apply(null, [signatureFn].concat(original)); | ||
} | ||
if (context == null) { | ||
return; | ||
} | ||
return fn.apply(null, null); | ||
}; | ||
}; | ||
})(function() {}, Defer()); | ||
}; |
@@ -8,12 +8,11 @@ // Generated by CoffeeScript 1.4.0 | ||
return (function(context, configured) { | ||
context.preparator = Preparator; | ||
context.signature = argsOf(decoratedFn); | ||
context.first = []; | ||
context.last = []; | ||
if (context.preparator.beforeAll != null) { | ||
context.preparator.beforeAll(context); | ||
if (Preparator.beforeAll != null) { | ||
Preparator.beforeAll(context); | ||
} | ||
return function() { | ||
var arg, result, _i, _j, _len, _len1; | ||
context.inject = typeof context.preparator === 'function' ? context.preparator(context.signature) : context.preparator instanceof Array ? context.preparator : context.preparator instanceof Object ? (configured = true, []) : [context.preparator]; | ||
context.inject = typeof Preparator === 'function' ? Preparator(context.signature) : Preparator instanceof Array ? Preparator : Preparator instanceof Object ? (configured = true, []) : [Preparator]; | ||
if (!configured) { | ||
@@ -26,4 +25,4 @@ for (_i = 0, _len = arguments.length; _i < _len; _i++) { | ||
} | ||
if (context.preparator.beforeEach != null) { | ||
context.preparator.beforeEach(context); | ||
if (Preparator.beforeEach != null) { | ||
Preparator.beforeEach(context); | ||
} | ||
@@ -35,4 +34,4 @@ for (_j = 0, _len1 = arguments.length; _j < _len1; _j++) { | ||
result = decoratedFn.apply(null, context.first.concat(context.inject).concat(context.last)); | ||
if (context.preparator.afterEach != null) { | ||
context.preparator.afterEach(context, result); | ||
if (Preparator.afterEach != null) { | ||
Preparator.afterEach(context, result); | ||
} | ||
@@ -39,0 +38,0 @@ return result; |
{ | ||
"name": "also", | ||
"description": "decorators", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"author": "nomilous <nomilous@gmail.com>", | ||
@@ -14,3 +14,5 @@ "contributors": [ | ||
"repository": "git@github.com:nomilous/also.git", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"when": "~2.1.0" | ||
}, | ||
"devDependencies": { | ||
@@ -17,0 +19,0 @@ "nez": "0.0.7", |
@@ -6,3 +6,3 @@ also | ||
### 0.0.1 (unstable) | ||
### 0.0.2 (unstable) | ||
@@ -22,13 +22,12 @@ | ||
beforeEach: -> ducklings++ | ||
beforeAll: -> ducks++ | ||
beforeEach: -> ducklings++ | ||
-> | ||
ducklings: ducklings | ||
ducks: ducks | ||
ducklings: ducklings | ||
quark quark quark quark quark quark quark() | ||
@@ -40,1 +39,21 @@ | ||
``` | ||
vague example with node modules | ||
------------------------------- | ||
```coffee | ||
nodeModules = (names) -> | ||
for name in names | ||
require name | ||
start = sync nodeModules, (crypto, zlib, net) -> | ||
# | ||
# ... | ||
# | ||
start() | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
22090
104
57
1
+ Addedwhen@~2.1.0
+ Addedwhen@2.1.1(transitive)