Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

@storybook/channels

Package Overview
Dependencies
0
Maintainers
11
Versions
1762
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.3.0-alpha.3 to 3.3.0-alpha.4

17

dist/index.js

@@ -44,2 +44,13 @@ "use strict";

}, {
key: "addPeerListener",
value: function addPeerListener(type, listener) {
var _this = this;
var peerListener = listener;
peerListener.isPeer = function (from) {
return from === _this._sender;
};
this.on(type, peerListener);
}
}, {
key: "emit",

@@ -125,3 +136,3 @@ value: function emit(type) {

listeners.forEach(function (fn) {
return fn.apply(undefined, (0, _toConsumableArray3.default)(event.args));
return !(fn.isPeer && fn.isPeer(event.from)) && fn.apply(undefined, (0, _toConsumableArray3.default)(event.args));
});

@@ -133,6 +144,6 @@ }

value: function _onceListener(type, listener) {
var _this = this;
var _this2 = this;
var onceListener = function onceListener() {
_this.removeListener(type, onceListener);
_this2.removeListener(type, onceListener);
return listener.apply(undefined, arguments);

@@ -139,0 +150,0 @@ };

5

package.json
{
"name": "@storybook/channels",
"version": "3.3.0-alpha.3",
"version": "3.3.0-alpha.4",
"description": "",

@@ -9,6 +9,3 @@ "license": "MIT",

"prepare": "node ../../scripts/prepare.js"
},
"devDependencies": {
"shelljs": "^0.7.8"
}
}

@@ -18,2 +18,3 @@ # Storybook Channel

addListener(type, listener) {}
addPeerListener(type, listener) {} // ignore events from itself
emit(type, ...args) {}

@@ -20,0 +21,0 @@ eventNames() {}

@@ -15,2 +15,8 @@ /* eslint no-underscore-dangle: 0 */

addPeerListener(type, listener) {
const peerListener = listener;
peerListener.isPeer = from => from === this._sender;
this.on(type, peerListener);
}
emit(type, ...args) {

@@ -79,3 +85,3 @@ const event = { type, args, from: this._sender };

if (listeners) {
listeners.forEach(fn => fn(...event.args));
listeners.forEach(fn => !(fn.isPeer && fn.isPeer(event.from)) && fn(...event.args));
}

@@ -82,0 +88,0 @@ }

@@ -103,4 +103,4 @@ /* eslint no-underscore-dangle: 0 */

channel.once('type-2', 22);
expect(channel._listeners['type-1'].length).toEqual(1);
expect(channel._listeners['type-2'].length).toEqual(2);
expect(channel._listeners['type-1']).toHaveLength(1);
expect(channel._listeners['type-2']).toHaveLength(2);
});

@@ -117,2 +117,20 @@

describe('method:addPeerListener', () => {
it('should add event listeners', () => {
channel.addPeerListener('type-1', () => {});
channel.addPeerListener('type-2', () => {});
channel.addPeerListener('type-2', () => {});
expect(channel._listeners['type-1']).toHaveLength(1);
expect(channel._listeners['type-2']).toHaveLength(2);
});
it('should call event listeners on event', () => {
const received = [];
channel.addPeerListener('type-1', n => received.push(n));
channel._handleEvent({ type: 'type-1', args: [11] });
channel._handleEvent({ type: 'type-1', args: [12] });
expect(received).toEqual([11, 12]);
});
});
describe('method:prependListener', () => {

@@ -136,4 +154,4 @@ it('should add event listeners', () => {

channel.prependOnceListener('type-2', 22);
expect(channel._listeners['type-1'].length).toEqual(1);
expect(channel._listeners['type-2'].length).toEqual(2);
expect(channel._listeners['type-1']).toHaveLength(1);
expect(channel._listeners['type-2']).toHaveLength(2);
});

@@ -190,3 +208,11 @@

});
it('should ignore if event handled by addPeerListener', () => {
const received = [];
channel.addPeerListener('type-1', n => received.push(n));
channel._handleEvent({ type: 'type-1', args: [11], from: channel._sender });
channel._handleEvent({ type: 'type-1', args: [12], from: '_' });
expect(received).toEqual([12]);
});
});
});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc