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

also

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

also - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

Cakefile

9

lib/also.js

@@ -1,5 +0,8 @@

// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.6.3
module.exports = {
inject: require('./inject')
util: require('./util'),
match: require('./match'),
inject: require('./inject'),
schedule: require('./schedule'),
deferral: require('./deferral')
};

@@ -1,5 +0,4 @@

// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.6.3
exports.sync = require('./inject/sync');
exports.async = require('./inject/async');

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.6.3
var Defer, argsOf, sequence;

@@ -11,21 +11,53 @@

module.exports = function(Preparator, decoratedFn) {
var seq, _id;
seq = 0;
_id = seq;
if (typeof Preparator === 'function' && typeof decoratedFn === 'undefined') {
decoratedFn = Preparator;
Preparator = {};
}
if (typeof Preparator !== 'object' || Preparator instanceof Array) {
throw new Error('also.inject.async(Preparator, decoratedFn) requires Preparator as object');
}
return (function(context, done) {
var beforeAll;
if (Preparator.timeout == null) {
Preparator.timeout = 0;
}
if (Preparator.parallel == null) {
Preparator.parallel = true;
}
return (function(context, beforeAllDone) {
var beforeAll, calls, queue, queueRemainingLength, running;
context.signature = argsOf(decoratedFn);
context.first = [];
context.last = [];
queue = [];
calls = [];
running = false;
queueRemainingLength = function() {
var call, item, length, _i, _j, _len, _len1;
length = 0;
if (Preparator.parallel) {
for (_i = 0, _len = queue.length; _i < _len; _i++) {
item = queue[_i];
if (!item.done) {
length++;
}
}
} else {
for (_j = 0, _len1 = calls.length; _j < _len1; _j++) {
call = calls[_j];
length++;
}
}
return length;
};
beforeAll = function() {
var defer;
var defer, done;
defer = Defer();
if (done.beforeAll) {
if (beforeAllDone) {
return defer.resolve();
}
if (!((Preparator.beforeAll != null) && typeof Preparator.beforeAll === 'function' && (done.beforeAll = true))) {
if (typeof Preparator.beforeAll !== 'function') {
return defer.resolve();
}
beforeAllDone = true;
done = function(result) {
done.beforeAll = true;
if (result instanceof Error) {

@@ -39,39 +71,218 @@ return defer.reject(result);

};
Object.defineProperty(context, 'args', {
enumerable: true,
get: function() {
try {
return queue[_id].args;
} catch (_error) {}
}
});
Object.defineProperty(context, 'defer', {
enumerable: true,
get: function() {
queue[_id].altDefer = true;
try {
return queue[_id].defer;
} catch (_error) {}
}
});
Object.defineProperty(context, 'first', {
enumerable: true,
get: function() {
try {
return queue[_id].first;
} catch (_error) {}
}
});
Object.defineProperty(context, 'last', {
enumerable: true,
get: function() {
try {
return queue[_id].last;
} catch (_error) {}
}
});
Object.defineProperty(context, 'queue', {
enumerable: true,
get: function() {
return {
remaining: queueRemainingLength(),
elements: queue,
current: _id
};
}
});
Object.defineProperty(context, 'current', {
enumerable: true,
get: function() {
return queue[_id];
}
});
return function() {
var arg, beforeEach, rejected, resolved, _i, _len;
context.inject = [];
for (_i = 0, _len = arguments.length; _i < _len; _i++) {
arg = arguments[_i];
context.inject.push(arg);
}
beforeEach = function() {
var defer;
defer = Defer();
if (!((Preparator.beforeEach != null) && typeof Preparator.beforeEach === 'function')) {
return defer.resolve();
var finished, fn, run;
finished = Defer();
fn = function(finished, args) {
var afterAll, afterEach, arg, beforeEach, callDecoratedFn, fnDone, id, inject, _i, _len;
id = seq++;
inject = [];
for (_i = 0, _len = args.length; _i < _len; _i++) {
arg = args[_i];
inject.push(arg);
}
done = function(result) {
fnDone = function(result) {
_id = id;
if (Preparator.timeout != null) {
clearTimeout(queue[id].timer);
}
if (result instanceof Error) {
return defer.reject(result);
return queue[id].defer.reject(result);
}
return defer.resolve(result);
finished.notify({
result: result
});
return queue[id].defer.resolve(result);
};
Preparator.beforeEach(done, context);
return defer.promise;
queue[id] = {
done: false,
timeout: false,
defer: Defer(),
altDefer: false,
first: [],
last: [],
args: inject
};
if (Preparator.timeout !== 0) {
queue[id].timer = setTimeout((function() {
if (typeof Preparator.onTimeout === 'function') {
return Preparator.onTimeout(fnDone, {
type: 'fn'
}, context);
} else {
return fnDone();
}
}), Preparator.timeout);
}
beforeEach = function() {
var defer, done;
defer = Defer();
if (typeof Preparator.beforeEach !== 'function') {
return defer.resolve();
}
done = function(result) {
_id = id;
finished.notify({
beforeEach: result
});
if (result instanceof Error) {
return defer.reject(result);
}
return defer.resolve(result);
};
_id = id;
Preparator.beforeEach(done, context);
return defer.promise;
};
callDecoratedFn = function() {
_id = id;
if (queue[id].altDefer) {
decoratedFn.apply(this, queue[id].first.concat(inject).concat(queue[id].last));
} else {
decoratedFn.apply(this, [fnDone].concat(queue[id].first.concat(inject).concat(queue[id].last)));
}
return queue[id].defer.promise;
};
afterEach = function() {
var defer, done;
_id = id;
defer = Defer();
if (typeof Preparator.afterEach !== 'function') {
return defer.resolve();
}
done = function(result) {
_id = id;
finished.notify({
afterEach: result
});
if (result instanceof Error) {
return defer.reject(result);
}
return defer.resolve(result);
};
Preparator.afterEach(done, context);
return defer.promise;
};
afterAll = function() {
var defer, done;
_id = id;
defer = Defer();
queue[id].done = true;
if (Preparator.timeout != null) {
clearTimeout(queue[id].timer);
}
if (queueRemainingLength() !== 0) {
return defer.resolve();
}
if (typeof Preparator.afterAll !== 'function') {
queue.length = 0;
return defer.resolve();
}
done = function(result) {
_id = -1;
queue.length = 0;
if (result instanceof Error) {
return defer.reject(result);
}
return defer.resolve(result);
};
_id = -1;
Preparator.afterAll(done, context);
return defer.promise;
};
sequence([beforeAll, beforeEach, callDecoratedFn, afterEach, afterAll]).then(function(results) {
return finished.resolve(results[2]);
}, function(error) {
_id = id;
if (Preparator.onError instanceof Function) {
Preparator.onError(error, context);
}
return finished.reject(error);
}, function(status) {
_id = id;
if (Preparator.onNotify instanceof Function) {
Preparator.onNotify(status, context);
}
return finished.notify(status);
});
return finished.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) {
return Preparator.afterEach(context, result);
if (!Preparator.parallel) {
calls.push({
"function": fn,
finished: finished,
"arguments": arguments
});
run = function() {
var call;
running = true;
call = calls.shift();
if (call == null) {
running = false;
return;
}
return call["function"](call.finished, call["arguments"]).then(function() {
return run();
}, function() {
return run();
});
};
if (!running) {
run();
}
}, rejected = function(error) {
if (Preparator.error instanceof Function) {
return Preparator.error(error);
}
});
return finished.promise;
}
if (Preparator.parallel) {
return fn(finished, arguments);
}
};
})(function() {}, {
beforeAll: false
});
})(function() {}, false);
};

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.6.3
var argsOf;

@@ -3,0 +3,0 @@

@@ -1,5 +0,5 @@

// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.6.3
module.exports = {
argsOf: function(fn) {
var error;
try {

@@ -11,3 +11,4 @@ return fn.toString().match(/function\s*\((.*)\)/)[1].replace(/\s/g, '').split(',').filter(function(arg) {

});
} catch (error) {
} catch (_error) {
error = _error;
return [];

@@ -14,0 +15,0 @@ }

{
"name": "also",
"description": "decorators",
"version": "0.0.3",
"version": "0.0.4",
"author": "nomilous <nomilous@gmail.com>",

@@ -18,5 +18,6 @@ "contributors": [

"devDependencies": {
"nez": "0.0.7",
"should": "~1.2.2"
"should": "~1.2.2",
"mocha": "~1.12.0",
"coffee-script": "~1.6.3"
}
}

@@ -0,32 +1,38 @@

### Version 0.0.4 (unstable)
`npm install also`
also
====
decorators
An accumulating set of function decorators. <br />
### 0.0.3 (unstable)
Function decorators?: [Coffeescript Ristretto](https://leanpub.com/coffeescript-ristretto)
example with ducks
------------------
Examples
--------
### synchronous example with ducks
```coffee
{sync, async} = require( 'also' ).inject
{inject} = require 'also'
ducks = 0
ducklings = 0
quark = sync
ducks = 0
quark = inject.sync
beforeAll: -> ducks++
beforeEach: -> ducklings++
beforeAll: -> ducks++
->
ducks: ducks
ducklings: ducklings
ducks: ducks
quark quark quark quark quark quark quark()
console.log quark quark quark quark quark quark quark()

@@ -39,13 +45,11 @@ # => { ducks: 1, ducklings: 7 }

example with node modules
-------------------------
### synchronous example with node modules
```coffee
nodeModules = (names) ->
for name in names
require name
nodeModules = (names) -> require name for name in names
start = inject.sync nodeModules, (crypto, zlib, net) ->
start = sync nodeModules, (crypto, zlib, net) ->
#

@@ -58,1 +62,11 @@ # ...

```
### asynchronous example
none. see [spec](https://github.com/nomilous/also/blob/master/spec/inject/async_spec.coffee)
todo
----
* combine with Notice (hub) and run as daemon (script server for worker/drone farm)

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

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

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