Comparing version 0.0.2 to 0.0.3
// Generated by CoffeeScript 1.4.0 | ||
var Defer, argsOf; | ||
var Defer, argsOf, sequence; | ||
@@ -8,2 +8,4 @@ argsOf = require('../util').argsOf; | ||
sequence = require('when/sequence'); | ||
module.exports = function(Preparator, decoratedFn) { | ||
@@ -13,22 +15,29 @@ if (typeof Preparator !== 'object' || Preparator instanceof Array) { | ||
} | ||
return (function(context, beforeAll) { | ||
return (function(context, done) { | ||
var beforeAll; | ||
context.signature = argsOf(decoratedFn); | ||
context.first = []; | ||
context.last = []; | ||
if ((Preparator.beforeAll != null) && typeof Preparator.beforeAll === 'function') { | ||
Preparator.beforeAll(function(result) { | ||
beforeAll = function() { | ||
var defer; | ||
defer = Defer(); | ||
if (done.beforeAll) { | ||
return defer.resolve(); | ||
} | ||
if (!((Preparator.beforeAll != null) && typeof Preparator.beforeAll === 'function' && (done.beforeAll = true))) { | ||
return defer.resolve(); | ||
} | ||
done = function(result) { | ||
done.beforeAll = true; | ||
if (result instanceof Error) { | ||
return beforeAll.reject(result); | ||
return defer.reject(result); | ||
} | ||
return beforeAll.resolve(result); | ||
}, context); | ||
} else { | ||
beforeAll.resolve(); | ||
} | ||
return defer.resolve(result); | ||
}; | ||
Preparator.beforeAll(done, context); | ||
return defer.promise; | ||
}; | ||
return function() { | ||
var arg, rejected, resolved, _i, _len; | ||
var arg, beforeEach, rejected, resolved, _i, _len; | ||
context.inject = []; | ||
if (Preparator.beforeEach != null) { | ||
Preparator.beforeEach(context); | ||
} | ||
for (_i = 0, _len = arguments.length; _i < _len; _i++) { | ||
@@ -38,9 +47,23 @@ arg = arguments[_i]; | ||
} | ||
return beforeAll.promise.then(resolved = function() { | ||
beforeEach = function() { | ||
var defer; | ||
defer = Defer(); | ||
if (!((Preparator.beforeEach != null) && typeof Preparator.beforeEach === 'function')) { | ||
return defer.resolve(); | ||
} | ||
done = function(result) { | ||
if (result instanceof Error) { | ||
return defer.reject(result); | ||
} | ||
return defer.resolve(result); | ||
}; | ||
Preparator.beforeEach(done, context); | ||
return defer.promise; | ||
}; | ||
return sequence([beforeAll, beforeEach]).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 Preparator.afterEach(context, result); | ||
} | ||
return result; | ||
}, rejected = function(error) { | ||
@@ -52,3 +75,5 @@ if (Preparator.error instanceof Function) { | ||
}; | ||
})(function() {}, Defer()); | ||
})(function() {}, { | ||
beforeAll: false | ||
}); | ||
}; |
{ | ||
"name": "also", | ||
"description": "decorators", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"author": "nomilous <nomilous@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -6,7 +6,7 @@ also | ||
### 0.0.2 (unstable) | ||
### 0.0.3 (unstable) | ||
vague example with ducks | ||
------------------------ | ||
example with ducks | ||
------------------ | ||
@@ -40,4 +40,4 @@ ```coffee | ||
vague example with node modules | ||
------------------------------- | ||
example with node modules | ||
------------------------- | ||
@@ -44,0 +44,0 @@ ```coffee |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
26291
128