@storybook/channels
Advanced tools
Comparing version 4.2.0-alpha.5 to 4.2.0-alpha.6
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
require("core-js/modules/es6.string.iterator"); | ||
require("core-js/modules/es6.array.from"); | ||
require("core-js/modules/es7.symbol.async-iterator"); | ||
require("core-js/modules/es6.symbol"); | ||
require("core-js/modules/es6.array.is-array"); | ||
require("core-js/modules/es6.object.define-property"); | ||
require("core-js/modules/es6.array.for-each"); | ||
require("core-js/modules/es6.regexp.to-string"); | ||
require("core-js/modules/es6.date.to-string"); | ||
require("core-js/modules/es6.array.filter"); | ||
require("core-js/modules/web.dom.iterable"); | ||
require("core-js/modules/es6.array.iterator"); | ||
require("core-js/modules/es6.object.keys"); | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
/* eslint no-underscore-dangle: 0 */ | ||
var Channel = | ||
/*#__PURE__*/ | ||
function () { | ||
function Channel() { | ||
var _this = this; | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
transport = _ref.transport, | ||
async = _ref.async; | ||
_classCallCheck(this, Channel); | ||
this._sender = this._randomId(); | ||
this._async = async; | ||
if (transport) { | ||
this._transport = transport; | ||
this._transport.setHandler(function (event) { | ||
return _this._handleEvent(event); | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var generateRandomId = function () { | ||
// generates a random 13 character string | ||
return Math.random() | ||
.toString(16) | ||
.slice(2); | ||
}; | ||
var Channel = /** @class */ (function () { | ||
function Channel(_a) { | ||
var _b = _a === void 0 ? {} : _a, transport = _b.transport, _c = _b.async, async = _c === void 0 ? false : _c; | ||
var _this = this; | ||
this.sender = generateRandomId(); | ||
this.events = {}; | ||
this.isAsync = async; | ||
if (transport) { | ||
this.transport = transport; | ||
this.transport.setHandler(function (event) { return _this.handleEvent(event); }); | ||
} | ||
} | ||
this._listeners = {}; | ||
} | ||
_createClass(Channel, [{ | ||
key: "addListener", | ||
value: function addListener(type, listener) { | ||
this.on(type, listener); | ||
} | ||
}, { | ||
key: "addPeerListener", | ||
value: function addPeerListener(type, listener) { | ||
var peerListener = listener; | ||
peerListener.ignorePeer = true; | ||
this.on(type, peerListener); | ||
} | ||
}, { | ||
key: "emit", | ||
value: function emit(type) { | ||
var _this2 = this; | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
var event = { | ||
type: type, | ||
args: args, | ||
from: this._sender | ||
}; | ||
var handler = function handler() { | ||
if (_this2._transport) { | ||
_this2._transport.send(event); | ||
Object.defineProperty(Channel.prototype, "hasTransport", { | ||
get: function () { | ||
return !!this.transport; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Channel.prototype.addListener = function (eventName, listener) { | ||
this.events[eventName] = this.events[eventName] || []; | ||
this.events[eventName].push(listener); | ||
}; | ||
Channel.prototype.addPeerListener = function (eventName, listener) { | ||
var peerListener = listener; | ||
peerListener.ignorePeer = true; | ||
this.addListener(eventName, peerListener); | ||
}; | ||
Channel.prototype.emit = function (eventName) { | ||
var _this = this; | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
_this2._handleEvent(event, true); | ||
}; | ||
if (this._async) { | ||
setImmediate(handler); | ||
} else { | ||
handler(); | ||
} | ||
} | ||
}, { | ||
key: "eventNames", | ||
value: function eventNames() { | ||
return Object.keys(this._listeners); | ||
} | ||
}, { | ||
key: "listenerCount", | ||
value: function listenerCount(type) { | ||
var listeners = this._listeners[type]; | ||
return listeners ? listeners.length : 0; | ||
} | ||
}, { | ||
key: "listeners", | ||
value: function listeners(type) { | ||
return this._listeners[type]; | ||
} | ||
}, { | ||
key: "on", | ||
value: function on(type, listener) { | ||
this._listeners[type] = this._listeners[type] || []; | ||
this._listeners[type].push(listener); | ||
} | ||
}, { | ||
key: "once", | ||
value: function once(type, listener) { | ||
var onceListener = this._onceListener(type, listener); | ||
this.on(type, onceListener); | ||
} | ||
}, { | ||
key: "prependListener", | ||
value: function prependListener(type, listener) { | ||
this._listeners[type] = this._listeners[type] || []; | ||
this._listeners[type].unshift(listener); | ||
} | ||
}, { | ||
key: "prependOnceListener", | ||
value: function prependOnceListener(type, listener) { | ||
var onceListener = this._onceListener(type, listener); | ||
this.prependListener(type, onceListener); | ||
} | ||
}, { | ||
key: "removeAllListeners", | ||
value: function removeAllListeners(type) { | ||
if (!type) { | ||
this._listeners = {}; | ||
} else if (this._listeners[type]) { | ||
delete this._listeners[type]; | ||
} | ||
} | ||
}, { | ||
key: "removeListener", | ||
value: function removeListener(type, listener) { | ||
var listeners = this._listeners[type]; | ||
if (listeners) { | ||
this._listeners[type] = listeners.filter(function (l) { | ||
return l !== listener; | ||
}); | ||
} | ||
} | ||
}, { | ||
key: "_randomId", | ||
value: function _randomId() { | ||
// generates a random 13 character string | ||
return Math.random().toString(16).slice(2); | ||
} | ||
}, { | ||
key: "_handleEvent", | ||
value: function _handleEvent(event, isPeer) { | ||
var listeners = this._listeners[event.type]; | ||
if (listeners && (isPeer || event.from !== this._sender)) { | ||
listeners.forEach(function (fn) { | ||
return !(isPeer && fn.ignorePeer) && fn.apply(void 0, _toConsumableArray(event.args)); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: "_onceListener", | ||
value: function _onceListener(type, listener) { | ||
var _this3 = this; | ||
var onceListener = function onceListener() { | ||
_this3.removeListener(type, onceListener); | ||
return listener.apply(void 0, arguments); | ||
}; | ||
return onceListener; | ||
} | ||
}]); | ||
return Channel; | ||
}(); | ||
exports.default = Channel; | ||
var event = { type: eventName, args: args, from: this.sender }; | ||
var handler = function () { | ||
if (_this.transport) { | ||
_this.transport.send(event); | ||
} | ||
_this.handleEvent(event, true); | ||
}; | ||
if (this.isAsync) { | ||
// todo I'm not sure how to test this | ||
setImmediate(handler); | ||
} | ||
else { | ||
handler(); | ||
} | ||
}; | ||
Channel.prototype.eventNames = function () { | ||
return Object.keys(this.events); | ||
}; | ||
Channel.prototype.listenerCount = function (eventName) { | ||
var listeners = this.listeners(eventName); | ||
return listeners ? listeners.length : 0; | ||
}; | ||
Channel.prototype.listeners = function (eventName) { | ||
var listeners = this.events[eventName]; | ||
return listeners ? listeners : undefined; | ||
}; | ||
Channel.prototype.once = function (eventName, listener) { | ||
var onceListener = this.onceListener(eventName, listener); | ||
this.addListener(eventName, onceListener); | ||
}; | ||
Channel.prototype.removeAllListeners = function (eventName) { | ||
if (!eventName) { | ||
this.events = {}; | ||
} | ||
else if (this.events[eventName]) { | ||
delete this.events[eventName]; | ||
} | ||
}; | ||
Channel.prototype.removeListener = function (eventName, listener) { | ||
var listeners = this.listeners(eventName); | ||
if (listeners) { | ||
this.events[eventName] = listeners.filter(function (l) { return l !== listener; }); | ||
} | ||
}; | ||
Channel.prototype.on = function (eventName, listener) { | ||
this.addListener(eventName, listener); | ||
}; | ||
Channel.prototype.handleEvent = function (event, isPeer) { | ||
if (isPeer === void 0) { isPeer = false; } | ||
var listeners = this.listeners(event.type); | ||
if (listeners && (isPeer || event.from !== this.sender)) { | ||
listeners.forEach(function (fn) { return !(isPeer && fn.ignorePeer) && fn.apply(void 0, event.args); }); | ||
} | ||
}; | ||
Channel.prototype.onceListener = function (eventName, listener) { | ||
var _this = this; | ||
var onceListener = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
_this.removeListener(eventName, onceListener); | ||
return listener.apply(void 0, args); | ||
}; | ||
return onceListener; | ||
}; | ||
return Channel; | ||
}()); | ||
exports.Channel = Channel; | ||
exports.default = Channel; |
{ | ||
"name": "@storybook/channels", | ||
"version": "4.2.0-alpha.5", | ||
"version": "4.2.0-alpha.6", | ||
"description": "", | ||
@@ -18,3 +18,3 @@ "keywords": [ | ||
"main": "dist/index.js", | ||
"jsnext:main": "src/index.js", | ||
"jsnext:main": "src/index.ts", | ||
"scripts": { | ||
@@ -26,3 +26,3 @@ "prepare": "node ../../scripts/prepare.js" | ||
}, | ||
"gitHead": "fd600487eb3d295b22c3b32ba659f9b3ce7ef3e8" | ||
"gitHead": "bb9b7b3d5b996ed037001f57ca60bd26ac5c1326" | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
8
18703
440
1