From 84bd16d4a2faa78623737b3bb2a44efcd29c21fa Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Tue, 13 Oct 2015 02:31:57 -0700 Subject: [PATCH] compose function --- lib/index2.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/index2.js b/lib/index2.js index 6c5a250bc..cd310bdef 100644 --- a/lib/index2.js +++ b/lib/index2.js @@ -10,6 +10,7 @@ const path = require('path'), /** * JAWS Class */ + let JAWS = class JAWS { constructor() { @@ -107,6 +108,7 @@ let JAWS = class JAWS { * Update Config * @param config */ + config(config) { // Extend JAWS with config properties @@ -116,6 +118,7 @@ let JAWS = class JAWS { /** * Set Action */ + action(action, actionGenerator) { // Check action is valid @@ -129,6 +132,7 @@ let JAWS = class JAWS { /** * Set Hook */ + hook(hook, hookGenerator, index) { // Check hook is valid @@ -141,13 +145,26 @@ let JAWS = class JAWS { } /** - * Orchestrator + * Compose */ - orchestrate() { + compose(genArray) { + return function *(next){ + if (!next) next = noop(); + + var i = genArray.length; + + while (i--) { + next = genArray[i].call(this, next); + } + + yield *next; + } } } module.exports = new JAWS(); +function *noop(){} +