Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add .extend method

remove async dependency
  • Loading branch information...
commit a9280a52a589908f3225cbba78278b0cc609d960 1 parent de99baf
owner authored
View
3  index.js
@@ -1,5 +1,8 @@
var further = module.exports;
+further.extend = require('./lib/extend');
+
+further.reg =
further.registery = require('./lib/registery');
further.Serial = require('./lib/tasks/serial');
View
95 lib/extend.js
@@ -0,0 +1,95 @@
+var toString = Object.prototype.toString,
+ hasOwn = Object.prototype.hasOwnProperty,
+// push = Array.prototype.push,
+// slice = Array.prototype.slice,
+// trim = String.prototype.trim,
+// indexOf = Array.prototype.indexOf,
+ class2type = {
+ "[object Boolean]": "boolean",
+ "[object Number]": "number",
+ "[object String]": "string",
+ "[object Function]": "function",
+ "[object Array]": "array",
+ "[object Date]": "date",
+ "[object RegExp]": "regexp",
+ "[object Object]": "object"
+ },
+ jQuery = {
+ isFunction: function (obj) {
+ return jQuery.type(obj) === "function"
+ },
+ isArray: Array.isArray ||
+ function (obj) {
+ return jQuery.type(obj) === "array"
+ },
+ isWindow: function (obj) {
+ return obj != null && obj == obj.window
+ },
+ isNumeric: function (obj) {
+ return !isNaN(parseFloat(obj)) && isFinite(obj)
+ },
+ type: function (obj) {
+ return obj == null ? String(obj) : class2type[toString.call(obj)] || "object"
+ },
+ isPlainObject: function (obj) {
+ if (!obj || jQuery.type(obj) !== "object" || obj.nodeType) {
+ return false
+ }
+ try {
+ if (obj.constructor && !hasOwn.call(obj, "constructor") && !hasOwn.call(obj.constructor.prototype, "isPrototypeOf")) {
+ return false
+ }
+ } catch (e) {
+ return false
+ }
+ var key;
+ for (key in obj) {}
+ return key === undefined || hasOwn.call(obj, key)
+ }
+ };
+
+// jQuery extend
+module.exports = function() {
+ var options, name, src, copy, copyIsArray, clone,
+ target = arguments[0] || {},
+ i = 1,
+ length = arguments.length,
+ deep = false;
+
+ if (typeof target === "boolean") {
+ deep = target;
+ target = arguments[1] || {};
+ i = 2;
+ }
+ if (typeof target !== "object" && !jQuery.isFunction(target)) {
+ target = {}
+ }
+ if (length === i) {
+ target = this;
+ --i;
+ }
+ for (i; i < length; i++) {
+ if ((options = arguments[i]) != null) {
+ for (name in options) {
+ src = target[name];
+ copy = options[name];
+ if (target === copy) {
+ continue
+ }
+ if (deep && copy && (jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)))) {
+ if (copyIsArray) {
+ copyIsArray = false;
+ clone = src && jQuery.isArray(src) ? src : []
+ } else {
+ clone = src && jQuery.isPlainObject(src) ? src : {};
+ }
+ // WARNING: RECURSION
+ target[name] = extend(deep, clone, copy);
+ } else if (copy !== undefined) {
+ target[name] = copy;
+ }
+ }
+ }
+ }
+ return target;
+};
View
3  lib/requires.js
@@ -1,5 +1,4 @@
-var async = require('async'),
- path = require('path'),
+var path = require('path'),
fs = require('fs'),
registery = require('./registery');
View
25 lib/setup.js
@@ -1,8 +1,8 @@
-var async = require('async'),
- path = require('path'),
+var path = require('path'),
fs = require('fs'),
registery = require('./registery'),
+ Serial = require('./tasks/serial'),
Controller = require('./controller'),
requires = require('./requires'),
@@ -15,14 +15,21 @@ setup = module.exports = function(options, callback) {
registery[key] = options[key];
}
+ var tasks = new Serial();
+
// then, call setup methods
- async.forEachSeries(Object.keys(setup.methods), function (key, callback){
- if(typeof registery[key] === 'undefined' || registery[key] === null) {
- return callback();
- }
-
- setup.methods[key].call(registery, registery[key], callback);
- }, callback);
+ Object.keys(setup.methods)
+ .forEach(function(key) {
+ tasks.push(key, function (callback){
+ if(typeof registery[key] === 'undefined' || registery[key] === null) {
+ return callback();
+ }
+
+ setup.methods[key].call(registery, registery[key], callback);
+ });
+ });
+
+ tasks.run(callback);
};
// Setup app on each Controller
View
7 lib/tasks/task.js
@@ -18,7 +18,10 @@ Task.prototype.isRunning = function() {
};
Task.prototype.done = function(callback) {
- if(this.isRunning())
+ if(this._onDone === null)
+ throw new Error('Task wasn\'t run yet');
+
+ if(this._onDone.length)
this._onDone.push(callback);
else
callback.apply(this, this._results);
@@ -45,7 +48,7 @@ Task.prototype.run = function(callback) {
// define a done strategy
var self = this,
- done = function(err) {
+ done = function() {
self._results = Array.prototype.slice.call(arguments);
var fns = self._onDone;
View
1  package.json
@@ -10,7 +10,6 @@
"start": "node app"
},
"dependencies": {
- "async": "~0.1.22"
},
"devDependencies": {
},
Please sign in to comment.
Something went wrong with that request. Please try again.