Socket
Socket
Sign inDemoInstall

eden-class

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eden-class - npm Package Compare versions

Comparing version 0.0.1 to 0.0.3

.npmignore

95

class.js

@@ -16,2 +16,8 @@ module.exports = require('classified-magic')(function(prototype) {

-------------------------------*/
prototype.__sequence = {
stack : [],
working : false,
args : [],
loop : [] };
var __states = {};

@@ -151,2 +157,24 @@

prototype.sync = function(callback, unshift) {
//argument 1 must be a function
argument.test(1, 'function');
var sequence = this.__sequence;
if(!unshift) {
sequence.stack.push(callback);
} else {
sequence.stack.unshift(callback);
}
if(!sequence.working) {
sequence.working = true;
sequence.scope = this;
this.__next.apply(sequence, sequence.args);
}
return this;
};
/**

@@ -192,2 +220,69 @@ * Notify all observers of that a specific

-------------------------------*/
prototype.__next = function() {
var args = Array.prototype.slice.apply(arguments);
//if there is something in the loop
if(this.loop.length) {
//save the last called args
if(!this.last) {
this.last = args;
}
var item = this.loop.shift();
//push in next()
//this function will recurse call
//so no need to parse the loop
item.args.push(arguments.callee.bind(this));
//async call
process.nextTick(function() {
//do the callback
item.callback.apply(this.scope, item.args);
}.bind(this));
return;
}
if(this.last) {
args = this.last;
delete this.last;
}
if(!this.stack.length) {
this.working = false;
this.args = args;
return;
}
var callback = this.stack.shift(),
next = arguments.callee.bind(this);
next.loop = __loop.bind(this);
args.push(next);
//async call
process.nextTick(function() {
//do the callback
callback.apply(this.scope, args);
}.bind(this));
};
var __loop = function() {
if(!this.stack.length) {
return;
}
var item = {args: Array.prototype.slice.apply(arguments) };
//if loop is empty
if(!this.loop.length) {
item.callback = this.stack.shift();
} else {
item.callback = this.loop[0].callback;
}
this.loop.push(item);
};
var _isNative = function(value) {

@@ -194,0 +289,0 @@ //do the easy ones first

4

package.json
{
"name": "eden-class",
"description": "Eden JS Base Class",
"version": "0.0.1",
"version": "0.0.3",
"author": {

@@ -18,3 +18,3 @@ "name": "Christian Blanquera",

"argument": "0.0.2",
"classified-magic": "0.0.10"
"classified-magic": "0.0.13"
},

@@ -21,0 +21,0 @@ "main": "./class.js",

@@ -14,3 +14,3 @@ var assert = require('assert');

var user = require('../class').extend(function(prototype) {
var User = require('../class').extend(function(prototype) {
prototype.setName = function(name) {

@@ -24,4 +24,14 @@ this.name = name;

};
}).load();
});
var user = User.load();
var Member = User.extend({});
var member = Member.load();
var Person = Member.extend({});
var person = Person.load();
describe('Class Test Suite', function() {

@@ -39,3 +49,80 @@ describe('Extending Tests', function() {

});
it('should sync methods', function(done) {
user.sync(function(next) {
next(1);
}).sync(function(value, next) {
this.syncTest = value;
next();
}).sync(function(next) {
assert.equal(1, this.syncTest);
next();
done();
});
});
it('should sync methods in tree', function(done) {
user.sync(function(next) {
next(1);
}).sync(function(value, next) {
this.syncTest = value;
next();
}).sync(function(next) {
assert.equal(1, this.syncTest);
next();
member.sync(function(next) {
next(1);
}).sync(function(value, next) {
this.syncTest = value;
next();
}).sync(function(next) {
assert.equal(1, this.syncTest);
next();
person.sync(function(next) {
next(1);
}).sync(function(value, next) {
this.syncTest = value;
next();
}).sync(function(next) {
assert.equal(1, this.syncTest);
next();
done();
});
});
});
});
it('should loop sync methods', function(done) {
user.sync(function(next) {
for(var i = 0; i < 5; i++) {
next.loop(i);
}
next('yes');
}).sync(function(i, next) {
assert.equal('number', typeof i);
next();
}).sync(function(string, next) {
assert.equal('yes', string);
next();
}).sync(function(next) {
for(var i = 5; i < 10; i++) {
next.loop(i);
}
next([1,2,3,4]);
}).sync(function(i, next) {
assert.equal('number', typeof i);
next();
}).sync(function(list, next) {
assert.equal(true, list instanceof Array);
done();
next();
});
});
});
});
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