Skip to content

Commit

Permalink
Consistent typing of $els in components
Browse files Browse the repository at this point in the history
Allow them to be passed as null or undefined everywhere.
  • Loading branch information
danimoh committed Sep 6, 2024
1 parent a15fcda commit 50a7e74
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 45 deletions.
5 changes: 4 additions & 1 deletion src/components/AddressInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class AddressInfo { // eslint-disable-line no-unused-vars

/**
* Inserts this AddressInfo into $el overwriting the original content of $el.
* @param {HTMLElement} $el
* @param {?HTMLElement} [$el]
* @param {boolean} [isDetailedView = false]
* @returns {HTMLElement}
*/
renderTo($el, isDetailedView = false) {
$el = $el || document.createElement('div');
Expand Down Expand Up @@ -94,5 +95,7 @@ class AddressInfo { // eslint-disable-line no-unused-vars
const copyableAddress = new Copyable(this._addressInfo.userFriendlyAddress, $address);
$el.appendChild(copyableAddress.getElement());
}

return $el;
}
}
4 changes: 2 additions & 2 deletions src/components/BalanceDistributionBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BalanceDistributionBar { // eslint-disable-line no-unused-vars
* leftFiatRate: number,
* rightFiatRate: number,
* }} settings
* @param {HTMLDivElement} [$el]
* @param {?HTMLDivElement} [$el]
*/
constructor(settings, $el) {
this.$el = BalanceDistributionBar._createElement($el);
Expand Down Expand Up @@ -74,7 +74,7 @@ class BalanceDistributionBar { // eslint-disable-line no-unused-vars
}

/**
* @param {HTMLDivElement} [$el]
* @param {?HTMLDivElement} [$el]
* @returns {HTMLDivElement}
*/
static _createElement($el) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Copyable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Copyable {
/**
* @param {string} text
* @param {HTMLDivElement} [$el]
* @param {?HTMLDivElement} [$el]
*/
constructor(text, $el) {
this._text = text;
Expand Down Expand Up @@ -37,7 +37,7 @@ class Copyable {
}

/**
* @param {HTMLDivElement} [$el]
* @param {?HTMLDivElement} [$el]
* @returns {HTMLDivElement}
*/
static _createElement($el) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/DownloadLoginFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class DownloadLoginFile extends Nimiq.Observable {
/**
* @param {HTMLDivElement} [$el]
* @param {?HTMLDivElement} [$el]
*/
constructor($el) {
super();
Expand Down
4 changes: 2 additions & 2 deletions src/components/FileImporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FileImporter extends Nimiq.Observable {
}

/**
* @param {HTMLLabelElement} [$el]
* @param {?HTMLLabelElement} [$el]
* @param {boolean} [displayFile = true]
*/
constructor($el, displayFile = true) {
Expand All @@ -63,7 +63,7 @@ class FileImporter extends Nimiq.Observable {
}

/**
* @param {HTMLLabelElement} [$el]
* @param {?HTMLLabelElement} [$el]
* @returns {HTMLLabelElement}
*/
static _createElement($el) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Identicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Identicon { // eslint-disable-line no-unused-vars
/**
* @param {string} [address]
* @param {HTMLDivElement} [$el]
* @param {?HTMLDivElement} [$el]
*/
constructor(address, $el) {
this._address = address;
Expand Down Expand Up @@ -31,7 +31,7 @@ class Identicon { // eslint-disable-line no-unused-vars
}

/**
* @param {HTMLDivElement} [$el]
* @param {?HTMLDivElement} [$el]
* @returns {HTMLDivElement}
*/
static _createElement($el) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/LanguagePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

class LanguagePicker { // eslint-disable-line no-unused-vars
/**
* @param {HTMLSelectElement} [$el]
* @param {?HTMLSelectElement} [$el]
*/
constructor($el) {
this.$el = $el || LanguagePicker._createElement($el);
}

/**
* Produces a select element that the user can chose an available language from.
* @param {HTMLSelectElement} [$el]
* @param {?HTMLSelectElement} [$el]
* @returns {HTMLSelectElement}
*/
static _createElement($el) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/LoginFileAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class LoginFileAnimation {
/**
* @param {HTMLDivElement} [$el]
* @param {?HTMLDivElement} [$el]
*/
constructor($el) {
this._color = 0;
Expand Down Expand Up @@ -58,7 +58,7 @@ class LoginFileAnimation {
}

/**
* @param {HTMLDivElement} [$el]
* @param {?HTMLDivElement} [$el]
* @returns {HTMLDivElement}
*/
static _createElement($el) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/LoginFileIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class LoginFileIcon { // eslint-disable-line no-unused-vars
/**
*
* @param {HTMLDivElement?} [$el]
* @param {?HTMLDivElement} [$el]
*/
constructor($el) {
this.colorClass = '';
Expand Down
6 changes: 3 additions & 3 deletions src/components/PasswordBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class PasswordBox extends Nimiq.Observable {
// eslint-disable-next-line valid-jsdoc
/**
* @param {HTMLFormElement} [$el]
* @param {?HTMLFormElement} [$el]
* @param {Partial<PasswordBoxOptions>} [options]
*/
constructor($el, options = {}) {
Expand All @@ -41,7 +41,7 @@ class PasswordBox extends Nimiq.Observable {

this.$el.classList.toggle('hide-input', this.options.hideInput);

this._passwordInput = new PasswordInput(this.$el.querySelector('[password-input]'));
this._passwordInput = new PasswordInput(/** @type {HTMLElement} */(this.$el.querySelector('[password-input]')));
this._passwordInput.on(PasswordInput.Events.VALID, isValid => this._onInputChangeValidity(isValid));

this.setMinLength(this.options.minLength);
Expand All @@ -60,7 +60,7 @@ class PasswordBox extends Nimiq.Observable {
}

/**
* @param {HTMLFormElement | undefined} $el
* @param {?HTMLFormElement | undefined} $el
* @param {PasswordBoxOptions} options
* @returns {HTMLFormElement}
*/
Expand Down
6 changes: 3 additions & 3 deletions src/components/PasswordInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

class PasswordInput extends Nimiq.Observable {
/**
* @param {?HTMLElement} $el
* @param {?HTMLElement} [$el]
* @param {object} [options]
* @param {number=} [options.maxLength = Infinity]
* @param {string=} [options.placeholder = '••••••••']
* @param {number} [options.maxLength = Infinity]
* @param {string} [options.placeholder = '••••••••']
* @param {'current-password' | 'new-password' | undefined} [options.autocomplete = 'current-password']
*/
constructor($el, options = {}) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/PasswordSetterBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class PasswordSetterBox extends Nimiq.Observable {
// eslint-disable-next-line valid-jsdoc
/**
* @param {?HTMLFormElement} $el
* @param {?HTMLFormElement} [$el]
* @param {{bgColor?: string, buttonI18nTag?: string}} [options]
*/
constructor($el, options = {}) {
Expand All @@ -27,7 +27,7 @@ class PasswordSetterBox extends Nimiq.Observable {
this.$el = PasswordSetterBox._createElement($el, this.options);

this._passwordInput = new PasswordInput(
this.$el.querySelector('[password-input]'),
/** @type {HTMLElement} */ (this.$el.querySelector('[password-input]')),
{
maxLength: PasswordSetterBox.PASSWORD_MAX_LENGTH,
autocomplete: 'new-password',
Expand All @@ -52,7 +52,7 @@ class PasswordSetterBox extends Nimiq.Observable {
}

/**
* @param {?HTMLFormElement} $el
* @param {?HTMLFormElement | undefined} $el
* @param {{bgColor: string, buttonI18nTag: string}} options
* @returns {HTMLFormElement}
*/
Expand Down
4 changes: 2 additions & 2 deletions src/components/PaymentInfoLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class PaymentInfoLine { // eslint-disable-line no-unused-vars
/**
* @param {PaymentInfo} paymentInfo
* @param {HTMLElement} [$el]
* @param {?HTMLElement} [$el]
*/
constructor(paymentInfo, $el) {
this.paymentInfo = paymentInfo;
Expand Down Expand Up @@ -56,7 +56,7 @@ class PaymentInfoLine { // eslint-disable-line no-unused-vars

/**
* @private
* @param {HTMLElement} [$el]
* @param {?HTMLElement} [$el]
* @returns {HTMLElement}
*/
static _createElement($el) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/PolygonAddressInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PolygonAddressInfo { // eslint-disable-line no-unused-vars

/**
* Inserts this AddressInfo into $el overwriting the original content of $el.
* @param {HTMLElement} [$el]
* @param {?HTMLElement} [$el]
* @returns {HTMLElement}
*/
renderTo($el) {
Expand Down
10 changes: 5 additions & 5 deletions src/components/ProgressIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class ProgressIndicator extends Nimiq.Observable { // eslint-disable-line no-unused-vars
/**
* @param {?HTMLElement} $el
* @param {?Element | undefined} $el
* @param {number} numberOfSteps
* @param {number} [currentStep]
*/
Expand All @@ -14,9 +14,9 @@ class ProgressIndicator extends Nimiq.Observable { // eslint-disable-line no-unu
}

/**
* @param {?HTMLElement} $el
* @param {?Element | undefined} $el
* @param {number} numberOfSteps
* @returns {HTMLElement}
* @returns {Element}
*/
static _createElement($el, numberOfSteps) {
$el = $el || document.createElement('div');
Expand All @@ -33,12 +33,12 @@ class ProgressIndicator extends Nimiq.Observable { // eslint-disable-line no-unu
return $el;
}

/** @returns {HTMLElement} @deprecated */
/** @returns {Element} @deprecated */
getElement() {
return this.$el;
}

/** @type {HTMLElement} */
/** @type {Element} */
get element() {
return this.$el;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/QrVideoScanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class QrVideoScanner extends Nimiq.Observable {
// eslint-disable-next-line valid-jsdoc
/**
* @param {HTMLDivElement} [$el]
* @param {?HTMLDivElement} [$el]
* @param {(result: string) => boolean} [validator]
* @param {number} [reportFrequency = 7000]
*/
Expand Down Expand Up @@ -110,7 +110,7 @@ class QrVideoScanner extends Nimiq.Observable {
}

/**
* @param {HTMLDivElement} [$el]
* @param {?HTMLDivElement} [$el]
* @returns {HTMLDivElement}
*/
static _createElement($el) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/RecoveryWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class RecoveryWords extends Nimiq.Observable {
/**
*
* @param {HTMLElement} [$el]
* @param {?HTMLElement} [$el]
* @param {boolean} [providesInput]
*/
constructor($el, providesInput) {
Expand Down Expand Up @@ -40,7 +40,7 @@ class RecoveryWords extends Nimiq.Observable {
}

/**
* @param {HTMLElement} [$el]
* @param {?HTMLElement} [$el]
* @param {boolean} input
* @returns {HTMLElement}
* */
Expand Down Expand Up @@ -160,7 +160,7 @@ class RecoveryWords extends Nimiq.Observable {

/**
* @param {number} index
* @param {?string} paste
* @param {string} [paste]
*/
_setFocusToNextInput(index, paste) {
index = Math.max(index, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/components/TabWidthSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class TabWidthSelector extends Nimiq.Observable {
/**
* @param {?HTMLElement} $el
* @param {?HTMLElement} [$el]
*/
constructor($el) {
super();
Expand Down
4 changes: 2 additions & 2 deletions src/components/Timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Timer extends Nimiq.Observable {
/**
* @param {number} startTime
* @param {number} endTime
* @param {HTMLElement} [$el]
* @param {?HTMLElement} [$el]
*/
constructor(startTime, endTime, $el) {
super();
Expand Down Expand Up @@ -52,7 +52,7 @@ class Timer extends Nimiq.Observable {

/**
* @private
* @param {HTMLElement} [$el]
* @param {?HTMLElement} [$el]
* @returns {HTMLElement}
*/
static _createElement($el) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/ValidateWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class ValidateWords extends Nimiq.Observable {
/**
* @param {HTMLElement} [$el]
* @param {?HTMLElement} [$el]
*/
constructor($el) {
super();
Expand All @@ -29,7 +29,7 @@ class ValidateWords extends Nimiq.Observable {
}

/**
* @param {HTMLElement} [$el]
* @param {?HTMLElement} [$el]
* @returns {HTMLElement}
*/
static _createElement($el) {
Expand Down
6 changes: 3 additions & 3 deletions src/request/create/IdenticonSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class IdenticonSelector extends Nimiq.Observable {
/**
* @param {HTMLElement} $el
* @param {?HTMLElement | undefined} $el
* @param {string} keyPath
*/
constructor($el, keyPath) {
Expand All @@ -15,7 +15,7 @@ class IdenticonSelector extends Nimiq.Observable {

this.$el = IdenticonSelector._createElement($el);

/** @type {{ [address: string]: Nimiq.Entropy}} */
/** @type {{ [address: string]: Nimiq.Entropy }} */
this._volatileEntropies = {};

this.$identicons = /** @type {HTMLElement} */ (this.$el.querySelector('.identicons'));
Expand All @@ -25,7 +25,7 @@ class IdenticonSelector extends Nimiq.Observable {
}

/**
* @param {HTMLElement} [$el]
* @param {?HTMLElement} [$el]
*
* @returns {HTMLElement}
*/
Expand Down

0 comments on commit 50a7e74

Please sign in to comment.