Unverified Commit 93dfa4b1 authored by Kyle Keating's avatar Kyle Keating Committed by GitHub

Improve typechecking in several shared modules (#2323)

parent 9fab053b
......@@ -7,6 +7,9 @@
/**
* Implementation of `element.closest(selector)`. This is used to support browsers
* (IE 11) that don't have a native implementation.
*
* @param {Element|null} element
* @param {string} selector
*/
export function closest(element, selector) {
while (element) {
......
......@@ -29,6 +29,13 @@
const VERSION = '1.0.0';
/**
* @constructor
* @param {Window} src
* @param {Window} dst
* @param {string} origin
* @param {(Object<string, ((any) => any)>) | ((any) => any)} methods
*/
export default function RPC(src, dst, origin, methods) {
if (!(this instanceof RPC)) return new RPC(src, dst, origin, methods);
const self = this;
......@@ -64,11 +71,18 @@ RPC.prototype.destroy = function () {
this.src.removeEventListener('message', this._onmessage);
};
/**
* @param {string} method
*/
RPC.prototype.call = function (method) {
const args = [].slice.call(arguments, 1);
return this.apply(method, args);
};
/**
* @param {string} method
* @param {any[]} args
*/
RPC.prototype.apply = function (method, args) {
if (this._destroyed) return;
const seq = this._sequence++;
......
......@@ -44,7 +44,7 @@ export function toInteger(value) {
* Returns either the value if its an object or an empty object
*
* @param {any} value - initial value
* @return {object}
* @return {Object}
*/
export function toObject(value) {
if (typeof value === 'object' && value !== null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment