Skip to content

Commit

Permalink
chore: mark private/protected methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Jun 25, 2024
1 parent 60ba8a6 commit 326d1a6
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 64 deletions.
5 changes: 5 additions & 0 deletions abstract/ActivityBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const ACTIVE_ATTR = 'active';
const ACTIVE_PROP = '___ACTIVITY_IS_ACTIVE___';

export class ActivityBlock extends Block {
/** @protected */
historyTracked = false;

/** @protected */
init$ = activityBlockCtx(this);

_debouncedHistoryFlush = debounce(this._historyFlush.bind(this), 10);
Expand Down Expand Up @@ -37,6 +40,7 @@ export class ActivityBlock extends Block {
});
}

/** @protected */
initCallback() {
super.initCallback();
if (this.hasAttribute('current-activity')) {
Expand Down Expand Up @@ -131,6 +135,7 @@ export class ActivityBlock extends Block {
ActivityBlock._activityCallbacks.delete(this);
}

/** @protected */
destroyCallback() {
super.destroyCallback();
this._isActivityRegistered() && this.unregisterActivity();
Expand Down
41 changes: 19 additions & 22 deletions abstract/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ export class Block extends BaseComponent {

/** @type {string[]} */
static styleAttrs = [];

/** @protected */
requireCtxName = false;
allowCustomTemplate = true;

/** @type {import('./ActivityBlock.js').ActivityType} */
activityType = null;

/** @protected */
init$ = blockCtx();

/**
Expand All @@ -52,6 +55,7 @@ export class Block extends BaseComponent {
}

/**
* @private
* @param {string} key
* @param {number} count
* @returns {string}
Expand All @@ -65,6 +69,7 @@ export class Block extends BaseComponent {
/**
* @param {string} key
* @param {() => void} resolver
* @protected
*/
bindL10n(key, resolver) {
this.localeManager?.bindL10n(this, key, resolver);
Expand Down Expand Up @@ -118,6 +123,7 @@ export class Block extends BaseComponent {
);
}

/** @protected */
connectedCallback() {
const styleAttrs = /** @type {typeof Block} */ (this.constructor).styleAttrs;
styleAttrs.forEach((attr) => {
Expand Down Expand Up @@ -149,11 +155,13 @@ export class Block extends BaseComponent {
WindowHeightTracker.registerClient(this);
}

/** @protected */
disconnectedCallback() {
super.disconnectedCallback();
WindowHeightTracker.unregisterClient(this);
}

/** @protected */
initCallback() {
if (!this.has('*blocksRegistry')) {
this.add('*blocksRegistry', new Set());
Expand All @@ -179,12 +187,18 @@ export class Block extends BaseComponent {
});
}

/** @returns {LocaleManager | null} */
/**
* @private
* @returns {LocaleManager | null}
*/
get localeManager() {
return this.has('*localeManager') ? this.$['*localeManager'] : null;
}

/** @returns {A11y | null} */
/**
* @returns {A11y | null}
* @protected
*/
get a11y() {
return this.has('*a11y') ? this.$['*a11y'] : null;
}
Expand All @@ -194,6 +208,7 @@ export class Block extends BaseComponent {
return this.$['*blocksRegistry'];
}

/** @protected */
destroyCallback() {
let blocksRegistry = this.blocksRegistry;
blocksRegistry.delete(this);
Expand Down Expand Up @@ -225,28 +240,10 @@ export class Block extends BaseComponent {
this.a11y?.destroy();
}

/**
* @param {Number} bytes
* @param {Number} [decimals]
*/
fileSizeFmt(bytes, decimals = 2) {
let units = ['B', 'KB', 'MB', 'GB', 'TB'];
/**
* @param {String} str
* @returns {String}
*/
if (bytes === 0) {
return `0 ${units[0]}`;
}
let k = 1024;
let dm = decimals < 0 ? 0 : decimals;
let i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / k ** i).toFixed(dm)) + ' ' + units[i];
}

/**
* @param {String} url
* @returns {String}
* @protected
*/
proxyUrl(url) {
if (this.cfg.secureDeliveryProxy && this.cfg.secureDeliveryProxyUrlResolver) {
Expand Down
34 changes: 20 additions & 14 deletions abstract/UploaderBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { EventType } from '../blocks/UploadCtxProvider/EventEmitter.js';
import { debounce } from '../blocks/utils/debounce.js';
import { customUserAgent } from '../blocks/utils/userAgent.js';
import { createCdnUrl, createCdnUrlModifiers } from '../utils/cdn-utils.js';
import { stringToArray } from '../utils/stringToArray.js';
import { uploaderBlockCtx } from './CTX.js';
import { SecureUploadsManager } from './SecureUploadsManager.js';
import { TypedCollection } from './TypedCollection.js';
Expand All @@ -18,11 +17,16 @@ import { ValidationManager } from './ValidationManager.js';
import { uploadEntrySchema } from './uploadEntrySchema.js';

export class UploaderBlock extends ActivityBlock {
/** @protected */
couldBeCtxOwner = false;

/** @private */
isCtxOwner = false;

/** @protected */
init$ = uploaderBlockCtx(this);

/** @private */
get hasCtxOwner() {
return this.hasBlockInCtx((block) => {
if (block instanceof UploaderBlock) {
Expand All @@ -32,6 +36,7 @@ export class UploaderBlock extends ActivityBlock {
});
}

/** @protected */
initCallback() {
super.initCallback();

Expand All @@ -56,7 +61,10 @@ export class UploaderBlock extends ActivityBlock {
}
}

/** @returns {ValidationManager} */
/**
* @returns {ValidationManager}
* @protected
*/
get validationManager() {
if (!this.has('*validationManager')) {
throw new Error('Unexpected error: ValidationManager is not initialized');
Expand All @@ -72,6 +80,10 @@ export class UploaderBlock extends ActivityBlock {
return this.$['*publicApi'];
}

get getAPI() {
return this.api;
}

/** @returns {TypedCollection} */
get uploadCollection() {
if (!this.has('*uploadCollection')) {
Expand All @@ -80,6 +92,7 @@ export class UploaderBlock extends ActivityBlock {
return this.$['*uploadCollection'];
}

/** @protected */
destroyCtxCallback() {
this._unobserveCollectionProperties?.();
this._unobserveCollection?.();
Expand All @@ -89,6 +102,7 @@ export class UploaderBlock extends ActivityBlock {
super.destroyCtxCallback();
}

/** @private */
initCtxOwner() {
this.isCtxOwner = true;

Expand Down Expand Up @@ -117,17 +131,6 @@ export class UploaderBlock extends ActivityBlock {
}
}

/** @type {string[]} */
get sourceList() {
/** @type {string[]} */
let list = [];
if (this.cfg.sourceList) {
list = stringToArray(this.cfg.sourceList);
}
// @ts-ignore TODO: fix this
return list;
}

/**
* @private
* @param {import('../types').OutputCollectionState} collectionState
Expand Down Expand Up @@ -374,7 +377,10 @@ export class UploaderBlock extends ActivityBlock {
return configValue;
}

/** @returns {Promise<import('@uploadcare/upload-client').FileFromOptions>} */
/**
* @returns {Promise<import('@uploadcare/upload-client').FileFromOptions>}
* @protected
*/
async getUploadClientOptions() {
/** @type {SecureUploadsManager} */
const secureUploadsManager = this.$['*secureUploadsManager'];
Expand Down
Loading

0 comments on commit 326d1a6

Please sign in to comment.