Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

wrap() on remote callbacks only

  • Loading branch information...
commit 089fd203f16bab8b1ee6039cf2f4e40c7dc3169b 1 parent eb36273
James Halliday authored
Showing with 14 additions and 13 deletions.
  1. +2 −2 example/weak.js
  2. +6 −3 index.js
  3. +4 −6 lib/scrub.js
  4. +2 −2 test/wrap.js
4 example/weak.js
View
@@ -12,7 +12,7 @@ var s = (function () {
return proto(cons, function (cb, id) {
var ref = weak(cb, function () {
console.log('s.cull(' + id + ')')
- s.cull(id);
+ //s.cull(id);
});
return function () {
var f = weak.get(ref);
@@ -24,7 +24,7 @@ var s = (function () {
var c = proto({}, function (cb, id) {
var ref = weak(cb, function () {
console.log('c.cull(' + id + ')')
- c.cull(id);
+ //c.cull(id);
});
return function () {
var f = weak.get(ref);
9 index.js
View
@@ -17,10 +17,12 @@ module.exports = function (cons, wrap) {
function Proto (cons, wrap) {
var self = this;
EventEmitter.call(self);
- self.remote = {};
+ self.remote = {};
self.callbacks = { local : [], remote : [] };
- self.scrubber = scrubber(self.callbacks.local, wrap);
+ self.wrap = wrap;
+
+ self.scrubber = scrubber(self.callbacks.local);
if (typeof cons === 'function') {
self.instance = new cons(self.remote, self);
@@ -57,9 +59,10 @@ Proto.prototype.handle = function (req) {
if (self.callbacks.remote[id] === undefined) {
// create a new function only if one hasn't already been created
// for a particular id
- self.callbacks.remote[id] = function () {
+ var cb = function () {
self.request(id, [].slice.apply(arguments));
};
+ self.callbacks.remote[id] = self.wrap ? self.wrap(cb, id) : cb;
}
return self.callbacks.remote[id];
});
10 lib/scrub.js
View
@@ -9,13 +9,12 @@ function indexOf (xs, x) {
}
// scrub callbacks out of requests in order to call them again later
-module.exports = function (callbacks, wrap) {
- return new Scrubber(callbacks, wrap);
+module.exports = function (callbacks) {
+ return new Scrubber(callbacks);
};
-function Scrubber (callbacks, wrap) {
+function Scrubber (callbacks) {
this.callbacks = callbacks;
- this.wrap = wrap;
}
// Take the functions out and note them for future use
@@ -35,8 +34,7 @@ Scrubber.prototype.scrub = function (obj) {
}
else {
var id = self.callbacks.length;
- var ref = self.wrap ? self.wrap(node, id) : node;
- self.callbacks.push(ref);
+ self.callbacks.push(node);
paths[id] = this.path;
}
4 test/wrap.js
View
@@ -8,8 +8,8 @@ test('proto hashes', function (t) {
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.s, 2); // f, g
+ t.same(times.c, 1); // x(f,g)
t.end();
}
Please sign in to comment.
Something went wrong with that request. Please try again.