@storybook/channels
Advanced tools
Comparing version 5.1.0-alpha.20 to 5.1.0-alpha.21
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var generateRandomId = function () { | ||
// generates a random 13 character string | ||
return Math.random() | ||
.toString(16) | ||
.slice(2); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.Channel = 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.array.filter"); | ||
require("core-js/modules/web.dom.iterable"); | ||
require("core-js/modules/es6.array.iterator"); | ||
require("core-js/modules/es6.object.keys"); | ||
require("core-js/modules/es6.regexp.to-string"); | ||
require("core-js/modules/es6.date.to-string"); | ||
require("core-js/modules/es6.object.to-string"); | ||
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; } | ||
var generateRandomId = function generateRandomId() { | ||
// 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); }); | ||
var Channel = | ||
/*#__PURE__*/ | ||
function () { | ||
function Channel() { | ||
var _this = this; | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
transport = _ref.transport, | ||
_ref$async = _ref.async, | ||
async = _ref$async === void 0 ? false : _ref$async; | ||
_classCallCheck(this, Channel); | ||
this.isAsync = void 0; | ||
this.sender = generateRandomId(); | ||
this.events = {}; | ||
this.transport = void 0; | ||
this.isAsync = async; | ||
if (transport) { | ||
this.transport = transport; | ||
this.transport.setHandler(function (event) { | ||
return _this.handleEvent(event); | ||
}); | ||
} | ||
} | ||
_createClass(Channel, [{ | ||
key: "addListener", | ||
value: function addListener(eventName, listener) { | ||
this.events[eventName] = this.events[eventName] || []; | ||
this.events[eventName].push(listener); | ||
} | ||
}, { | ||
key: "addPeerListener", | ||
value: function addPeerListener(eventName, listener) { | ||
var peerListener = listener; | ||
peerListener.ignorePeer = true; | ||
this.addListener(eventName, peerListener); | ||
} | ||
}, { | ||
key: "emit", | ||
value: function emit(eventName) { | ||
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: eventName, | ||
args: args, | ||
from: this.sender | ||
}; | ||
var handler = function handler() { | ||
if (_this2.transport) { | ||
_this2.transport.send(event); | ||
} | ||
_this2.handleEvent(event, true); | ||
}; | ||
if (this.isAsync) { | ||
// todo I'm not sure how to test this | ||
setImmediate(handler); | ||
} else { | ||
handler(); | ||
} | ||
} | ||
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]; | ||
} | ||
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; | ||
}()); | ||
}, { | ||
key: "eventNames", | ||
value: function eventNames() { | ||
return Object.keys(this.events); | ||
} | ||
}, { | ||
key: "listenerCount", | ||
value: function listenerCount(eventName) { | ||
var listeners = this.listeners(eventName); | ||
return listeners ? listeners.length : 0; | ||
} | ||
}, { | ||
key: "listeners", | ||
value: function listeners(eventName) { | ||
var listeners = this.events[eventName]; | ||
return listeners ? listeners : undefined; | ||
} | ||
}, { | ||
key: "once", | ||
value: function once(eventName, listener) { | ||
var onceListener = this.onceListener(eventName, listener); | ||
this.addListener(eventName, onceListener); | ||
} | ||
}, { | ||
key: "removeAllListeners", | ||
value: function removeAllListeners(eventName) { | ||
if (!eventName) { | ||
this.events = {}; | ||
} else if (this.events[eventName]) { | ||
delete this.events[eventName]; | ||
} | ||
} | ||
}, { | ||
key: "removeListener", | ||
value: function removeListener(eventName, listener) { | ||
var listeners = this.listeners(eventName); | ||
if (listeners) { | ||
this.events[eventName] = listeners.filter(function (l) { | ||
return l !== listener; | ||
}); | ||
} | ||
} | ||
}, { | ||
key: "on", | ||
value: function on(eventName, listener) { | ||
this.addListener(eventName, listener); | ||
} | ||
}, { | ||
key: "handleEvent", | ||
value: function handleEvent(event) { | ||
var isPeer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 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, _toConsumableArray(event.args)); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: "onceListener", | ||
value: function onceListener(eventName, listener) { | ||
var _this3 = this; | ||
var onceListener = function onceListener() { | ||
_this3.removeListener(eventName, onceListener); | ||
return listener.apply(void 0, arguments); | ||
}; | ||
return onceListener; | ||
} | ||
}, { | ||
key: "hasTransport", | ||
get: function get() { | ||
return !!this.transport; | ||
} | ||
}]); | ||
return Channel; | ||
}(); | ||
exports.Channel = Channel; | ||
exports.default = Channel; | ||
var _default = Channel; | ||
exports.default = _default; |
{ | ||
"name": "@storybook/channels", | ||
"version": "5.1.0-alpha.20", | ||
"version": "5.1.0-alpha.21", | ||
"description": "", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "a57917a19ceaafd5f5c42bd47821568f9dc26390" | ||
"gitHead": "99c262545d1c106802ada148883ed371901f971c" | ||
} |
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
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
28456
9
700