Comparing version 0.0.9 to 0.1.0
79
index.js
@@ -9,5 +9,13 @@ var Traverse = require('traverse'); | ||
if (r !== undefined) saw.handlers = r; | ||
saw.record(); | ||
return saw.chain(); | ||
}; | ||
Chainsaw.light = function ChainsawLight (builder) { | ||
var saw = Chainsaw.saw(builder, {}); | ||
var r = builder.call(saw.handlers, saw); | ||
if (r !== undefined) saw.handlers = r; | ||
return saw.chain(); | ||
}; | ||
Chainsaw.saw = function (builder, handlers) { | ||
@@ -17,4 +25,3 @@ var saw = new EventEmitter; | ||
saw.actions = []; | ||
saw.step = 0; | ||
saw.chain = function () { | ||
@@ -24,3 +31,3 @@ var ch = Traverse(saw.handlers).map(function (node) { | ||
var ps = this.path; | ||
if (typeof node === 'function') { | ||
@@ -36,3 +43,3 @@ this.update(function () { | ||
}); | ||
process.nextTick(function () { | ||
@@ -42,10 +49,13 @@ saw.emit('begin'); | ||
}); | ||
return ch; | ||
}; | ||
saw.pop = function () { | ||
return saw.actions.shift(); | ||
}; | ||
saw.next = function () { | ||
var action = saw.actions[saw.step]; | ||
saw.step ++; | ||
var action = saw.pop(); | ||
if (!action) { | ||
@@ -60,7 +70,7 @@ saw.emit('end'); | ||
}; | ||
saw.nest = function (cb) { | ||
var args = [].slice.call(arguments, 1); | ||
var autonext = true; | ||
if (typeof cb === 'boolean') { | ||
@@ -70,11 +80,40 @@ var autonext = cb; | ||
} | ||
var s = Chainsaw.saw(builder, {}); | ||
var r = builder.call(s.handlers, s); | ||
if (r !== undefined) s.handlers = r; | ||
// If we are recording... | ||
if ("undefined" !== typeof saw.step) { | ||
// ... our children should, too | ||
s.record(); | ||
} | ||
cb.apply(s.chain(), args); | ||
if (autonext !== false) s.on('end', saw.next); | ||
}; | ||
saw.record = function () { | ||
upgradeChainsaw(saw); | ||
}; | ||
['trap', 'down', 'jump'].forEach(function (method) { | ||
saw[method] = function () { | ||
throw new Error("To use the trap, down and jump features, please "+ | ||
"call record() first to start recording actions."); | ||
}; | ||
}); | ||
return saw; | ||
}; | ||
function upgradeChainsaw(saw) { | ||
saw.step = 0; | ||
// override pop | ||
saw.pop = function () { | ||
return saw.actions[saw.step++]; | ||
}; | ||
saw.trap = function (name, cb) { | ||
@@ -89,3 +128,3 @@ var ps = Array.isArray(name) ? name : [name]; | ||
}; | ||
saw.down = function (name) { | ||
@@ -97,6 +136,6 @@ var ps = (Array.isArray(name) ? name : [name]).join('/'); | ||
}).indexOf(true); | ||
if (i >= 0) saw.step += i; | ||
else saw.step = saw.actions.length; | ||
var act = saw.actions[saw.step - 1]; | ||
@@ -110,3 +149,3 @@ if (act && act.trap) { | ||
}; | ||
saw.jump = function (step) { | ||
@@ -116,4 +155,2 @@ saw.step = step; | ||
}; | ||
return saw; | ||
}; | ||
}; |
{ | ||
"name" : "chainsaw", | ||
"version" : "0.0.9", | ||
"version" : "0.1.0", | ||
"description" : "Build chainable fluent interfaces the easy way... with a freakin' chainsaw!", | ||
@@ -5,0 +5,0 @@ "main" : "./index.js", |
var assert = require('assert'); | ||
var Chainsaw = require('chainsaw'); | ||
var Chainsaw = require('../index'); | ||
@@ -4,0 +4,0 @@ exports.getset = function () { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20363
568
158