From 98fc489ba7eef7e9aa2bf743dd70f5f87a96c41c Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Wed, 10 Dec 2014 19:47:56 -0500 Subject: [PATCH] Initial deposit --- index.js | 40 ++++++++++++++++++++++++++++++++++++++++ package.json | 11 +++++++++++ 2 files changed, 51 insertions(+) create mode 100644 index.js create mode 100644 package.json diff --git a/index.js b/index.js new file mode 100644 index 0000000..576bdd4 --- /dev/null +++ b/index.js @@ -0,0 +1,40 @@ +function Kareem() { + this._pres = {}; + this._posts = {}; +} + +Kareem.prototype.execPre = function(name, context, arguments) { + +}; + +Kareem.prototype.pre = function(name, isAsync, fn, error) { + if ('boolean' !== typeof arguments[1]) { + errorCallback = callback; + callback = isAsync; + isAsync = false; + } + + this._pres[name] = this._pres[name] || []; + var pres = this._pres[name]; + + if (isAsync) { + pres.numAsync = pres.numAsync || 0; + ++pres.numAsync; + } + + fn.isAsync = isAsync; + this._pres.push(fn); + + return this; +}; + +Kareem.prototype.post = function(name, isAsync, fn) { + if (arguments.length === 2) { + fn = isAsync; + isAsync = false; + } + + fn.isAsync = isAsync; + (this._posts[name] = this._posts[name] || []).push(fn); + return this; +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..ca89e8f --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "kareem", + "version": "0.0.0", + "description": "Next-generation hooks", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +}