Permalink
Browse files

wrapper counting test works

  • Loading branch information...
1 parent 7cbb08b commit 995098fa5cb5adb6ad10b66d1d0752828378a55c @substack committed Jun 20, 2012
Showing with 12 additions and 8 deletions.
  1. +2 −2 index.js
  2. +6 −4 lib/scrub.js
  3. +4 −2 test/wrap.js
View
@@ -4,8 +4,8 @@ var objectKeys = require('./lib/keys');
var forEach = require('./lib/foreach');
var isEnumerable = require('./lib/is_enum');
-module.exports = function (cons) {
- return new Proto(cons);
+module.exports = function (cons, opts) {
+ return new Proto(cons, opts);
};
(function () { // browsers bleh
View
@@ -9,12 +9,13 @@ function indexOf (xs, x) {
}
// scrub callbacks out of requests in order to call them again later
-module.exports = function (callbacks) {
- return new Scrubber(callbacks);
+module.exports = function (callbacks, wrap) {
+ return new Scrubber(callbacks, wrap);
};
-function Scrubber (callbacks) {
+function Scrubber (callbacks, wrap) {
this.callbacks = callbacks;
+ this.wrap = wrap;
}
// Take the functions out and note them for future use
@@ -33,7 +34,8 @@ Scrubber.prototype.scrub = function (obj) {
paths[i] = this.path;
}
else {
- var id = self.callbacks.push(node) - 1;
+ var ref = self.wrap ? self.wrap(node) : node;
+ var id = self.callbacks.push(ref) - 1;
paths[id] = this.path;
}
View
@@ -3,13 +3,13 @@ var proto = require('../');
var traverse = require('traverse');
test('proto hashes', function (t) {
- t.plan(8);
+ t.plan(10);
var pending = 5;
var times = { s : 0, c : 0 };
function done () {
t.same(times.s, 1); // x(f,g)
-: t.same(times.c, 2); // f, g
+ t.same(times.c, 2); // f, g
t.end();
}
@@ -18,13 +18,15 @@ test('proto hashes', function (t) {
t.equal(typeof fn, 'function');
times.s ++;
if (--pending === 0) done();
+ return fn;
}
function cwrapper (fn) {
// 2 of these
t.equal(typeof fn, 'function');
times.c ++;
if (--pending === 0) done();
+ return fn;
}
var s = proto({

0 comments on commit 995098f

Please sign in to comment.