Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dnode-protocol

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dnode-protocol - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

25

example/weak.js

@@ -7,17 +7,22 @@ var weak = require('weak');

x : function (f, g) {
setTimeout(function () { f(5) }, 2000);
setTimeout(function () { g(6) }, 2000);
setTimeout(function () { f(5) }, 200);
setTimeout(function () { g(6) }, 400);
},
y : 555
};
return proto(cons, function (fn, id) {
weak(fn, function () { console.log('s.cull:' + id) });
return fn;
return proto(cons, {
wrap : function (cb, id) {
return weak(cb, function () {
console.log('s.cull(' + id + ')')
s.cull(id);
});
},
unwrap : function (ref, id) {
var cb = weak.get(ref);
return cb || function () {};
}
});
})();
var c = proto({}, function wrapc (fn, id) {
weak(fn, function () { console.log('c.cull:' + id) });
return fn;
});
var c = proto();

@@ -41,2 +46,2 @@ s.on('request', c.handle.bind(c));

xs = [];
}, 2500);
}, 1000);

27

index.js

@@ -7,4 +7,4 @@ var EventEmitter = require('events').EventEmitter;

module.exports = function (cons, wrap) {
return new Proto(cons, wrap);
module.exports = function (cons, opts) {
return new Proto(cons, opts);
};

@@ -18,10 +18,14 @@

function Proto (cons, wrap) {
function Proto (cons, opts) {
var self = this;
EventEmitter.call(self);
if (!opts) opts = {};
self.remote = {};
self.callbacks = { local : [], remote : [] };
self.scrubber = scrubber(self.callbacks.local, wrap);
self.wrap = opts.wrap;
self.unwrap = opts.unwrap;
self.scrubber = scrubber(self.callbacks.local);
if (typeof cons === 'function') {

@@ -38,3 +42,3 @@ self.instance = new cons(self.remote, self);

Proto.prototype.cull = function (id) {
delete this.callbacks.local[id];
delete this.callbacks.remote[id];
this.emit('request', {

@@ -63,7 +67,12 @@ method : 'cull',

// 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 cb;
}
return self.callbacks.remote[id];
return self.unwrap
? self.unwrap(self.callbacks.remote[id], id)
: self.callbacks.remote[id]
;
});

@@ -76,3 +85,3 @@

forEach(args, function (id) {
delete self.callbacks.remote[id];
delete self.callbacks.local[id];
});

@@ -79,0 +88,0 @@ }

@@ -12,9 +12,8 @@ var traverse = require('traverse');

// 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;
}

@@ -39,4 +38,3 @@

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;

@@ -43,0 +41,0 @@ }

{
"name": "dnode-protocol",
"description": "Implements the dnode protocol abstractly",
"version": "0.2.1",
"description": "implements the dnode protocol abstractly",
"version": "0.2.2",
"repository": "https://github.com/substack/dnode-protocol.git",

@@ -17,4 +17,3 @@ "author": {

"devDependencies" : {
"tap" : "~0.2.5",
"weak" : "~0.2.1"
"tap" : "~0.2.5"
},

@@ -21,0 +20,0 @@ "scripts": {

@@ -11,4 +11,4 @@ var test = require('tap').test;

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();

@@ -39,5 +39,5 @@ }

y : 555
}, swrapper);
}, { wrap : swrapper });
var c = proto({}, cwrapper);
var c = proto({}, { wrap : cwrapper });

@@ -44,0 +44,0 @@ var sreqs = [];

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc