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

ginga

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ginga - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

22

flatten.js

@@ -1,15 +0,15 @@

var is = require('./is');
var is = require('./is')
module.exports = function flatten(arr, res){
if(!res){
res = [];
module.exports = function flatten (arr, res) {
if (!res) {
res = []
}
for(var i = 0, l = arr.length; i < l; i++){
if(arr[i] && is.array(arr[i])){
flatten(arr[i], res);
}else{
res.push(arr[i]);
for (var i = 0, l = arr.length; i < l; i++) {
if (arr[i] && is.array(arr[i])) {
flatten(arr[i], res)
} else {
res.push(arr[i])
}
}
return res;
};
return res
}

@@ -1,158 +0,156 @@

var is = require('./is'),
flatten = require('./flatten'),
EventEmitter = require('events').EventEmitter,
params = require('./params');
var is = require('./is')
var flatten = require('./flatten')
var EventEmitter = require('events').EventEmitter
var params = require('./params')
//ginga use method
function use(){
//init hooks
if(!this.hasOwnProperty('_hooks')){
this._hooks = {};
// ginga use method
function use () {
// init hooks
if (!this.hasOwnProperty('_hooks')) {
this._hooks = {}
}
var args = Array.prototype.slice.call(arguments);
var name = null, i, j, l, m;
var args = Array.prototype.slice.call(arguments)
var i, j, l, m
var name = null
if(is.array(args[0])){
//use(['a','b','c'], ...)
var arr = args.shift();
for(i = 0, l = arr.length; i<l; i++)
use.apply(this, [arr[i]].concat(args));
return this;
}else if(is.object(args[0]) && args[0]._hooks){
//use(ginga)
var key;
//concat hooks
for(key in args[0]._hooks)
use.call(this, key, args[0]._hooks[key]);
return this;
if (is.array(args[0])) {
// use(['a','b','c'], ...)
var arr = args.shift()
for (i = 0, l = arr.length; i < l; i++) {
use.apply(this, [arr[i]].concat(args))
}
return this
}else if (is.object(args[0]) && args[0]._hooks) {
// use(ginga)
var key
// concat hooks
for (key in args[0]._hooks)
use.call(this, key, args[0]._hooks[key])
return this
}
//method name
if(is.string(args[0]))
name = args.shift();
if(!name)
throw new Error('Method name is not defined.');
if(!this._hooks[name])
this._hooks[name] = [];
// method name
if (is.string(args[0])) name = args.shift()
if (!name) throw new Error('Method name is not defined.')
if (!this._hooks[name]) this._hooks[name] = []
for(i = 0, l = args.length; i<l; i++){
if(is.function(args[i])){
this._hooks[name].push(args[i]);
}else if(is.array(args[i])){
//use('a', [fn1, fn2, fn3])
for(j = 0, m = args[i].length; j<m; j++)
use.call(this, name, args[i][j]);
return this;
}else
throw new Error('Middleware must be a function');
for (i = 0, l = args.length; i < l; i++) {
if (is.function(args[i])) {
this._hooks[name].push(args[i])
} else if (is.array(args[i])) {
// use('a', [fn1, fn2, fn3])
for (j = 0, m = args[i].length; j < m; j++) {
use.call(this, name, args[i][j])
}
return this
} else {
throw new Error('Middleware must be a function')
}
}
return this;
return this
}
//ginga define method
function define(){
var args = Array.prototype.slice.call(arguments);
var i, l;
// ginga define method
function define () {
var args = Array.prototype.slice.call(arguments)
var i, l
var name = args.shift();
if(is.array(name)) {
name = args.shift();
for(i = 0, l = name.length; i<l; i++)
define.apply(this, [name[i]].concat(args));
return this;
var name = args.shift()
if (is.array(name)) {
name = args.shift()
for (i = 0, l = name.length; i < l; i++) {
define.apply(this, [name[i]].concat(args))
}
return this
}
if(!is.string(name))
throw new Error('method name is not defined');
if (!is.string(name)) throw new Error('Method name is not defined')
var invoke = args.pop();
if (!is.function(invoke))
invoke = null;
var invoke = args.pop()
if (!is.function(invoke)) invoke = null
var pre = args;
var pre = args
//define scope method
this[name] = function(){
var args = Array.prototype.slice.call(arguments);
var self = this;
// define scope method
this[name] = function () {
var args = Array.prototype.slice.call(arguments)
var self = this
var callbacks = [];
if (is.function(args[args.length - 1]))
callbacks.push(args.pop());
var callbacks = []
if (is.function(args[args.length - 1])) callbacks.push(args.pop())
//init pipeline;
var pipe = [];
var obj = this;
// init pipeline
var pipe = []
var obj = this
//prototype chain
while(obj){
if(obj.hasOwnProperty('_hooks') && obj._hooks[name])
pipe.unshift(obj._hooks[name]);
obj = Object.getPrototypeOf(obj);
// prototype chain
while (obj) {
if (obj.hasOwnProperty('_hooks') && obj._hooks[name]) {
pipe.unshift(obj._hooks[name])
}
obj = Object.getPrototypeOf(obj)
}
//pre middlewares
pipe.unshift(pre);
// pre middlewares
pipe.unshift(pre)
//invoke middleware
if(invoke)
pipe.push(invoke);
// invoke middleware
if (invoke) pipe.push(invoke)
pipe = flatten(pipe);
pipe = flatten(pipe)
//context object and next triggerer
var ctx = new EventEmitter();
ctx.method = name;
ctx.args = args;
// context object and next triggerer
var ctx = new EventEmitter()
ctx.method = name
ctx.args = args
var index = 0;
var size = pipe.length;
var cb = null;
var index = 0
var size = pipe.length
var cb = null
function end(fn){
if(cb)
fn.apply(self, cb);
else if(is.function(fn))
callbacks.push(fn);
function end (fn) {
if (cb) fn.apply(self, cb)
else if (is.function(fn)) callbacks.push(fn)
}
function next(){
if(arguments.length > 0){
for(var i = 0, l = callbacks.length; i<l; i++)
callbacks[i].apply(self, arguments);
cb = Array.prototype.slice.call(arguments);
ctx.emit.apply(ctx, ['end'].concat(cb));
return;
function next () {
if (arguments.length > 0) {
for (var i = 0, l = callbacks.length; i < l; i++) {
callbacks[i].apply(self, arguments)
}
cb = Array.prototype.slice.call(arguments)
ctx.emit.apply(ctx, ['end'].concat(cb))
return
}
if(index < size){
var fn = pipe[index];
var len = fn.length;
index++;
if (index < size) {
var fn = pipe[index]
index++
fn.call(self, ctx, next, end);
//args without next()
if(fn.length < 2) next();
}else{
//trigger empty callback if no more pipe
next(null);
fn.call(self, ctx, next, end)
// args without next()
if (fn.length < 2) next()
} else {
// trigger empty callback if no more pipe
next(null)
}
}
next();
next()
return this;
};
return this;
return this
}
return this
}
function Ginga(scope){
scope = scope || {};
scope.use = use;
scope.define = define;
function ginga (scope) {
scope = scope || {}
scope.use = use
scope.define = define
return scope;
return scope
}
Ginga.use = use;
Ginga.define = define;
Ginga.params = params;
module.exports = Ginga;
ginga.use = use
ginga.define = define
ginga.params = params
module.exports = ginga

@@ -1,26 +0,26 @@

var is = module.exports;
var is = module.exports
is.string = function(val){
return typeof val === 'string';
};
is.boolean = function(val){
return typeof val === 'boolean';
};
is.function = function(val){
return typeof val === 'function';
};
is.number = function(val){
return typeof val === 'number';
};
is.date = function(val){
return Object.prototype.toString.call(val) === '[object Date]';
};
is.regexp = function(val){
return Object.prototype.toString.call(val) === '[object RegExp]';
};
is.object = function(val){
return typeof val === 'object' && !!val;
};
is.array = Array.isArray || function(val){
return Object.prototype.toString.call(val) === '[object Array]';
};
is.string = function (val) {
return typeof val === 'string'
}
is.boolean = function (val) {
return typeof val === 'boolean'
}
is.function = function (val) {
return typeof val === 'function'
}
is.number = function (val) {
return typeof val === 'number'
}
is.date = function (val) {
return Object.prototype.toString.call(val) === '[object Date]'
}
is.regexp = function (val) {
return Object.prototype.toString.call(val) === '[object RegExp]'
}
is.object = function (val) {
return typeof val === 'object' && !!val
}
is.array = Array.isArray || function (val) {
return Object.prototype.toString.call(val) === '[object Array]'
}
{
"name": "ginga",
"version": "1.1.0",
"version": "1.1.1",
"description": "Middleware framework for JavaScript functions",
"scripts": {
"test": "set -e; for t in test/*.js; do node $t; done",
"test": "set -e; standard; for t in test/*.js; do node $t; done",
"build": "rm -rf dist; mkdir dist; npm run browserify;",

@@ -24,5 +24,6 @@ "browserify": "browserify . -s ginga | derequire > dist/ginga.js"

"devDependencies": {
"tape": "^3.0.2",
"derequire": "^2.0.0"
"derequire": "^2.0.0",
"standard": "^5.1.1",
"tape": "^3.0.2"
}
}

@@ -1,70 +0,74 @@

var is = require('./is');
var is = require('./is')
function dummy(){
return true;
}
function dummy () { return true }
//params parsing middleware
module.exports = function(){
var args = Array.prototype.slice.call(arguments);
var spec = [];
var specLen = args.length;
var min = 0;
var i, l;
for(i = 0; i<specLen; i++){
var obj = {};
var str = args[i];
// params parsing middleware
module.exports = function () {
var args = Array.prototype.slice.call(arguments)
var spec = []
var specLen = args.length
var min = 0
var i
for (i = 0; i < specLen; i++) {
var obj = {}
var str = args[i]
var ch = str.slice(-1);
obj.required = '?'.indexOf(ch) === -1;
var ch = str.slice(-1)
obj.required = '?'.indexOf(ch) === -1
if(obj.required)
min++;
if (obj.required) min++
if( '?'.indexOf(ch) > -1)
str = str.slice(0,-1);
if ('?'.indexOf(ch) > -1) str = str.slice(0, -1)
var arg = str.split(':');
obj.name = arg[0];
if(arg.length > 1){
//defined type
var check = is[arg[1].toLowerCase()];
if(typeof check !== 'function')
throw new Error('Parameter `'+arg[0]+'`: type `'+arg[1]+'` not exist');
obj.check = check;
}else
obj.check = dummy;
spec.push(obj);
var arg = str.split(':')
obj.name = arg[0]
if (arg.length > 1) {
// defined type
var check = is[arg[1].toLowerCase()]
if (typeof check !== 'function') {
throw new Error('Parameter `' + arg[0] + '`: type `' + arg[1] + '` not exist')
}
obj.check = check
} else {
obj.check = dummy
}
spec.push(obj)
}
return function(ctx, next){
var i, l;
var args = ctx.args;
var len = args.length;
var params = {};
var index = 0;
var offset = 0;
return function params (ctx, next) {
var args = ctx.args
var len = args.length
var params = {}
var index = 0
var offset = 0
ctx.params = params;
if(len < min)
return next(new Error('Too few arguments. Expected at least '+min));
while(offset < len && index < specLen){
while(
!spec[index].check(args[offset]) &&
ctx.params = params
if (len < min) {
return next(new Error(
'Too few arguments. Expected at least ' + min
))
}
while (offset < len && index < specLen) {
while (
!spec[index].check(args[offset]) &&
!spec[index].required
){
index++;
if(args[offset] === null || args[offset] === undefined)
offset++;
if(index >= specLen || offset >= len)
return next();
) {
index++
if (args[offset] === null || args[offset] === undefined) {
offset++
}
if (index >= specLen || offset >= len) {
return next()
}
}
if( !spec[index].check(args[offset]) )
return next(new Error('Invalid type on argument `'+args[offset]+'`.'));
params[spec[index].name] = args[offset];
index++;
offset++;
if (!spec[index].check(args[offset])) {
return next(new Error(
'Invalid type on argument `' + args[offset] + '`.'
))
}
params[spec[index].name] = args[offset]
index++
offset++
}
next();
};
};
next()
}
}

@@ -7,5 +7,5 @@ # Ginga.js

```bash
$ npm install ginga
```
npm install ginga
```

@@ -16,10 +16,10 @@ #### ginga([object])

```js
var ginga = require('ginga');
var obj = ginga(); //as a new object
var ginga = require('ginga')
var obj = ginga() //as a new object
var app = {};
ginga(app); //as a mixin
var app = {}
ginga(app) //as a mixin
function App(){ }
ginga(App.prototype); //as a prototype mixin:
function App () { }
ginga(App.prototype) //as a prototype mixin
```

@@ -37,24 +37,24 @@

```js
var ginga = require('ginga');
var app = ginga();
var ginga = require('ginga')
var app = ginga()
//defining method
app.define('test', function(ctx, next){
ctx.logs = ['pre'];
next();
}, function(ctx, done){
ctx.logs.push('invoke');
done(null, ctx.logs);
});
app.define('test', function (ctx, next) {
ctx.logs = ['pre']
next()
}, function (ctx, done) {
ctx.logs.push('invoke')
done(null, ctx.logs)
})
//hook
app.use('test', function(ctx, next){
ctx.logs.push('hook');
next();
});
app.use('test', function (ctx, next) {
ctx.logs.push('hook')
next()
})
//call method
app.test(function(err, res){
console.log(res); //['pre', 'hook', 'invoke']
});
app.test(function (err, res) {
console.log(res) //['pre', 'hook', 'invoke']
})
```

@@ -89,22 +89,22 @@

```js
var ginga = require('ginga');
var params = ginga.params;
var ginga = require('ginga')
var params = ginga.params
var app = ginga();
var app = ginga()
//define method with params parsing
app.define('test', params('a:string','b:number?','c:string?'), function(ctx, done){
done(null, ctx.params);
});
app.define('test', params('a:string', 'b:number?', 'c:string?'), function (ctx, done) {
done(null, ctx.params)
})
//call method
app.test('s',1,function(err, res){
console.log(res); //{"a":"s", "b":1}
});
app.test('s','t',function(err, res){
console.log(res); //{"a":"s", "c":"t"}
});
app.test(function(err, res){
console.log(err); //Error: Too few arguments. Expected at least 1
});
app.test('s',1,function (err, res) {
console.log(res) //{"a":"s", "b":1}
})
app.test('s','t',function (err, res) {
console.log(res) //{"a":"s", "c":"t"}
})
app.test(function (err, res) {
console.log(err) //Error: Too few arguments. Expected at least 1
})
```

@@ -119,28 +119,28 @@

```js
var ginga = require('ginga');
var ginga = require('ginga')
//define app
var app = ginga();
app.define('test', function(ctx, next){
ctx.logs = ['pre'];
next();
}, function(ctx, done){
ctx.logs.push('invoke');
done(null, ctx.logs);
});
var app = ginga()
app.define('test', function (ctx, next) {
ctx.logs = ['pre']
next()
}, function (ctx, done) {
ctx.logs.push('invoke')
done(null, ctx.logs)
})
//define plugin
var plugin = ginga();
plugin.use('test', function(ctx, next){
ctx.logs.push('plugin');
next();
});
var plugin = ginga()
plugin.use('test', function (ctx, next) {
ctx.logs.push('plugin')
next()
})
//use plugin
app.use(plugin);
app.use(plugin)
//call methods
app.test(function(err, res){
console.log(res); //['pre','plugin', 'invoke']
});
app.test(function (err, res) {
console.log(res) //['pre','plugin', 'invoke']
})
```

@@ -152,41 +152,41 @@

```js
var ginga = require('ginga');
var ginga = require('ginga')
function App(){}
var A = ginga(App.prototype); //ginga prototype mixin
function App () { }
var A = ginga(App.prototype) //ginga prototype mixin
A.define('test', function(ctx, next){
ctx.logs = ['pre'];
next();
}, function(ctx, done){
ctx.logs.push('invoke');
done(null, ctx.logs);
});
A.define('test', function (ctx, next) {
ctx.logs = ['pre']
next()
}, function (ctx, done) {
ctx.logs.push('invoke')
done(null, ctx.logs)
})
var a1 = new App();
var a2 = new App();
var a1 = new App()
var a2 = new App()
//prototype hook
A.use('test', function(ctx, next){
ctx.logs.push('A hook');
next();
});
A.use('test', function (ctx, next) {
ctx.logs.push('A hook')
next()
})
//instance hook
a1.use('test', function(ctx, next){
ctx.logs.push('a1 hook');
next();
});
a2.use('test', function(ctx, next){
ctx.logs.push('a2 hook');
next();
});
a1.use('test', function (ctx, next) {
ctx.logs.push('a1 hook')
next()
})
a2.use('test', function (ctx, next) {
ctx.logs.push('a2 hook')
next()
})
//call methods
a1.test(function(err, res){
console.log(res); //['pre','A hook','a1 hook', 'invoke']
});
a2.test(function(err, res){
console.log(res); //['pre','A hook','a2 hook', 'invoke']
});
a1.test(function (err, res) {
console.log(res) //['pre','A hook','a1 hook', 'invoke']
})
a2.test(function (err, res) {
console.log(res) //['pre','A hook','a2 hook', 'invoke']
})

@@ -193,0 +193,0 @@ ```

@@ -1,53 +0,53 @@

var tape = require('tape');
var ginga = require('../');
var tape = require('tape')
var ginga = require('../')
tape('ginga end', function(t){
t.plan(4);
var obj = ginga().define('f', function(ctx, done, end){
end(function(err, res){
t.deepEqual(err, 'err');
t.deepEqual(res, 'res');
});
done('err', 'res');
});
tape('ginga end', function (t) {
t.plan(4)
var obj = ginga().define('f', function (ctx, done, end) {
end(function (err, res) {
t.deepEqual(err, 'err')
t.deepEqual(res, 'res')
})
done('err', 'res')
})
obj.f(function(err, res){
t.deepEqual(err, 'err');
t.deepEqual(res, 'res');
});
});
obj.f(function (err, res) {
t.deepEqual(err, 'err')
t.deepEqual(res, 'res')
})
})
tape('ginga end emitter', function(t){
t.plan(4);
var obj = ginga().define('f', function(ctx, done){
ctx.on('end', function(err, res){
t.deepEqual(err, 'err');
t.deepEqual(res, 'res');
});
done('err', 'res');
});
tape('ginga end emitter', function (t) {
t.plan(4)
var obj = ginga().define('f', function (ctx, done) {
ctx.on('end', function (err, res) {
t.deepEqual(err, 'err')
t.deepEqual(res, 'res')
})
done('err', 'res')
})
obj.f(function(err, res){
t.deepEqual(err, 'err');
t.deepEqual(res, 'res');
});
});
obj.f(function (err, res) {
t.deepEqual(err, 'err')
t.deepEqual(res, 'res')
})
})
tape('ginga end after', function(t){
t.plan(4);
var obj = ginga().define('f', function(ctx, done, end){
setTimeout(function(){
end(function(err, res){
t.deepEqual(err, 'err');
t.deepEqual(res, 'res');
});
},10);
done('err', 'res');
});
tape('ginga end after', function (t) {
t.plan(4)
var obj = ginga().define('f', function (ctx, done, end) {
setTimeout(function () {
end(function (err, res) {
t.deepEqual(err, 'err')
t.deepEqual(res, 'res')
})
}, 10)
done('err', 'res')
})
obj.f(function(err, res){
t.deepEqual(err, 'err');
t.deepEqual(res, 'res');
});
obj.f(function (err, res) {
t.deepEqual(err, 'err')
t.deepEqual(res, 'res')
})
});
})

@@ -1,28 +0,28 @@

var tape = require('tape');
var ginga = require('../');
var params = ginga.params;
var tape = require('tape')
var ginga = require('../')
var params = ginga.params
function invoke(ctx, done){
return done(null, ctx.params);
function invoke (ctx, done) {
return done(null, ctx.params)
}
var obj = ginga()
.define('f1', params('a:string','b:string?','c:function?'), invoke)
.define('f2', params('a','b:string'), invoke);
.define('f1', params('a:string', 'b:string?', 'c:function?'), invoke)
.define('f2', params('a', 'b:string'), invoke)
function fn(){}
function fn () {}
tape('ginga params',function(t){
t.plan(6);
obj.f1('1','2', function(err, res){
t.notOk(err, 'no error');
t.deepEqual(res, { a: '1', b: '2' });
});
obj.f1('1',fn, function(err, res){
t.notOk(err, 'no error');
t.deepEqual(res, { a: '1', c: fn });
});
obj.f2('1', function(err, res){
t.ok(err, 'error');
t.notOk(res, 'no result');
});
});
tape('ginga params', function (t) {
t.plan(6)
obj.f1('1', '2', function (err, res) {
t.notOk(err, 'no error')
t.deepEqual(res, { a: '1', b: '2' })
})
obj.f1('1', fn, function (err, res) {
t.notOk(err, 'no error')
t.deepEqual(res, { a: '1', c: fn })
})
obj.f2('1', function (err, res) {
t.ok(err, 'error')
t.notOk(res, 'no result')
})
})

@@ -1,71 +0,69 @@

var tape = require('tape');
var ginga = require('../');
var tape = require('tape')
var ginga = require('../')
function Clock(){
this._tick = 'tick';
this._tock = 'tock';
function Clock () {
this._tick = 'tick'
this._tock = 'tock'
}
function base(ctx, next){
ctx.logs = ['clock'];
next();
function base (ctx, next) {
ctx.logs = ['clock']
next()
}
function tick(ctx, next){
ctx.logs.push(this._tick);
next();
function tick (ctx, next) {
ctx.logs.push(this._tick)
next()
}
function tock(ctx, next){
ctx.logs.push(this._tock);
next();
function tock (ctx, next) {
ctx.logs.push(this._tock)
next()
}
function end(ctx, done){
ctx.logs.push('done');
done(null, ctx.logs);
function end (ctx, done) {
ctx.logs.push('done')
done(null, ctx.logs)
}
ginga(Clock.prototype)
.define('tick', base, tick, end)
.define('tock', base, tick, tock, end);
.define('tock', base, tick, tock, end)
var plugin = ginga()
.use(
'tick',
function(ctx, next){
ctx.logs.push('more');
next();
function (ctx, next) {
ctx.logs.push('more')
next()
},
function(ctx, next){
ctx.logs.push('and more tick');
next();
function (ctx, next) {
ctx.logs.push('and more tick')
next()
}
)
.use('tock',function(ctx, next){
next('booooom');
});
)
.use('tock', function (ctx, next) {
next('booooom')
})
tape('ginga plugin', function (t) {
t.plan(8);
t.plan(8)
var clock = new Clock();
var clock = new Clock()
clock.tick(function(err,res){
t.notOk(err, 'no error');
t.deepEqual(res,['clock','tick','done']);
});
clock.tock(function(err,res){
t.notOk(err, 'no error');
t.deepEqual(res,['clock','tick','tock','done']);
});
clock.tick(function (err, res) {
t.notOk(err, 'no error')
t.deepEqual(res, ['clock', 'tick', 'done'])
})
clock.tock(function (err, res) {
t.notOk(err, 'no error')
t.deepEqual(res, ['clock', 'tick', 'tock', 'done'])
})
clock.use(plugin);
clock.use(plugin)
clock.tick(function(err,res){
t.notOk(err, 'no error');
t.deepEqual(res,['clock','tick','more','and more tick','done']);
});
clock.tock(function(err,res){
t.notOk(res, 'no result');
t.equal(err,'booooom', 'return error');
});
});
clock.tick(function (err, res) {
t.notOk(err, 'no error')
t.deepEqual(res, ['clock', 'tick', 'more', 'and more tick', 'done'])
})
clock.tock(function (err, res) {
t.notOk(res, 'no result')
t.equal(err, 'booooom', 'return error')
})
})

@@ -1,72 +0,72 @@

var tape = require('tape');
var ginga = require('../');
var tape = require('tape')
var ginga = require('../')
function Clock(){
this._tick = 'tick';
this._tock = 'tock';
function Clock () {
this._tick = 'tick'
this._tock = 'tock'
}
function base(ctx, next){
ctx.logs = ['clock'];
next();
function base (ctx, next) {
ctx.logs = ['clock']
next()
}
function tick(ctx){
//no callback
ctx.logs.push(this._tick);
function tick (ctx) {
// no callback
ctx.logs.push(this._tick)
}
function tock(ctx, next){
ctx.logs.push(this._tock);
next();
function tock (ctx, next) {
ctx.logs.push(this._tock)
next()
}
function end(ctx, done){
ctx.logs.push('done');
done(null, ctx.logs);
function end (ctx, done) {
ctx.logs.push('done')
done(null, ctx.logs)
}
var C = ginga(Clock.prototype);
var C = ginga(Clock.prototype)
var clock1 = new Clock();
var clock2 = new Clock();
var clock1 = new Clock()
var clock2 = new Clock()
clock2.use(
'tick',
function(ctx, next){
ctx.logs.push('more');
next();
function (ctx, next) {
ctx.logs.push('more')
next()
},
function(ctx, next){
ctx.logs.push('and more tick');
next();
function (ctx, next) {
ctx.logs.push('and more tick')
next()
}
);
)
clock2.use(
'tock',
function(ctx, next){
next('booooom');
function (ctx, next) {
next('booooom')
}
);
)
C.define('tick', end);
C.define('tock', end);
C.use('tick', base, tick);
C.use('tock', base, tick, tock);
C.define('tick', end)
C.define('tock', end)
C.use('tick', base, tick)
C.use('tock', base, tick, tock)
tape('ginga prototype', function (t) {
t.plan(8);
t.plan(8)
clock1.tick(function(err,res){
t.notOk(err, 'no error');
t.deepEqual(res,['clock','tick','done']);
});
clock1.tock(function(err,res){
t.notOk(err, 'no error');
t.deepEqual(res,['clock','tick','tock','done']);
});
clock2.tick(function(err,res){
t.notOk(err, 'no error');
t.deepEqual(res,['clock','tick','more','and more tick','done']);
});
clock2.tock(function(err,res){
t.notOk(res, 'no result');
t.equal(err,'booooom', 'return error');
});
});
clock1.tick(function (err, res) {
t.notOk(err, 'no error')
t.deepEqual(res, ['clock', 'tick', 'done'])
})
clock1.tock(function (err, res) {
t.notOk(err, 'no error')
t.deepEqual(res, ['clock', 'tick', 'tock', 'done'])
})
clock2.tick(function (err, res) {
t.notOk(err, 'no error')
t.deepEqual(res, ['clock', 'tick', 'more', 'and more tick', 'done'])
})
clock2.tock(function (err, res) {
t.notOk(res, 'no result')
t.equal(err, 'booooom', 'return error')
})
})
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