Skip to content

Commit

Permalink
Improve typechecking in several shared modules (#2323)
Browse files Browse the repository at this point in the history
  • Loading branch information
LMS007 authored Jul 10, 2020
1 parent 9fab053 commit 93dfa4b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/shared/dom-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions src/shared/frame-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/type-coercions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 93dfa4b

Please sign in to comment.